class Enemy(pygame.sprite.Sprite): def __init__(self, x, y, speed): pygame.sprite.Sprite.__init__(self) # (x, y) represents bottom center self.x = x self.y = y self.time = 0 self.speed = speed self.interval = z_walk.animSpeed / abs(self.speed) self.dead = False self.deadShot = False self.size = 25 self.animSprite = AnimatedSprite(ZOMBIE_SPRITE_SHEET, [z_walk, z_hit, z_die], 'walk') self.animSprite.loadImages() self.rect = pygame.rect.Rect( (self.x - self.size / 2, self.y - self.size, self.size, self.size)) self.image = pygame.Surface((self.size, self.size)) self.hp = 100 def updateHit(self): iw = self.image.get_width() ih = self.image.get_height() self.rect = pygame.rect.Rect((self.x - iw / 2, self.y - ih, iw, ih)) def update(self): self.updateHit() self.image = self.animSprite.getImage( True if self.speed < 0 else False) if not self.dead and self.time % self.interval == 0: self.x += self.speed * self.interval self.time += 1 * abs(self.speed) def hItYoUrSeLf(self): if not self.dead: self.animSprite.clearStack() self.animSprite.addAnimation('hit') self.hp -= 25 if self.hp <= 0: self.die() def die(self): self.animSprite.addAnimation('die') self.dead = True def draw(self, surf): surf.blit(self.image, (self.x - self.image.get_width() / 2, self.y - self.image.get_height())) def collidePoint(self, x, y): return self.rect.collidepoint(x, y)
sys.exit() print(mouse) elif event.type == KEYDOWN: kp = True keyid = event.key keys[keyid] = True print("pressed %d" % keyid) elif event.type == KEYUP: keyid = -1 keys[event.key] = False if not GAMEOVER: bullx = 0 bully = 0 if keys[K_RIGHT]: if kp: kirb.clearStack() kirb_right = True kirb_x += walk_speed bullx = 1 kirb.whenDone('walk') if keys[K_LEFT]: if kp: kirb.clearStack() kirb_right = False kirb_x -= walk_speed bullx = -1 kirb.whenDone('walk') if keys[K_UP]: kirb_y -= walk_speed bully = -1 if kp: