-
Notifications
You must be signed in to change notification settings - Fork 0
/
SuperMario.py
631 lines (595 loc) · 31.9 KB
/
SuperMario.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
import Mario
import Settings
import World
import Text
import WORLD_MAP
import fireball
from pygame import *
class SuperMario:
def __init__(self):
mixer.pre_init(44100, -16, 1, 4096)
mixer.init()
init()
self.clock = time.Clock()
self.screen = Settings.SCREEN
self.should_exit = False
self.gameTimer = time.get_ticks()
self.gameTime = 400
def initGame(self):
mixer.init()
self.SOUNDS = {}
for sound_name in ['smb_breakblock', 'smb_bump', 'smb_coin', 'smb_fireball',
'smb_jump-small', 'smb_jump-super', 'smb_kick', 'smb_mariodie',
'smb_pipe', 'smb_powerup', 'smb_powerup_appears', 'smb_stomp',
'smb_warning', 'smb_gameover', 'smb_stage_clear']:
self.SOUNDS[sound_name] = mixer.Sound(Settings.SOUND_PATH + '{}.wav'.format(sound_name))
self.SOUNDS[sound_name].set_volume(0.2)
mixer.music.load('music.ogg')
mixer.music.set_volume(0.2)
mixer.music.play(-1)
self.player_xpos = 700
self.player_ypos = 480
self.gameTimer_tock = 400
self.tock_index = 0
self.lowerTime = True
self.level = '1-1'
self.slideController = False
self.playSlideSound = False
self.levelTransition = False
self.playedlevelTransition = False
self.warningPlayed = False
self.coinAmount = 0
self.player = Mario.Mario(self.player_xpos, self.player_ypos)
self.world = World.World(1, 1, 1400)
self.enemies = sprite.Group()
self.goombas = sprite.Group()
self.koopas = sprite.Group()
self.playerGroup = sprite.Group()
self.textGroup = sprite.Group()
self.blocks = sprite.Group()
self.groundBlocks = sprite.Group()
self.QuestionBlocks = sprite.Group()
self.normalBlocks = sprite.Group()
self.normalPipes = sprite.Group()
self.groundUpBlocks = sprite.Group()
self.move_steps = sprite.Group()
self.long_pipes = sprite.Group()
self.flags = sprite.Group()
self.flagPoles = sprite.Group()
self.castles = sprite.Group()
self.instruction_board = sprite.Group()
self.brushes = sprite.Group()
self.clouds = sprite.Group()
self.mountains = sprite.Group()
self.unmove_items = sprite.Group()
self.fireballs = sprite.Group()
self.fireball_amount = 5
self.fireball_timer = 0
self.itemGroup = sprite.Group()
self.mushrooms = sprite.Group()
self.flowers = sprite.Group()
self.coins = sprite.Group()
self.score = 0
self.lives = 3
self.spaceDown = False
self.newLifeHandle = False
self.steadyText = sprite.Group()
self.playerGroup.add(self.player)
WORLD_MAP.world1_1(game)
def handleDeath(self, currentTime):
mixer.music.pause()
self.SOUNDS['smb_mariodie'].play()
self.player.isAlive = False
while not self.player.update(currentTime):
display.update()
self.screen.blit(self.world.image, (self.world.rel_x - self.world.bgWidth, 0))
if self.world.rel_x < 1200: # screen width
self.screen.blit(self.world.image, (self.world.rel_x, 0))
for item in self.unmove_items:
self.screen.blit(item.image, item.rect)
for block in self.blocks:
self.screen.blit(block.image, block.rect)
for item in self.itemGroup:
self.screen.blit(item.image, item.rect)
for enemy in self.enemies:
self.screen.blit(enemy.image, enemy.rect)
for fireball in self.fireballs:
self.screen.blit(fireball.image, fireball.rect)
self.Kill_All(self.player_xpos, self.player_ypos, '1-1')
if self.lives < 0:
self.SOUNDS['smb_gameover'].play()
self.lives = 3
self.score = 0
waiter = time.get_ticks()
end = waiter + 4100
while waiter < end:
waiter = time.get_ticks()
mixer.music.set_pos(0)
mixer.music.unpause()
def Kill_All(self, player_xpos, player_ypos, *args):
self.lives -= 1
state = 'Mini'
if self.player.rect.top < Settings.SCREEN_HEIGHT:
state = self.player.state
for block in self.blocks:
block.kill()
for item in self.itemGroup:
item.kill()
for enemy in self.enemies:
enemy.kill()
for text in self.textGroup:
text.kill()
for player in self.playerGroup:
player.kill()
for fireball in self.fireballs:
fireball.kill()
for item in self.unmove_items:
item.kill()
self.player = Mario.Mario(player_xpos, player_ypos, state)
self.playerGroup.add(self.player)
self.world.kill()
if self.level == '1-1':
self.world = World.World(1, 1, 1400)
elif self.level == '1-2':
self.world = World.World(1, 2, 1400)
if self.level == '1-1':
WORLD_MAP.world1_1(game)
elif self.level == '1-2':
WORLD_MAP.world1_2(game)
self.newLifeHandle = False
self.gameTimer_tock = 400
def checkInput(self, currenttime):
if currenttime - self.gameTimer > Settings.GAME_FPS:
self.keys = key.get_pressed()
for e in event.get():
if e.type == KEYDOWN:
if e.key == K_SPACE:
self.spaceDown = True
elif e.key == K_ESCAPE:
sys.exit()
if e.type == KEYUP:
if e.key == K_SPACE:
self.spaceDown = False
if self.spaceDown:
if not self.player.isJumping and self.player.isStanding:
if self.player.jump_height == 0 and not self.player.isJumping and self.player.jumpCounter == 0:
if self.player.state != 'Mini':
self.SOUNDS['smb_jump-super'].play()
else:
self.SOUNDS['smb_jump-small'].play()
self.player.isJumping = True
self.player.jump_height = 1
self.player.jumpCounter += 1
else:
if self.player.jumpCounter > 2 and self.player.jump_height == 1:
self.player.jump_height = 2
if self.player.jumpCounter > 7 and self.player.jump_height == 2:
self.player.jump_height = 3
self.player.jumpCounter += 1
else:
self.player.jumpCounter = 0
if self.keys[K_DOWN] and self.player.state != 'Mini':
self.player.isCrouching = True
self.player.idle = True
self.player.runLeft = False
self.player.runRight = False
else:
self.player.isCrouching = False
if self.keys[K_LCTRL] or self.keys[K_RCTRL]:
if self.player.state == 'Fire' and self.fireball_timer == 0 and self.fireball_amount > 0:
self.SOUNDS['smb_fireball'].play()
self.fireball_amount -= 1
self.player.shootFire = True
self.fireballs.add(fireball.fireball(self.player.rect.x, self.player.rect.y,
self.player.direction))
self.fireball_timer = 8
else:
if self.fireball_timer > 0:
self.fireball_timer -= 1
if self.keys[K_LEFT] and not self.keys[K_RIGHT]:
self.player.idle = False
self.player.runLeft = True
self.player.runRight = False
elif self.keys[K_RIGHT] and not self.keys[K_LEFT]:
self.player.idle = False
self.player.runRight = True
self.player.runLeft = False
else:
self.player.idle = True
self.player.runLeft = False
self.player.runLeft = False
def check_camera(self):
#-------move mario--------------------
velocity = self.player.velocity
self.world.playerPosX += (Settings.MARIO_RUN_SPEED * (-1 if velocity < 0 else 1 if velocity > 0 else 0))
self.world.actualPosX += (Settings.MARIO_RUN_SPEED * (-1 if velocity < 0 else 1 if velocity > 0 else 0))
self.left_bound = self.world.actualPosX % 600
if self.world.playerPosX > self.world.stageWidth:
self.world.playerPosX = self.world.stageWidth
if self.player.rect.x < self.world.left_bound - 40: # half width of mario
self.world.playerPosX = self.world.left_bound
if self.world.playerPosX < self.world.startScrollingPosX:
self.player.rect.right = self.world.playerPosX
elif self.world.playerPosX > self.world.stageWidth - self.world.startScrollingPosX:
self.player.rect.right = self.world.playerPosX - self.world.stageWidth + 1200 # screen width
else:
self.player.rect.right = self.world.startScrollingPosX
if self.world.actualPosX > 600:
if self.world.playerPosX >= 600:
self.world.playerPosX = 599
for block in self.blocks:
if block not in self.normalBlocks:
block.rect.x -= Settings.MARIO_RUN_SPEED
for block in self.normalBlocks:
block.rect.x -= Settings.MARIO_RUN_SPEED
block.break_rect1.x -= Settings.MARIO_RUN_SPEED
block.break_rect2.x -= Settings.MARIO_RUN_SPEED
block.break_rect3.x -= Settings.MARIO_RUN_SPEED
for item in self.itemGroup:
item.rect.x -= Settings.MARIO_RUN_SPEED
for enemy in self.enemies:
enemy.rect.x -= Settings.MARIO_RUN_SPEED
for item in self.unmove_items:
item.rect.x -= Settings.MARIO_RUN_SPEED
for fireball in self.fireballs:
fireball.rect.x -= 4
for text in self.textGroup:
text.rect.x -= Settings.MARIO_RUN_SPEED
if self.player.direction == 1:
self.world.stagePosX -= velocity
elif self.player.direction == -1:
self.world.playerPosX = self.world.startScrollingPosX
self.world.rel_x = self.world.stagePosX % self.world.bgWidth
def update(self, currentTime):
if currentTime - self.gameTimer > Settings.GAME_FPS:
self.screen.blit(self.world.image, (self.world.rel_x - self.world.bgWidth, 0))
if self.world.rel_x < 1200: # screen width
self.screen.blit(self.world.image, (self.world.rel_x, 0))
self.unmove_items.update(currentTime)
self.player.update(currentTime)
self.itemGroup.update(currentTime)
self.fireballs.update()
self.blocks.update(currentTime)
self.textGroup.update(currentTime)
self.enemies.update(self.left_bound - 500, self.left_bound + Settings.SCREEN_WIDTH)
self.gameTimer = time.get_ticks()
def check_Terrain(self, mario, collision):
boot = False
if mario.rect.bottom in (collision.rect.top + index for index in range(0, Settings.MARIO_FALL_SPEED + 3)):
if not ((mario.rect.right > collision.rect.left - 20) and (mario.rect.right < collision.rect.left + 20) \
or (mario.rect.left < collision.rect.right + 20) and (mario.rect.left > collision.rect.right - 20)):
if not mario.isReachedApex:
if mario.rect.bottom < mario.lastGroundYPos and mario.isJumping:
mario.isJumping = False
self.player.jump_height = 0
mario.lastGroundYPos = collision.rect.top + 1
mario.rect.bottom = collision.rect.top + 1
mario.isStanding = True
if mario.isReachedApex:
mario.lastGroundYPos = collision.rect.top + 1
mario.rect.bottom = collision.rect.top + 1
mario.isStanding = True
mario.isReachedApex = False
mario.isJumping = False
self.player.jump_height = 0
if mario.rect.colliderect(collision.rect):
if mario.rect.top in range(collision.rect.bottom - 20, collision.rect.bottom):
if mario.rect.right not in range(collision.rect.left - 1, collision.rect.left + 3) \
and mario.rect.left not in range(collision.rect.right - 3, collision.rect.right + 1) \
and not mario.isReachedApex:
boot = True
mario.isJumping = False
mario.jump_height = 0
if collision in self.QuestionBlocks:
if not collision.gotHit:
if collision.contents == 'Coin':
self.SOUNDS['smb_coin'].play()
self.score += 200
self.coinAmount += 1
collision.Activate(mario.state, collision.rect.x, collision.rect.y,
self.itemGroup, self.mushrooms, self.flowers, self.coins,
self.SOUNDS['smb_powerup_appears'])
if collision in self.normalBlocks:
if mario.state != 'Mini':
self.SOUNDS['smb_breakblock'].play()
else:
self.SOUNDS['smb_bump'].play()
collision.Activate(mario.state)
if mario.rect.left in (collision.rect.right + 3 - index for index in range(0, 41)) and not boot:
if mario.rect.top not \
in (collision.rect.bottom - index for index in range(0, Settings.MARIO_JUMP_SPEED - 1)):
if mario.rect.bottom > collision.rect.top + 1:
mario.rect.left = collision.rect.right + 2
mario.velocity = 0
mario.runLeft = False
if mario.rect.right in (collision.rect.left - 3 + index for index in range(0, 41)):
if mario.rect.top not \
in (collision.rect.bottom - index for index in range(0, Settings.MARIO_JUMP_SPEED - 1)) and not boot:
if mario.rect.bottom > collision.rect.top + 1:
mario.rect.right = collision.rect.left - 2
mario.velocity = 0
mario.runRight = False
def Slide(self):
collisions = sprite.groupcollide(self.playerGroup, self.flagPoles, False, False)
for flagpole in self.flagPoles:
if self.player.rect.bottom >= flagpole.rect.bottom:
self.slideController = False
self.levelTransition = True
if not self.playedlevelTransition:
self.SOUNDS['smb_stage_clear'].play()
self.playedlevelTransition = True
self.player.image = Settings.MARIO_FIRE_IMAGES['22'] if self.player.state == 'Fire' else \
Settings.MARIO_BIG_IMAGES['22'] if self.player.state == 'Big' else \
Settings.MARIO_MINI_IMAGES['20']
pos = self.player.rect.bottomleft
self.player.rect = self.player.image.get_rect(bottomleft=pos)
if self.slideController:
self.player.rect.y += 4
for flag in self.flags:
flag.rect.y = self.player.rect.top - 10
self.gameTimer_tock -= 1
self.score += 100
self.SOUNDS['smb_coin'].play()
else:
self.SOUNDS['smb_coin'].play()
self.score += 100
self.gameTimer_tock -= 1
if self.levelTransition and self.gameTimer_tock <= 0:
self.player.Sliding = False
self.levelTransition = False
self.slideController = False
if self.level == '1-1':
# level transition. killall will make a new world, mario's state will be carried over.
# set his new coords here
#start the mixer playing the corresponding oog here. i couldnt find it in time, this is up to you to get
self.level = '1-2'
mixer.music.load('Sounds/Underground.wav')
mixer.music.play(-1)
self.player_xpos = self.player_xpos
self.player_ypos = self.player_ypos
self.Kill_All(self.player_xpos, self.player_ypos)
self.lowerTime = True
def checkCollisions(self, currentTime):
collision = False
grow_collision = False
enemy_collision = False
if not self.player.movementLock:
collision = sprite.groupcollide(self.playerGroup, self.blocks, False, False)
grow_collision = sprite.groupcollide(self.playerGroup, self.itemGroup, False, False)
enemy_collision = sprite.groupcollide(self.playerGroup, self.enemies, False, False)
if self.levelTransition:
self.transition()
if self.player.Sliding:
self.Slide()
item_collison = sprite.groupcollide(self.itemGroup, self.blocks, False, False)
fireball_world_collision = sprite.groupcollide(self.fireballs, self.blocks, False, False)
fireball_enemy_collision = sprite.groupcollide(self.fireballs, self.enemies, False, False)
enemy_world_collison = sprite.groupcollide(self.enemies, self.blocks, False, False)
enemy_enemy_collison = sprite.groupcollide(self.goombas, self.koopas, False, False)
flagpole_collisions = sprite.groupcollide(self.playerGroup, self.flagPoles, False, False)
if not self.player.movementLock:
if flagpole_collisions:
self.SOUNDS['smb_stage_clear'].play()
self.lowerTime = False
self.player.Sliding = True
self.slideController = True
self.player.movementLock = True
mixer.music.pause()
if collision:
for mario, block in collision.items():
for collision in block:
self.check_Terrain(mario, collision)
else:
self.player.isStanding = False
if grow_collision:
for mario, items in grow_collision.items():
for item in items:
if mario.rect.bottom in range(item.rect.top - 2, item.rect.bottom + 2):
if mario.state == 'Mini' and item in self.mushrooms and not item.isEmerging:
self.SOUNDS['smb_powerup'].play()
mario.changeMarioState('Mushroom')
item.kill()
if mario.state == 'Big' and item in self.flowers and not item.isEmerging:
self.SOUNDS['smb_powerup'].play()
mario.changeMarioState('Flower')
item.kill()
if mario.state == 'Fire' and item in self.flowers and not item.isEmerging:
self.SOUNDS['smb_coin'].play()
text = Text.Text(Settings.FONT, 20, '1000', (255, 255, 255), item.rect.x,
item.rect.y - (45 if self.player.state == 'Mini' else 85))
self.textGroup.add(text)
self.score += 1000
item.kill()
if mario.state == 'Big' and item in self.mushrooms and not item.isEmerging:
self.SOUNDS['smb_coin'].play()
text = Text.Text(Settings.FONT, 20, '1000', (255, 255, 255), item.rect.x,
item.rect.y - (45 if self.player.state == 'Mini' else 85))
self.textGroup.add(text)
self.score += 1000
item.kill()
if enemy_collision:
for mario, baddies in enemy_collision.items():
for enemy in baddies:
if enemy.is_alive:
if mario.rect.bottom < enemy.rect.top + 10:
if enemy in self.koopas:
if enemy.hasShell:
self.SOUNDS['smb_stomp'].play()
mario.isJumping = True
mario.jump_height = 1
mario.isReachedApex = False
enemy.hasShell = False
else:
self.SOUNDS['smb_kick'].play()
enemy.Spin(mario.direction)
mario.isJumping = True
mario.jump_height = 1
mario.jumpCounter = 0
mario.isReachedApex = False
if enemy in self.goombas:
self.SOUNDS['smb_stomp'].play()
mario.isJumping = True
mario.jump_height = 1
mario.jumpCounter = 0
mario.isReachedApex = False
enemy.is_alive = False
text = Text.Text(Settings.FONT, 20, '200', (255, 255, 255), enemy.rect.x,
enemy.rect.y - (45 if self.player.state == 'Mini' else 85))
self.textGroup.add(text)
self.score += 200
else:
if enemy in self.koopas:
if not enemy.hasShell and not enemy.isMoving:
self.SOUNDS['smb_kick'].play()
enemy.Spin(mario.direction)
else:
if mario.state != 'Mini':
self.SOUNDS['smb_pipe'].play()
mario.changeMarioState('Damage')
else:
self.handleDeath(currentTime)
else:
if mario.state != 'Mini':
self.SOUNDS['smb_pipe'].play()
mario.changeMarioState('Damage')
else:
self.SOUNDS['smb_mariodie'].play()
self.handleDeath(currentTime)
if enemy_enemy_collison:
for goomba, koopas in enemy_enemy_collison.items():
for koopa in koopas:
if goomba.is_alive and koopa.is_alive:
if koopa.isMoving:
self.SOUNDS['smb_kick'].play()
goomba.fireBallDeath = True
goomba.is_alive = False
score = 200 + (0 if koopa.enemies_hit == 0 else 100 if koopa.enemies_hit == 1
else 300 if koopa.enemies_hit == 2 else 600 if koopa.enemies_hit == 3
else 800)
koopa.enemies_hit += 1
text = Text.Text(Settings.FONT, 20, str(score), (255, 255, 255), goomba.rect.x,
goomba.rect.y - 5)
self.textGroup.add(text)
self.score += score
else:
koopa.hitWall = True
goomba.hitWall = True
if item_collison:
for item, block in item_collison.items():
for collision in block:
if item in self.mushrooms:
if item.rect.bottom in range(collision.rect.top-6, collision.rect.top + 13):
item.rect.bottom = collision.rect.top + 1
item.isStanding = True
if item.rect.left in (collision.rect.right + 3 - index for index in range(0, 41)) or \
item.rect.right in (collision.rect.left - 3 + index for index in range(0, 41)):
if item.rect.bottom not in range(collision.rect.top - 2, collision.rect.top + 2):
item.hitWall = True
if fireball_world_collision:
for fireball, terrain in fireball_world_collision.items():
for block in terrain:
if fireball.rect.top <= block.rect.bottom + 3 and fireball.rect.top >= block.rect.top:
fireball.is_alive = False
self.fireball_amount += 1
if fireball.rect.bottom in range(block.rect.top - 6, block.rect.top + 13):
fireball.rect.bottom = block.rect.top + 1
fireball.rising = 1
fireball.last_y = block.rect.top - 1
if fireball.rect.left in (block.rect.right + 3 - index for index in range(0, 41)) or \
fireball.rect.right in (block.rect.left - 3 + index for index in range(0, 41)):
if fireball.rect.bottom not in range(block.rect.top - 2, block.rect.top + 2):
fireball.is_alive = False
self.fireball_amount += 1
if fireball_enemy_collision:
for fireball, baddies in fireball_enemy_collision.items():
for enemy in baddies:
if fireball.is_alive:
if enemy in self.koopas:
if enemy.is_alive:
self.SOUNDS['smb_kick'].play()
enemy.is_alive = False
text = Text.Text(Settings.FONT, 20, '200', (255, 255, 255), enemy.rect.x, enemy.rect.y - 5)
self.textGroup.add(text)
self.score += 200
fireball.is_alive = False
if enemy in self.goombas:
if enemy.is_alive:
self.SOUNDS['smb_kick'].play()
enemy.is_alive = False
enemy.fireBallDeath = True
text = Text.Text(Settings.FONT, 20, '200', (255, 255, 255), enemy.rect.x, enemy.rect.y - 5)
self.textGroup.add(text)
self.score += 200
fireball.is_alive = False
if enemy_world_collison:
for enemy, terrain in enemy_world_collison.items():
for block in terrain:
if enemy.rect.bottom in range(block.rect.top - 6, block.rect.top + 13):
if enemy in self.koopas:
if enemy.is_alive:
enemy.rect.bottom = block.rect.top + 1
enemy.isStanding = True
if enemy in self.goombas:
if enemy.is_alive:
enemy.rect.bottom = block.rect.top + 1
enemy.isStanding = True
if enemy.rect.left in (block.rect.right + 3 - index for index in range(0, 41)) or \
enemy.rect.right in (block.rect.left - 3 + index for index in range(0, 41)):
if enemy.rect.bottom not in range(block.rect.top - 2, block.rect.top + 2):
enemy.hitWall = True
if self.player.rect.y > 672:
self.handleDeath(currentTime)
def draw_UI(self):
for text in self.steadyText:
text.kill()
self.steadyText.add(Text.steadyText(Settings.FONT, 20, 'SCORE', (255, 255, 255),
175, 5))
self.steadyText.add(Text.steadyText(Settings.FONT, 20, str(self.score), (255, 255, 255),
175, 25))
self.steadyText.add(Text.steadyText(Settings.FONT, 20, 'TIME', (255, 255, 255),
400, 5))
self.steadyText.add(Text.steadyText(Settings.FONT, 20, str(self.gameTimer_tock), (255, 255, 255),
400, 25))
self.steadyText.add(Text.steadyText(Settings.FONT, 20, 'WORLD', (255, 255, 255),
600, 5))
self.steadyText.add(Text.steadyText(Settings.FONT, 20, str(self.level), (255, 255, 255),
620, 25))
self.steadyText.add(Text.steadyText(Settings.FONT, 20, 'COINS', (255, 255, 255),
800, 5))
self.steadyText.add(Text.steadyText(Settings.FONT, 20, str(self.coinAmount), (255, 255, 255),
827, 25))
self.steadyText.add(Text.steadyText(Settings.FONT, 20, 'LIVES', (255, 255, 255),
1000, 5))
self.steadyText.add(Text.steadyText(Settings.FONT, 20, str(self.lives), (255, 255, 255),
1027, 25))
self.steadyText.update()
def mainLoop(self):
self.initGame()
while True:
currentTicks = time.get_ticks()
if self.player.rect.top > Settings.SCREEN_HEIGHT:
self.handleDeath(currentTicks)
if self.tock_index > 4:
if self.lowerTime:
self.gameTimer_tock -= 1
self.tock_index = 0
if self.gameTimer_tock < 100 and self.lowerTime:
if not self.warningPlayed:
self.SOUNDS['smb_warning'].play()
self.warningPlayed = True
else:
self.tock_index += 1
if self.gameTimer_tock <= 0 and self.lowerTime:
self.SOUNDS['smb_mariodie'].play()
self.handleDeath(currentTicks)
if not self.player.movementLock:
self.checkInput(currentTicks)
self.check_camera()
self.checkCollisions(currentTicks)
self.update(currentTicks)
self.draw_UI()
display.update()
self.clock.tick(30)
if __name__ == '__main__':
game = SuperMario()
game.mainLoop()