-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.py
221 lines (197 loc) · 6.7 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from config import (
SCREEN_HEIGHT,
SCREEN_WIDTH,
LEFT,
RIGHT,
DERIVACAO,
resource_path,
calcule_vetor_distance,
verify_align,
)
from pygame.image import load
from persons import SpritePerson
from objetcs import PedraEnemy
from grupos import grupo_objets_enemy
import random
class Enemy(SpritePerson):
def __init__(self, speed):
super(Enemy, self).__init__()
self.tipo = 1
self.imageswalk = [
resource_path("images/Enemy-" + str(self.tipo) + "-Walk-" + str(i) + ".png")
for i in range(1, 6)
]
self.imagesattack = [
resource_path(
"images/Enemy-" + str(self.tipo) + "-Attack-" + str(i) + ".png"
)
for i in range(1, 7)
]
self.imagesstop = [
resource_path("images/Enemy-" + str(self.tipo) + "-Walk-" + str(i) + ".png")
for i in [
1,
]
]
self.imageshit = [
resource_path("images/Enemy-" + str(self.tipo) + "-Hit-" + str(i) + ".png")
for i in range(1, 4)
]
self.imagesatirar = [
resource_path(
"images/Enemy-" + str(self.tipo) + "-Attack-" + str(i) + ".png"
)
for i in range(1, 7)
]
self.image = load(self.imageswalk[0])
self.images_list = self.imagesstop
self.rect = self.image.get_rect()
self.rect.y = SCREEN_HEIGHT - random.randint(0, 500)
self.rect.x = SCREEN_WIDTH
self.counter = 0
self.speed = random.randint(3, 3 + speed)
self.sprint = 3
self.pedras = random.randint(0, 2)
self.reverse = False
self.life = 6
self.execute = self.action_parado
def action_atirar(self):
if self.pedras > 0:
if self.update_image(self.imagesatirar):
self.execute = self.action_parado
else:
if self.counter == ((len(self.imagesatirar) - 1) * self.sprint):
if self.reverse:
grupo_objets_enemy.add(
PedraEnemy(self.rect.left, self.rect.y, LEFT)
)
if not self.reverse:
grupo_objets_enemy.add(
PedraEnemy(self.rect.right, self.rect.y, RIGHT)
)
self.pedras -= 1
else:
self.execute = self.action_parado
def paralaxe(self, step):
self.rect.x -= step
def attack_trigger(self):
if random.randint(1, 3000) < self.speed * 30:
return True
else:
return False
def update(self, grupo_player, grupo_enemy):
if self.execute not in [
self.action_in_attack,
self.action_attack,
self.action_hit,
self.action_atirar,
]:
for player_active in grupo_player:
if verify_align(self.rect.y, player_active.rect.y):
if (
calcule_vetor_distance(
self.rect.center, player_active.rect.center
)
> DERIVACAO
):
if self.attack_trigger():
self.execute = self.action_atirar
if (
calcule_vetor_distance(
self.rect.center, player_active.rect.center
)
< DERIVACAO
):
if self.attack_trigger():
self.execute = self.action_in_attack
self.dx = 0
self.dy = 0
for player_active in grupo_player:
if (
calcule_vetor_distance(self.rect.center, player_active.rect.center)
> DERIVACAO
):
dx, dy = self.calculate_path(grupo_player, 0)
self.dx += dx
self.dy += dy
dx, dy = self.calculate_path(grupo_enemy, 40)
self.dx -= dx
self.dy -= dy
self.passo_x = int(self.dx * self.speed)
self.passo_y = int(self.dy * self.speed)
self.move((self.passo_x, self.passo_y))
if self.dx < 0:
self.reverse = True
elif self.dx > 0:
self.reverse = False
if self.execute not in [
self.action_in_attack,
self.action_attack,
self.action_hit,
self.action_atirar,
]:
if self.dx == 0 and self.dy == 0:
self.execute = self.action_parado
else:
self.execute = self.action_andando
self.execute()
class Wooden(Enemy):
def __init__(self, speed):
super(Wooden, self).__init__(speed)
self.tipo = 1
self.imageswalk = [
resource_path("images/Enemy-" + str(self.tipo) + "-Walk-" + str(i) + ".png")
for i in range(1, 6)
]
self.imagesattack = [
resource_path(
"images/Enemy-" + str(self.tipo) + "-Attack-" + str(i) + ".png"
)
for i in range(1, 7)
]
self.imagesstop = [
resource_path("images/Enemy-" + str(self.tipo) + "-Walk-" + str(i) + ".png")
for i in [
1,
]
]
self.imageshit = [
resource_path("images/Enemy-" + str(self.tipo) + "-Hit-" + str(i) + ".png")
for i in range(1, 4)
]
self.imagesatirar = [
resource_path(
"images/Enemy-" + str(self.tipo) + "-Attack-" + str(i) + ".png"
)
for i in range(1, 7)
]
class Steam(Enemy):
def __init__(self, speed):
super(Steam, self).__init__(speed)
self.tipo = 2
self.imageswalk = [
resource_path("images/Enemy-" + str(self.tipo) + "-Walk-" + str(i) + ".png")
for i in range(1, 7)
]
self.imagesattack = [
resource_path(
"images/Enemy-" + str(self.tipo) + "-Attack-" + str(i) + ".png"
)
for i in range(1, 7)
]
self.imagesstop = [
resource_path("images/Enemy-" + str(self.tipo) + "-Walk-" + str(i) + ".png")
for i in [
1,
]
]
self.imageshit = [
resource_path("images/Enemy-" + str(self.tipo) + "-Hit-" + str(i) + ".png")
for i in range(1, 4)
]
self.imagesatirar = [
resource_path(
"images/Enemy-" + str(self.tipo) + "-Attack-" + str(i) + ".png"
)
for i in range(1, 7)
]