-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.py
340 lines (319 loc) · 11.1 KB
/
level.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
from characters import Pig, Bird, Node, a_star
from polygon import Polygon
class Level():
def __init__(self, pigs, columns, beams, space):
self.pigs = pigs
self.columns = columns
self.beams = beams
self.space = space
self.number = 0
self.number_of_birds = 4
# lower limit
self.one_star = 30000
self.two_star = 40000
self.three_star = 60000
self.bool_space = False
def open_flat(self, x, y, n):
"""Create a open flat struture"""
y0 = y
for i in range(n):
y = y0+100+i*100
p = (x, y)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (x+60, y)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (x+30, y+50)
self.beams.append(Polygon(p, 85, 20, self.space))
def closed_flat(self, x, y, n):
"""Create a closed flat struture"""
y0 = y
for i in range(n):
y = y0+100+i*125
p = (x+1, y+22)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (x+60, y+22)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (x+30, y+70)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (x+30, y-30)
self.beams.append(Polygon(p, 85, 20, self.space))
def horizontal_pile(self, x, y, n):
"""Create a horizontal pile"""
y += 70
for i in range(n):
p = (x, y+i*20)
self.beams.append(Polygon(p, 85, 20, self.space))
def vertical_pile(self, x, y, n):
"""Create a vertical pile"""
y += 10
for i in range(n):
p = (x, y+85+i*85)
self.columns.append(Polygon(p, 20, 85, self.space))
def move_bird_to_target(self, bird, target_position, grid):
start = Node((int(bird.body.position.x), int(bird.body.position.y)))
end = Node(target_position)
path = a_star(start, end, grid)
if path:
for position in path:
bird.body.position = position
def build_0(self):
"""level 0"""
pig1 = Pig(980, 100, self.space)
pig2 = Pig(985, 182, self.space)
self.pigs.append(pig1)
self.pigs.append(pig2)
p = (950, 80)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (1010, 80)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (980, 150)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (950, 200)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (1010, 200)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (980, 240)
self.beams.append(Polygon(p, 85, 20, self.space))
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
self.one_star = 30000
self.two_star = 40000
self.three_star = 60000
def build_1(self):
"""level 1"""
pig = Pig(1000, 100, self.space)
self.pigs.append(pig)
p = (900, 80)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (850, 80)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (850, 150)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (1105, 210)
self.beams.append(Polygon(p, 85, 20, self.space))
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def build_2(self):
"""level 2"""
pig1 = Pig(880, 180, self.space)
self.pigs.append(pig1)
pig2 = Pig(1000, 230, self.space)
self.pigs.append(pig2)
p = (880, 80)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (880, 150)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (1000, 80)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (1000, 180)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (1000, 210)
self.beams.append(Polygon(p, 85, 20, self.space))
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def build_3(self):
"""level 3"""
pig = Pig(950, 320, self.space)
pig.life = 25
self.pigs.append(pig)
pig = Pig(885, 225, self.space)
pig.life = 25
self.pigs.append(pig)
pig = Pig(1005, 225, self.space)
pig.life = 25
self.pigs.append(pig)
p = (1100, 100)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (1070, 152)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (1040, 100)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (980, 100)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (920, 100)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (950, 152)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (1010, 180)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (860, 100)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (800, 100)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (830, 152)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (890, 180)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (860, 223)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (920, 223)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (980, 223)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (1040, 223)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (890, 280)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (1010, 280)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (950, 300)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (920, 350)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (980, 350)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (950, 400)
self.beams.append(Polygon(p, 85, 20, self.space))
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def build_4(self):
"""level 4"""
pig = Pig(900, 300, self.space)
self.pigs.append(pig)
pig = Pig(1000, 500, self.space)
self.pigs.append(pig)
pig = Pig(1100, 400, self.space)
self.pigs.append(pig)
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def build_5(self):
"""level 5"""
pig = Pig(900, 70, self.space)
self.pigs.append(pig)
pig = Pig(1000, 152, self.space)
self.pigs.append(pig)
for i in range(9):
p = (800, 70+i*21)
self.beams.append(Polygon(p, 85, 20, self.space))
for i in range(4):
p = (1000, 70+i*21)
self.beams.append(Polygon(p, 85, 20, self.space))
p = (970, 176)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (1026, 176)
self.columns.append(Polygon(p, 20, 85, self.space))
p = (1000, 230)
self.beams.append(Polygon(p, 85, 20, self.space))
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def build_6(self):
"""level 6"""
pig = Pig(920, 533, self.space)
pig.life = 40
self.pigs.append(pig)
pig = Pig(820, 533, self.space)
self.pigs.append(pig)
pig = Pig(720, 633, self.space)
self.pigs.append(pig)
self.closed_flat(895, 423, 1)
self.vertical_pile(900, 0, 5)
self.vertical_pile(926, 0, 5)
self.vertical_pile(950, 0, 5)
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def build_7(self):
"""level 7"""
pig = Pig(978, 180, self.space)
pig.life = 30
self.pigs.append(pig)
pig = Pig(978, 280, self.space)
pig.life = 30
self.pigs.append(pig)
pig = Pig(978, 80, self.space)
pig.life = 30
self.pigs.append(pig)
self.open_flat(950, 0, 3)
self.vertical_pile(850, 0, 3)
self.vertical_pile(830, 0, 3)
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def build_8(self):
"""level 8"""
pig = Pig(1000, 180, self.space)
pig.life = 30
self.pigs.append(pig)
pig = Pig(1078, 280, self.space)
pig.life = 30
self.pigs.append(pig)
pig = Pig(900, 80, self.space)
pig.life = 30
self.pigs.append(pig)
self.open_flat(1050, 0, 3)
self.open_flat(963, 0, 2)
self.open_flat(880, 0, 1)
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def build_9(self):
"""level 9"""
pig = Pig(1000, 180, self.space)
pig.life = 20
self.pigs.append(pig)
pig = Pig(900, 180, self.space)
pig.life = 20
self.pigs.append(pig)
self.open_flat(1050, 0, 3)
self.open_flat(963, 0, 2)
self.open_flat(880, 0, 2)
self.open_flat(790, 0, 3)
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def build_10(self):
"""level 10"""
pig = Pig(960, 250, self.space)
pig.life = 20
self.pigs.append(pig)
pig = Pig(820, 160, self.space)
self.pigs.append(pig)
pig = Pig(1100, 160, self.space)
self.pigs.append(pig)
self.vertical_pile(900, 0, 3)
self.vertical_pile(930, 0, 3)
self.vertical_pile(1000, 0, 3)
self.vertical_pile(1030, 0, 3)
self.horizontal_pile(970, 250, 2)
self.horizontal_pile(820, 0, 4)
self.horizontal_pile(1100, 0, 4)
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def build_11(self):
"""level 11"""
pig = Pig(820, 177, self.space)
self.pigs.append(pig)
pig = Pig(960, 150, self.space)
self.pigs.append(pig)
pig = Pig(1100, 130, self.space)
self.pigs.append(pig)
pig = Pig(890, 270, self.space)
pig.life = 30
self.pigs.append(pig)
self.horizontal_pile(800, 0, 5)
self.horizontal_pile(950, 0, 3)
self.horizontal_pile(1100, 0, 2)
self.vertical_pile(745, 0, 2)
self.vertical_pile(855, 0, 2)
self.vertical_pile(900, 0, 2)
self.vertical_pile(1000, 0, 2)
p = (875, 230)
self.beams.append(Polygon(p, 85, 20, self.space))
self.number_of_birds = 4
if self.bool_space:
self.number_of_birds = 8
def load_level(self):
try:
build_name = "build_"+str(self.number)
getattr(self, build_name)()
except AttributeError:
self.number = 0
build_name = "build_"+str(self.number)
getattr(self, build_name)()