I am creating a program similar to the classic "astrocrash" game, but there are multiple types of ammunition, each only affecting a specific type of target. The method self.overlapping_sprites() will recognise any overlapping sprites and act accordingly, but how do I get the program to detect if the overlapping sprite is of a specific type?
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):