So once again I am trying to make a little shooting game where you have to dodge or shoot at enemies to win. The game is over once you get hit by an enemy and I managed to make that work. Yet my problem now is that I need a way to make it that once the enemy class and missiles class collide with each other they both disappear. But I couldn't figure a way to do that.
class Enemy(pg.sprite.Sprite):
def __init__(self):
super(Enemy, self).__init__()
self.surf = pg.image.load("Enemy.png").convert()
self.surf = pg.transform.smoothscale(self.surf, (75, 75))
self.surf.set_colorkey((255, 255, 255), RLEACCEL)
self.rect = self.surf.get_rect(center=(
random.randint(SCREEN_WIDTH + 20, SCREEN_WIDTH + 100),
random.randint(0, SCREEN_HEIGHT),
)
)
self.speed = random.randint(5, 15)
def update(self):
self.rect.move_ip(-self.speed, 0)
if self.rect.right < 0:
self.kill()
class Missile(pg.sprite.Sprite):
def __init__(self, pos):
super(Missile, self).__init__()
self.surf = pg.image.load("Missile.png").convert()
self.surf = pg.transform.smoothscale(self.surf, (20, 20))
self.surf.set_colorkey((0, 0, 0), RLEACCEL)
self.rect = self.surf.get_rect(center=pos)
def update(self):
self.rect.move_ip(10, 0)
if self.rect.right < 0:
self.kill()