-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.py
39 lines (31 loc) · 1.08 KB
/
enemy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pygame
import entity
class Enemy(entity.Entity):
def __init__(self, enemyType, position, anims, startAnim):
super(Enemy, self).__init__(position, anims, startAnim)
self.typeofenemy = enemyType
self.health = 1
self.dead = False
def collideWithBullet(self, bullet):
if not self.dead:
self.takeHit(1)
bullet.kill()
def takeHit(self, damage):
if not self.dead:
sound = pygame.mixer.Sound("data/sounds/hit.wav")
sound.play()
self.health -= damage
if self.health <= 0:
self.dead = True
self.changeAnimation('death')
self.movex = 0
self.movey = 0
else:
self.changeAnimation('takehit')
def update(self):
super(Enemy, self).update()
if self.animName == 'takehit' and self.anim.done:
self.changeAnimation('idle')
if self.dead and self.anim.done:
self.kill()
del self