Newer
Older
from enemies import Enemy, Shot
from common import *
from objects import Text
class LeftCannon(Enemy):
def __init__(self):
super().__init__("ei ei ei", 200, 50)
self.y = 0
self.exploding = 0
def update(self, tick):
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
if self.exploding > 0:
if self.exploding == 30:
explode(self.x, self.y, (255, 255, 0), 200, 1)
if self.exploding == 1:
explode(self.x, self.y, (255, 0, 0), 30, 4)
objects.remove(self)
self.exploding -= 1
elif tick % 50 == 1:
objects.append(Shot("a", self.x - 15, self.y + 20, -0.9, 0))
objects.append(Shot("s", self.x - 5, self.y + 20, -0.4, 0.4))
objects.append(Shot("d", self.x + 5, self.y + 20, 0.4, 0.4))
objects.append(Shot("f", self.x + 15, self.y + 20, 0.9, 0))
def draw(self):
super().draw()
pygame.draw.lines(screen, (255, 0, 0), True,
((self.x - 20, self.y),
(self.x, self.y - 20),
(self.x + 20, self.y),
(self.x, self.y + 20)
))
def hit(self):
self.exploding = 30
class RightCannon(Enemy):
def __init__(self):
super().__init__("ie ie ie", 600, 50)
self.y = 0
self.exploding = 0
def update(self, tick):
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
if self.exploding > 0:
if self.exploding == 30:
explode(self.x, self.y, (255, 255, 0), 200, 1)
if self.exploding == 1:
explode(self.x, self.y, (255, 0, 0), 30, 4)
objects.remove(self)
self.exploding -= 1
elif tick % 50 == 1:
objects.append(Shot("j", self.x - 15, self.y + 20, -0.9, 0))
objects.append(Shot("k", self.x - 5, self.y + 20, -0.4, 0.4))
objects.append(Shot("l", self.x + 5, self.y + 20, 0.4, 0.4))
objects.append(Shot("ö", self.x + 15, self.y + 20, 0.9, 0))
def draw(self):
super().draw()
pygame.draw.lines(screen, (255, 0, 0), True,
((self.x - 20, self.y),
(self.x, self.y - 20),
(self.x + 20, self.y),
(self.x, self.y + 20)
))
def hit(self):
self.exploding = 30
class Boss10(Enemy):
def __init__(self):
super().__init__("lustig", 400, 0)
self.leftCannon = LeftCannon()
objects.append(self.leftCannon)
self.rightCannon = RightCannon()
objects.append(self.rightCannon)
def update(self, tick):
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
def draw(self):
super().draw()
pygame.draw.lines(screen, (255, 0, 0), True,
((self.x - 250, self.y - 100),
(self.x + 250, self.y - 100),
(self.x + 250, self.y),
(self.x, self.y - 70),
(self.x - 250, self.y),
))
def hit(self):
score.inc(50)
objects.remove(self)
if self.leftCannon in objects:
objects.remove(self.leftCannon)
if self.rightCannon in objects:
objects.remove(self.rightCannon)
explode(self.x, self.y, (255, 255, 255), 100, 1)
explode(self.x, self.y, (255, 255, 0), 200, 2)
explode(self.x, self.y, (255, 0, 0), 200, 6)
def level10(objects, tick):
if tick == 1:
objects.append(Text("Level 10", 50))
objects.append(Boss10())
for obj in objects:
if isinstance(obj, Enemy):
return False
return True