-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gegner.py
317 lines (262 loc) · 10.7 KB
/
Gegner.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import random
class MOB(object):
def __init__(self,name,klasse,positionx,positiony,spawnpositonx,spawnpositiony,chunkx,chunky,bevorzugte_Richtung):
self.name = name
self.klasse = klasse
self.positionx = positionx
self.positiony = positiony
self.spawnpositionx = spawnpositonx
self.spawnpositony = spawnpositiony
self.chunkx = chunkx
self.chunky = chunky
self.posx = positionx
self.posy = positiony
self.spawned = False
self.agro = False
self.bevorzugte_Richtung = bevorzugte_Richtung
self.movement_Speed = 1
self.moves = ["Nord","NordOst","SüdOst","Süden","Osten","SüdWest","Westen","NordWest",self.bevorzugte_Richtung,self.bevorzugte_Richtung,self.bevorzugte_Richtung,self.bevorzugte_Richtung,self.bevorzugte_Richtung,self.bevorzugte_Richtung,self.bevorzugte_Richtung,self.bevorzugte_Richtung,self.bevorzugte_Richtung,self.bevorzugte_Richtung]
self.animation = "move"
self.actualframe = ""
self.animationstimer = 1
self.animation = "move"
self.move_frames = 2
self.attack_frames = 5
self.death_frames = 5
self.realanimationtimer = 1
self.dauerderFrames = 10
self.pixel = 1
self.damaged = False
if self.klasse == "Slime":
self.agro_range = 50
self.attack_range = 15
self.attack_damage = 10
self.attack_speed = 105
self.life = 50
if self.klasse == "Wolf":
self.agro_range = 50
self.attack_range = 20
self.attack_damage = 25
self.attack_speed = 105
self.life = 75
if self.klasse == "Dämon":
self.agro_range = 50
self.attack_range = 25
self.attack_damage = 30
self.attack_speed = 105
self.life = 100
if self.klasse == "Golem":
self.agro_range = 50
self.attack_range = 25
self.attack_damage = 80
self.attack_speed = 120
self.life = 250
self.attack_timer = 0
self.has_attacked = False
self.is_alive = True
def revive(self):
if self.klasse == "Golem":
self.life = 250
if self.klasse == "Dämon":
self.life = 100
if self.klasse == "Wolf":
self.life = 75
if self.klasse == "Slime":
self.life = 50
self.is_alive = True
def random_spawner(self,chunkx,chunky,posx,posy):
self.spawnpositionx = posx
self.spawnpositony = posy
self.chunkx = chunkx
self.chunky = chunky
self.spawned = False
def check_spawn(self,x,y):
if self.chunkx == x and self.chunky == y:
if self.spawned == False:
self.spawned = True
self.posx = self.spawnpositionx
self.posy = self.spawnpositony
print("gegner gespawnt")
else:
self.spawned = False
self.posx = self.positionx
self.posy = self.positiony
if self.is_alive == False and self.realanimationtimer > 48:
self.posx = 9000
self.posy = 9000
def die(self):
self.is_alive = False
def recieve_damage(self,damage):
Drops = ""
self.life = self.life - damage
if self.life <= 0 and self.is_alive == True:
self.die()
self.animation = "die"
Drops = self.klasse
return ( Drops)
def checke_entfernung(self,player_posx,player_posy):
Abstand_x = abs(self.posx - player_posx)
Abstand_y = abs(self.posy - player_posy)
return(Abstand_x,Abstand_y)
def move(self,player_posx, player_posy,playerchunkx,playerchunky,chunkwidth,chunkheight):
#print("Ich habe gerade "+str(self.life)+" Leben")
self.check_spawn(playerchunkx,playerchunky)
self.check_agro(player_posx,player_posy)
if self.spawned == True and self.agro == False and self.is_alive == True:
self.animation = "move"
Richtung = random.choice(self.moves)
if Richtung == "Nord":
self.posx = self.posx
self.posy = self.posy - self.movement_Speed
elif Richtung == "NordOst":
self.posx = self.posx + (self.movement_Speed/2)
self.posy = self.posy - (self.movement_Speed/2)
elif Richtung == "Osten":
self.posx = self.posx + self.movement_Speed
self.posy = self.posy
elif Richtung == "SüdOst":
self.posx = self.posx + (self.movement_Speed/2)
self.posy = self.posy + (self.movement_Speed/2)
elif Richtung == "Süden":
self.posx = self.posx
self.posy = self.posy + self.movement_Speed
elif Richtung == "SüdWest":
self.posx = self.posx - (self.movement_Speed/2)
self.posy = self.posy + (self.movement_Speed/2)
elif Richtung == "Westen":
self.posx = self.posx - self.movement_Speed
self.posy = self.posy
elif Richtung == "NordWest":
self.posx = self.posx - (self.movement_Speed/2)
self.posy = self.posy - (self.movement_Speed/2)
#print("MEineX: "+str(self.posx)+" MeineY: "+str(self.posy))
if self.posx <= 0:
print("Ich bin oben angestoßen")
self.posx = chunkwidth - 1
elif self.posx > chunkwidth:
print("Ich bin unten angestoßen")
self.posx = 1
if self.posy <= 0:
self.posy = chunkheight - 1
print("Ich bin rechts angestoßen")
elif self.posy > chunkheight:
print("Ich bin links angestoßen")
self.posy = 1
if self.agro == True and self.is_alive == True:
self.animation = "attack"
if player_posx < self.posx:
self.posx = self.posx - self.movement_Speed
#print("1")
elif player_posx > self.posx:
self.posx = self.posx + self.movement_Speed
#print("2")
if player_posy < self.posy:
self.posy = self.posy - self.movement_Speed
#print("3")
elif player_posy > self.posy:
self.posy = self.posy + self.movement_Speed
#print("4")
return(self.posx,self.posy)
def how_attack_damage(self,player_posx,player_posy):
Damage = 0
Abstand_x = abs(self.posx - player_posx)
Abstand_y = abs(self.posy - player_posy)
if self.has_attacked == False:
if Abstand_x <= self.attack_range and Abstand_y <= self.attack_range:
Damage = self.attack_damage
self.has_attacked = True
elif self.has_attacked == True:
self.attack_timer = self.attack_timer + 1
Damage = 0
if self.attack_timer > self.attack_speed:
self.attack_timer = 0
self.has_attacked = False
#print("Self.attacktimer = "+str(self.attack_timer))
self.attack_timer = self.attack_timer+1
return(Damage)
def check_agro(self,player_posx,player_posy):
Abstand_x = abs(self.posx - player_posx)
Abstand_y = abs(self.posy - player_posy)
#print("X Abstand zum player: "+str(Abstand_x))
#print("Y Abstand zum Player: "+str(Abstand_y))
if Abstand_x <= self.agro_range and Abstand_y <= self.agro_range:
self.agro = True
else:
self.agro = False
def animate(self):
self.realanimationtimer = self.realanimationtimer+1
#print("Realanimationtimer: "+str(self.realanimationtimer))
if self.animation == "move":
if self.realanimationtimer <= 10:
self.actualframe = "move_01"
elif self.realanimationtimer <=20:
self.actualframe = "move_02"
elif self.realanimationtimer > 20:
self.realanimationtimer = 1
if self.animation == "attack":
if self.realanimationtimer <= 10:
self.actualframe = "attack_01"
elif self.realanimationtimer <= 20:
self.actualframe = "attack_02"
elif self.realanimationtimer <= 30:
self.actualframe = "attack_03"
elif self.realanimationtimer <= 40:
self.actualframe = "attack_04"
elif self.realanimationtimer <= 50:
self.actualframe = "attack_05"
elif self.realanimationtimer >50:
self.realanimationtimer = 1
if self.animation == "die":
if self.realanimationtimer <= 10:
self.actualframe = "die_01"
elif self.realanimationtimer <= 20:
self.actualframe = "die_02"
elif self.realanimationtimer <= 30:
self.actualframe = "die_03"
elif self.realanimationtimer <= 40:
self.actualframe = "die_04"
elif self.realanimationtimer <= 50:
self.actualframe = "die_05"
elif self.realanimationtimer >50:
self.realanimationtimer = 1
self.die()
if self.actualframe == "move_01":
self.pixel = 0
self.damaged = False
if self.actualframe == "move_02":
self.pixel = 1
self.damaged = False
if self.actualframe == "attack_01":
self.pixel = 2
self.damaged = False
if self.actualframe == "attack_02":
self.pixel = 3
self.damaged = False
if self.actualframe == "attack_03":
self.pixel = 4
self.damaged = False
if self.actualframe == "attack_04":
self.pixel = 5
self.damaged = False
if self.actualframe == "attack_05":
self.pixel = 6
self.damaged = False
if self.actualframe == "die_01":
self.pixel = 7
self.damaged = False
if self.actualframe == "die_02":
self.pixel = 8
self.damaged = False
if self.actualframe == "die_03":
self.pixel = 9
self.damaged = False
if self.actualframe == "die_04":
self.pixel = 10
self.damaged = False
if self.actualframe == "die_05":
self.pixel = 11
self.damaged = False
self.die()
#print(self.actualframe)
#print("Frame: "+str(self.pixel))
return(self.pixel,self.damaged)