-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.py
127 lines (105 loc) · 3.33 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
import colorama
from vector2d import Vector2D
from texture import Texture
from loadtexture import load_texture
from hitbox import Hitbox
from laser import Laser
import random
#holt AI path und gibt ihn als array von richtungen zurück
def get_path(path):
file = open("paths/paths","r");
paths = file.readlines();
path = list(map(int,paths[path].split(",")))
converted_path = [];
for i in path:
converted_path.append(4);
converted_path.append(i);
return converted_path;
#Gegner vater klasse
class Enemy:
isAlive = True;
pos = Vector2D(0,0);
hitbox = None;
texture = None;
laser = [];
path_pos = 0;
path = [];
hp = 5;
dmg = 1;
speed = 1;
#daten update von gegner und lauft denn vorgegebenen path ab
def stat_update(self):
if(self.path_pos < len(self.path)):
if(self.path[self.path_pos] == 0): self.pos.y -= self.speed;
elif(self.path[self.path_pos] == 1): self.pos.x += self.speed;
elif(self.path[self.path_pos] == 2): self.pos.y += self.speed;
elif(self.path[self.path_pos] == 3): self.pos.x -= self.speed;
self.path_pos += 1;
if(self.hp <= 0):
self.isAlive = False;
self.hitbox.update_pos(self.pos);
#löscht alle inneren objekte für das neuerstellen
def delete(self):
self.pos = None;
self.hitbox = None;
self.texture = None;
#kleiner Gegner klasse
class TinyEnemy(Enemy):
#Konstruktor setzt position sowie path des gegners
def __init__(self,pos,path):
self.path = [];
self.laser = [];
self.path = get_path(path);
self.pos = pos;
self.texture = Texture(load_texture("entity",2),fore_color = colorama.Fore.CYAN);
self.hitbox = Hitbox(pos,Vector2D(2,1));
#updatet den gegner
def update(self):
self.stat_update();
#grosser Gegner klasse
class StrongEnemy(Enemy):
hp = 20;
dmg = 2;
cooldown_timer = 0;
#Konstruktor setzt position sowie path des Gegners
def __init__(self,pos,path):
self.path = [];
self.laser = [];
self.path = get_path(path);
self.pos = pos;
self.texture = Texture(load_texture("entity",6),fore_color = colorama.Fore.CYAN);
self.hitbox = Hitbox(pos,Vector2D(6,5));
#updated den gegner und shiesst nach ablauf des cooldowns
def update(self):
self.stat_update();
if(self.cooldown_timer > 0): self.cooldown_timer -= 1;
else: self.shoot();
#erstellt schuss objekt
def shoot(self):
self.laser.append(Laser(Vector2D(self.pos.x -3,self.pos.y),self.dmg,1));
self.laser.append(Laser(Vector2D(self.pos.x -3,self.pos.y + 4),self.dmg,1));
self.cooldown_timer = random.randint(1,30);
#Boss klasse
class Boss(Enemy):
hp = 550;
dmg = 1;
cooldown_timer = 0;
#erstellt boss an position und übergibt path
def __init__(self,pos,path):
self.path = [];
self.laser = [];
self.path = get_path(path);
self.pos = pos;
self.texture = Texture(load_texture("entity",7),fore_color = colorama.Fore.CYAN);
self.hitbox = Hitbox(pos,Vector2D(30,8));
#updatet Boss und schiesst wenn cooldown abgelaufen ist
def update(self):
self.stat_update();
if(self.path_pos > len(self.path)-1): self.path_pos = 0;
if(self.cooldown_timer > 0): self.cooldown_timer -= 1;
else: self.shoot();
#erstellt schussobjekt vom boss
def shoot(self):
self.laser.append(Laser(Vector2D(self.pos.x + 7 -10,self.pos.y + 2),self.dmg,1));
self.laser.append(Laser(Vector2D(self.pos.x + 7 -10,self.pos.y + 5),self.dmg,1));
self.cooldown_timer = random.randint(1,30);