-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.py
54 lines (45 loc) · 1.51 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pygame
from entity import Entity
from settings import *
class Enemy(Entity):
def __init__(self, x, y, w, h, speed):
super().__init__(x, y, w, h, speed, "run")
self.animations_database = {"run": self.animations("assets/img/enemy/run", [7, 7, 7])}
self.is_bite = False
self.bite_timing = 0
self.damage_timing = 0
if x > 0:
self.flip = True
else:
self.flip = False
def move(self):
self.velocity[0] = 0
self.velocity[1] = 0
if self.flip:
self.velocity[0] -= self.speed
super().move_left()
else:
self.velocity[0] += self.speed
super().move_right()
def detect_bite(self, player, audio):
if not self.is_bite:
if self.rect.colliderect(player.rect):
self.is_bite = True
player.damage(5)
audio.play_zombie_attack_sound()
else:
self.bite_timing += 1
if self.bite_timing >= 20:
self.bite_timing = 0
self.is_bite = False
def take_damage(self, player):
self.damage_timing += 1
if player.rect.colliderect(self.rect) and player.is_punching:
if self.damage_timing >= 20:
self.damage(20)
self.damage_timing = 0
def update(self):
super().update()
def draw(self, window):
super().draw(window)
pygame.draw.rect(window, GREEN_COLOR, self.life_rect)