-
Notifications
You must be signed in to change notification settings - Fork 2
/
levels.py
238 lines (198 loc) · 7.79 KB
/
levels.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
import pygame
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (50, 50, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
class _wall(pygame.sprite.Sprite):
is_fixed = True
is_killer = False
is_end = False
color = BLACK
def __init__(self, x, y, width=40, height=440):
super().__init__()
self.image = pygame.Surface([width, height])
tile = pygame.image.load(self.pic)
for i in range(0, height, 40):
self.image.blit(tile, (0, i))
self.rect = self.image.get_rect()
self.rect.x, self.rect.y = x, y
def is_fixed(self):
return True
class DumbWall(_wall):
"Wall that blocks passage"
pic = 'images/dumbwall.png'
# pic = 'images/dangerwall.png'
def collision_detected(self):
print("Collided with Dumbwall")
class DangerWall(_wall):
pic = 'images/dangerwall.png'
is_killer = True
"Wall that kills the octopus"
def collision_detected(self):
print("Collided with Dangerwall")
class Collectible(pygame.sprite.Sprite):
width = height = 40
is_fixed = False
is_killer = False
def __init__(self, name, x, y):
super().__init__()
# TODO: choose an image based on the name
self.image = pygame.Surface([self.width, self.height])
images = {"crab": 'images/crab.png'}
self.image = pygame.image.load(images.get(name))
self.rect = self.image.get_rect()
self.rect.x, self.rect.y = x, y
def collision_detected(self):
print("Just got a collectible")
class Garden(pygame.sprite.Sprite):
height = 1000 # TODO: screen height
width = 10
is_fixed = True
is_killer = False
is_end = True
def __init__(self, x):
self.image = pygame.image.load("images/garden.png")
self.rect = self.image.get_rect()
self.rect.y = 0
self.rect.x = x
super().__init__()
def collision_detected(self):
print("Now inside the garden")
WIDTH, HEIGHT = 1200, 700
def height_from_bottom(x):
return HEIGHT - Collectible.height - x
LEVELS_SPEC = [
[
# first level
Collectible('crab', 200, height_from_bottom(250)),
Collectible('crab', 200, height_from_bottom(150)),
Collectible('crab', 200, height_from_bottom(50)),
Collectible('crab', 750, 50),
DumbWall(800, 250),
Collectible('crab', 900, 50),
Collectible('crab', 1050, 50),
Collectible('crab', 1180, 50),
Collectible('crab', 1000, height_from_bottom(450)),
Collectible('crab', 1000, height_from_bottom(350)),
Collectible('crab', 1000, height_from_bottom(250)),
Collectible('crab', 1000, height_from_bottom(150)),
Collectible('crab', 1000, height_from_bottom(50)),
DumbWall(1200, 250),
Collectible('crab', 1450, 350),
Collectible('crab', 1450, 250),
Collectible('crab', 1450, 150),
Collectible('crab', 1450, 50),
Collectible('crab', 1580, height_from_bottom(150)),
Collectible('crab', 1580, height_from_bottom(50)),
DangerWall(1600, 0),
Collectible('crab', 1650, 50),
Collectible('crab', 1650, 100),
Collectible('crab', 1650, 150),
Collectible('crab', 1700, 50),
Collectible('crab', 1700, 100),
Collectible('crab', 1700, 150),
Collectible('crab', 2000, height_from_bottom(350)),
Collectible('crab', 2000, height_from_bottom(250)),
Collectible('crab', 2000, height_from_bottom(150)),
Collectible('crab', 2000, height_from_bottom(50)),
Collectible('crab', 2120, 50),
Collectible('crab', 2120, 150),
DangerWall(2150, 250),
Collectible('crab', 2350, 50),
Collectible('crab', 2350, 150),
Collectible('crab', 2350, 250),
Collectible('crab', 2350, 350),
Collectible('crab', 2500, 50),
Collectible('crab', 2500, 150),
Collectible('crab', 2500, 250),
Collectible('crab', 2500, 350),
DangerWall(2650, 250),
Collectible('crab', 3200, height_from_bottom(150)),
Collectible('crab', 3200, height_from_bottom(50)),
DangerWall(3200, 0),
Garden(3600),
],
[
# second level
Collectible('crab', 200, height_from_bottom(250)),
Collectible('crab', 200, height_from_bottom(150)),
Collectible('crab', 200, height_from_bottom(50)),
Collectible('crab', 780, 300),
Collectible('crab', 780, 360),
DangerWall(800, 0, height=240),
DangerWall(800, 500),
Collectible('crab', 1000, HEIGHT - Collectible.height - 50),
DangerWall(1200, 250),
Collectible('crab', 1150, 50),
Collectible('crab', 1300, height_from_bottom(50)),
Collectible('crab', 1300, height_from_bottom(150)),
Collectible('crab', 1580, 300),
Collectible('crab', 1580, 360),
DangerWall(1600, 0, height=240),
DangerWall(1600, 500),
Collectible('crab', 1700, 50),
Collectible('crab', 1700, 150),
Collectible('crab', 1700, HEIGHT - Collectible.height - 50),
Collectible('crab', 2000, HEIGHT - Collectible.height - 50),
DangerWall(2200, 250),
Collectible('crab', 2450, 50),
Collectible('crab', 2450, 150),
Collectible('crab', 2550, 50),
Collectible('crab', 2550, 150),
Collectible('crab', 2650, 50),
Collectible('crab', 2650, 150),
DangerWall(2800, 0),
Garden(3600),
],
[
Collectible('crab', 200, height_from_bottom(300)),
DangerWall(800,0,height=240),
Collectible('crab', 800, 300),
Collectible('crab', 800, 400),
DangerWall(800,500),
DangerWall(900,0,height=300),
DangerWall(900,520),
Collectible('crab', 900, 300),
Collectible('crab', 900, 400),
DangerWall(1000,0,height=240),
DangerWall(1000,600),
Collectible('crab', 1000, 300),
Collectible('crab', 1000, 400),
DangerWall(1100,0,height=300),
DangerWall(1100,500),
Collectible('crab', 1180, height_from_bottom(50)),
Collectible('crab', 1180, height_from_bottom(150)),
Collectible('crab', 1180, height_from_bottom(250)),
Collectible('crab', 1180, height_from_bottom(350)),
Collectible('crab', 1180, height_from_bottom(450)),
Collectible('crab', 1180, height_from_bottom(550)),
Collectible('crab', 1180, height_from_bottom(650)),
DangerWall(1300,0,height=400),
DangerWall(1300,650),
Collectible('crab', 1410, height_from_bottom(50)),
Collectible('crab', 1410, height_from_bottom(150)),
Collectible('crab', 1410, height_from_bottom(250)),
Collectible('crab', 1410, height_from_bottom(350)),
Collectible('crab', 1410, height_from_bottom(450)),
Collectible('crab', 1410, height_from_bottom(550)),
Collectible('crab', 1410, height_from_bottom(650)),
DangerWall(1600,400),
Collectible('crab', 1710, height_from_bottom(50)),
Collectible('crab', 1710, height_from_bottom(150)),
Collectible('crab', 1710, height_from_bottom(250)),
Collectible('crab', 1710, height_from_bottom(350)),
Collectible('crab', 1710, height_from_bottom(450)),
Collectible('crab', 1710, height_from_bottom(550)),
Collectible('crab', 1710, height_from_bottom(650)),
DangerWall(1850,0,height=400),
Collectible('crab', 2010, height_from_bottom(50)),
Collectible('crab', 2010, height_from_bottom(150)),
Collectible('crab', 2010, height_from_bottom(250)),
Collectible('crab', 2010, height_from_bottom(350)),
Collectible('crab', 2010, height_from_bottom(450)),
Collectible('crab', 2010, height_from_bottom(550)),
Collectible('crab', 2010, height_from_bottom(650)),
Garden(2400)
],
]