-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathenemy.py
55 lines (48 loc) · 1.65 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
55
"""Class enemy"""
from random import randint, choice
from entity import Entity
class Enemy(Entity):
"""init an enemy"""
def __init__(self, rect, surface, category):
Entity.__init__(self, rect)
self.category = category
self.surface = surface
self.speed = (0,0)
self.position = self.rect.topleft
def enemy_restriction(self):
"""return true if enemy left his rect restriction"""
height,_ = self.position
width = self.rect.size[0]
if self.category == "grass":
if height + width < 0:
return True
else:
if height + width < 0:
return True
return False
def display(self, screen):
"""displaying the enemy"""
screen.blit(self.surface, self.rect)
def moving(self):
"""verif if moving"""
return self.speed != (0,0)
def run(self ,speed):
"""animate the mob"""
if self.category == "flyingMob":
self.change_speed(
(
speed + speed*0.05,choice([randint(int(-400+speed * 0.3),
int(-300+speed * 0.3)
),
randint(
int(-120+speed * 0.1),
int(100+speed * 0.1))]
)
)
)
elif self.category == "heart":
self.change_speed((speed + randint(0,500),0))
elif self.category == "mediumMob":
self.change_speed((speed + speed*0.05,0))
else:
self.change_speed((speed,0))