【发布时间】:2014-05-25 22:00:48
【问题描述】:
我正在创建一个类似于经典“astrocrash”游戏的程序,但有多种类型的弹药,每种只影响特定类型的目标。 self.overlapping_sprites() 方法将识别任何重叠的精灵并采取相应的行动,但我如何让程序检测重叠的精灵是否属于特定类型?
class Krabbypatty(games.Sprite):
LETTUCE = 1
TOMATO = 2
PATTY = 3
images = {LETTUCE : games.load_image("tamatoandpatty.bmp"),
TOMATO : games.load_image("lettuceandpatty.bmp"),
PATTY : games.load_image("lettuceandtomato.bmp") }
SPEED = 3
def __init__(self, x, y, krabbypattytype):
super(Krabbypatty, self).__init__(
image = Krabbypatty.images[krabbypattytype],
x=x, y=y,
dx = random.choice([1, -1]) * Krabbypatty.SPEED * random.random()/krabbypattytype,
dy = random.choice([1, -1]) * Krabbypatty.SPEED * random.random()/krabbypattytype)
self.krabbypattytype = krabbypattytype
def update(self):
if self.top > games.screen.height:
self.bottom = 0
if self.bottom < 0:
self.top = games.screen.height
if self.left > games.screen.width:
self.right = 0
if self.right < 0:
self.left = games.screen.width
if self.overlapping_sprites:
sprite.change_patty()
def change_patty(self):
【问题讨论】:
标签: python pygame collision-detection collision sprite