-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene.py
More file actions
340 lines (315 loc) · 13 KB
/
scene.py
File metadata and controls
340 lines (315 loc) · 13 KB
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
'''This is scene.py '''
import os
import time
import random
from board import BOARD
from enemy import ELIST
from bricks import BRICK_LIST, Brick
from person import CHECKPOINT, PERSON
from manage import Manage
from config import BOSS_B
from polymorph import POLY
from move_bar import BLIST
from flag import FLAG
from coin import COIN_LIST
from boss import BOSS
from bullet import BULLET_LIST, BOSS_BULLET, Bullet
class Scene():
'''code for creating scene'''
# make cloud mountain
@classmethod
def make_cm(cls, k):
'''make cloud and mountain'''
BOARD.board_initialise(k) # board initialisation
BOARD.make_cloud(6, 25)
BOARD.make_cloud(4, 45)
BOARD.make_mountain(8, 10)
BOARD.make_mountain(4, 50)
# for brick and coins
@classmethod
def brick_coin(cls):
'''make brick, coin'''
flag = 0
for k in BRICK_LIST:
POLY.print_poly(k, k.xps, k.yps)
if PERSON.xpos == 18 and PERSON.ypos >= 345 and PERSON.ypos <= 347 and flag == 0:
PERSON.sym = 'M'
try:
sound = open('smb_powerup.wav', 'r')
os.system('aplay -q ./smb_powerup.wav&')
except:
pass
BRICK_LIST.append(Brick(14, 345, '*', 3))
flag = 1
# print(PERSON.xpos,PERSON.ypos,k.xps,k.yps)
if PERSON.xpos == k.xps + 4 and PERSON.ypos >= k.yps and PERSON.ypos <= k.yps + 2:
if k.coin != '*' and k.coin != 0:
k.coin -= 1
try:
sound = open('smb_coin.wav', 'r')
os.system('aplay -q ./smb_coin.wav&')
except:
pass
Manage.coinscollect()
Manage.changescore('coin')
else:
try:
sound = open('smb_bump.wav', 'r')
os.system('aplay -q ./smb_bump.wav&')
except:
pass
if k.coin == 0:
BRICK_LIST.remove(k)
try:
sound = open('smb_breakblock.wav', 'r')
os.system('aplay -q ./smb_breakblock.wav&')
except:
pass
Manage.changescore('brick')
for k in COIN_LIST:
# k.print_coin(k.x,k.y)
POLY.print_poly(k, k.xps, k.yps)
if PERSON.xpos == k.xps and PERSON.ypos == k.yps:
try:
sound = open('smb_coin.wav', 'r')
os.system('aplay -q ./smb_coin.wav&')
except:
pass
Manage.coinscollect()
COIN_LIST.remove(k)
Manage.changescore('coin')
# moving bar
@classmethod
def moving_bar(cls):
'''make moving bar'''
for k in BLIST:
if time.time() - k.tym > 0.2:
k.tym = time.time()
k.yps += k.vel
if PERSON.ypos == k.yps - 1 and PERSON.xpos + 1 == k.xps and k.vel > 0:
PERSON.ypos = k.yps
elif PERSON.ypos == k.yps + k.lgt and PERSON.xpos + 1 == k.xps and k.vel < 0:
PERSON.ypos = k.yps + k.lgt - 1
elif k.xps == PERSON.xpos + 1 and PERSON.ypos >= k.yps \
and PERSON.ypos < k.yps + k.lgt:
PERSON.ypos += k.vel
# k.make_move()
POLY.move_poly(k)
k.make_bar(k.xps, k.yps, k.lgt)
# PIPE,PITS AND SPRING
@classmethod
def make_pps(cls):
'''make pipe, pit, spring'''
BOARD.make_pipe(65, 4)
BOARD.make_pipe(90, 5)
BOARD.make_pipe(120, 6)
BOARD.make_pipe(140, 4)
BOARD.make_pit(160, 5)
BOARD.make_spring(359, 25)
BOARD.make_pit(200, 45)
BOARD.make_pit(403, 10)
BOARD.make_spring(400, 25)
BOARD.make_pipe(430, 6)
BOARD.make_spring(495, 18)
@classmethod
def make_flag(cls):
'''make end flag'''
# FLAG.print_FLAGag(FLAG.x)
POLY.print_poly(FLAG, FLAG.xps)
if PERSON.ypos == 504:
if FLAG.first == 0:
try:
sound = open('smb_flagpole.wav', 'r')
os.system('aplay -q ./smb_flagpole.wav&')
except:
pass
FLAG.first = PERSON.xpos - 1
# print(FLAG.first)
# FLAG.move(FLAG.first)
POLY.move_poly(FLAG, FLAG.first)
Manage.changescore('enemy1')
@classmethod
def enemy(cls, lgt):
'''make enemy bullets'''
# for bullets
for k in BULLET_LIST:
BOARD.mat[k.xps][k.yps] = k.sym
if time.time() - k.tym > 0.1:
k.tym = time.time()
if BOARD.checkstar(k.xps, k.yps + 1) is 1 or k.yps > lgt + 80:
BULLET_LIST.remove(k)
else:
k.yps += k.vel
if k.xps >= 22 and k.xps <= 25 and k.yps == BOSS.y and BOSS.Health >= 0:
Manage.bosslife()
BULLET_LIST.remove(k)
BOSS.Health -= 1
if BOSS.Health >= 0:
if time.time() - BOSS.bosstime > 1:
BOSS.bosstime = time.time()
BOSS.x = random.randint(22, 25)
BOSS.y = random.randint(460, 470)
BOSS_BULLET.append(Bullet(BOSS.x - 2, BOSS.y, -1, BOSS_B))
prob = random.randint(1, 100)
if prob < 20:
BOSS_BULLET.append(Bullet(BOSS.x - 3, BOSS.y, -1, BOSS_B))
if prob < 10:
BOSS_BULLET.append(Bullet(BOSS.x - 1, BOSS.y, -1, BOSS_B))
if prob == 2:
BOSS_BULLET.append(Bullet(BOSS.x, BOSS.y, -1, BOSS_B))
if PERSON.xpos <= 25 and PERSON.xpos >= 22 and PERSON.ypos >= BOSS.y \
and PERSON.ypos <= BOSS.y + 5:
Manage.changelives()
zps = 0
for i, j in CHECKPOINT:
if j >= PERSON.ypos and i is not None:
PERSON.xpos = CHECKPOINT[zps - 1][0]
PERSON.ypos = CHECKPOINT[zps - 1][1]
break
zps += 1
for k in BOSS_BULLET:
if (k.xps >= PERSON.xpos -
1 and k.xps <= PERSON.xpos or k.xps +
1 == PERSON.xpos) and (k.yps >= PERSON.ypos -
1 and k.yps <= PERSON.ypos):
Manage.changelives()
BOSS_BULLET.remove(k)
for k in BOSS_BULLET:
BOARD.mat[k.xps][k.yps] = k.sym
if time.time() - k.tym > 0.1:
k.tym = time.time()
if BOARD.checkstar(k.xps, k.yps - 1) is 1 or k.yps < lgt:
BOSS_BULLET.remove(k)
else:
k.yps += k.vel
# BOSS.print_boss(BOSS.x,BOSS.y)
POLY.print_poly(BOSS, BOSS.x, BOSS.y)
# print(lgt)
for k in ELIST:
if k.type == "enemy1":
flagvar = False
if time.time() - k.tym > 0.5:
k.tym = time.time()
if k.yps >= lgt and k.yps <= lgt + 80:
# k.move(None)
POLY.move_poly(k)
if(PERSON.xpos == k.xps and PERSON.ypos == k.yps):
Manage.changelives()
flagvar = True
zps = 0
for i, j in CHECKPOINT:
if j >= PERSON.ypos:
PERSON.xpos = CHECKPOINT[zps - 1][0]
PERSON.ypos = CHECKPOINT[zps - 1][1]
break
zps += 1
if PERSON.xpos + \
1 == k.xps and (PERSON.ypos - 1 == k.yps or PERSON.ypos == k.yps):
try:
sound = open('smb_stomp.wav', 'r')
os.system('aplay -q ./smb_stomp.wav&')
except:
pass
Manage.enemykill()
Manage.changescore(k.type)
PERSON.xpos -= 2
ELIST.remove(k)
if lgt > 100:
if PERSON.xpos == k.xps:
if k.vel > 0 and PERSON.ypos < k.yps - 4:
k.vel = -k.vel
if k.vel < 0 and PERSON.ypos > k.yps + 4:
k.vel = -k.vel
if k.xps == 26:
BOARD.mat[k.xps][k.yps] = ' '
ELIST.remove(k)
# k.print_enemy(k.xps,k.yps)
POLY.print_poly(k, k.xps, k.yps)
if flagvar:
return PERSON.ypos - 10
if k.type == "enemy2": # TURTLE ENEMY
flagvar = False
if time.time() - k.tym > 5 and k.sym == ' ':
k.tym = time.time()
k.sym = '^'
k.vel = random.randrange(-1, 2, 2)
if k.yps >= lgt and k.yps <= lgt + 80:
# k.move()
POLY.move_poly(k)
if PERSON.xpos == k.xps and PERSON.ypos + \
1 == k.yps and k.sym == ' ' and k.vel == 0:
try:
sound = open('smb_kick.wav', 'r')
os.system('aplay -q ./smb_kick.wav&')
except:
pass
k.vel = 1
if PERSON.xpos == k.xps and PERSON.ypos - \
2 == k.yps and k.sym == ' ' and k.vel == 0:
try:
sound = open('smb_kick.wav', 'r')
os.system('aplay -q ./smb_kick.wav&')
except:
pass
k.vel = -1
# enemy-enemy collision
if k.sym == ' ' and k.vel != 0 and time.time() - k.tym > 0.1:
k.tym = time.time()
if k.yps >= lgt and k.yps <= lgt + 80:
POLY.move_poly(k)
for enmy in ELIST:
if(enmy.xps == k.xps and enmy.yps == k.yps and k != enmy):
try:
sound = open('smb_stomp.wav', 'r')
os.system('aplay -q ./smb_stomp.wav&')
except:
pass
Manage.enemykill()
Manage.changescore(enmy.type)
ELIST.remove(enmy)
if time.time() - k.tym > 0.5 and k.sym == '^':
k.tym = time.time()
if k.yps >= lgt and k.yps <= lgt + 80:
POLY.move_poly(k)
if(PERSON.xpos == k.xps and (PERSON.ypos == k.yps or PERSON.ypos -
1 == k.yps) and k.vel != 0):
Manage.changelives()
flagvar = True
zps = 0
for i, j in CHECKPOINT:
if j >= PERSON.ypos:
PERSON.xpos = CHECKPOINT[zps - 1][0]
PERSON.ypos = CHECKPOINT[zps - 1][1]
break
zps += 1
if(PERSON.xpos + 2 == k.xps and (PERSON.ypos == k.yps or PERSON.ypos -
1 == k.yps) and k.sym == '^'):
k.sym = ' '
k.tym = time.time()
PERSON.xpos -= 2
k.vel = 0
if(PERSON.xpos + 1 == k.xps and (PERSON.ypos == k.yps or PERSON.ypos -
1 == k.yps) and k.sym == ' '):
try:
sound = open('smb_stomp.wav', 'r')
os.system('aplay -q ./smb_stomp.wav&')
except:
pass
Manage.enemykill()
Manage.changescore(k.type)
PERSON.xpos -= 2
ELIST.remove(k)
if lgt > 100:
if PERSON.xpos == k.xps and k.sym == '^':
if k.vel > 0 and PERSON.ypos < k.yps - 4:
k.vel = -k.vel
if k.vel < 0 and PERSON.ypos > k.yps + 4:
k.vel = -k.vel
if k.xps == 26:
BOARD.mat[k.xps][k.yps] = ' '
ELIST.remove(k)
# k.print_enemy(k.xps,k.yps,k.sym)
POLY.print_poly(k, k.xps, k.yps)
if flagvar:
return PERSON.ypos - 10
return lgt