나는 최근에이 코드를 작성해 왔으며 충돌 감지를 원했지만 이전에는 해본 적이 없으며 도움이 필요하다. 이 코드는 간단해야한다, 그래서 파이썬과 파이 게임으로 작성하지만 난파이 게임에서 어떻게 충돌 탐지를합니까?
import pygame, os, itertools
from pygame.locals import *
w = 640
h = 480
pink = (0,179,179)
player_x = 39
player_y = 320
def setup_background():
screen.fill((pink))
screen.blit(playerImg, (player_x,player_y))
screen.blit(brick_tile, (0,0))
pygame.display.flip()
pygame.init()
screen = pygame.display.set_mode((w, h))
clock = pygame.time.Clock()
playerImg = pygame.image.load('img/player.png').convert_alpha()
brick_tile = pygame.image.load('img/map.png').convert_alpha()
class Player(pygame.sprite.Sprite):
allsprites = pygame.sprite.Group()
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('img/player.png')
self.rect = self.image.get_rect()
class World(pygame.sprite.Sprite):
allsprites = pygame.sprite.Group()
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('img/map.png')
self.rect = self.image.get_rect()
player = Player()
world = World()
done = False
while not done:
setup_background()
block_hit_list = pygame.sprite.spritecollide(player, world.allsprites, True)
for world in block_hit_list:
print("WORKING")
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.KEYDOWN:
if event.key == K_RIGHT:
player_x += 5
스프라이트 검출 방법을 알고 싶습니까? 세계가 투명해야하는지에 대한 의견이 필요합니까? –