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
|
import pygame
from display import Display
from status import Status
from player import Player
from field import Field
from enemies import Enemies
from stats import Stats
from screens import levelup_screen, gameover_screen, level_screen
from .gameplay import Gameplay
from .anykey import anykey
from .show import Show
class Level:
""" One level that can be played """
def __init__(self, display = None):
self.display = display
self.ended = False
self.status = Status()
self.field = Field()
self.enemies = Enemies()
self.player = Player()
self.player_single = pygame.sprite.Group()
self.level_info = Show(level_screen())
self.game_over = Show(gameover_screen(), active = False)
self.levelup = Show(levelup_screen(), active = False)
self.gameplay = Gameplay(
player = self.player,
status = self.status,
field = self.field,
enemies = self.enemies)
self.obj_classes = [
self.status,
self.field,
self.enemies,
self.game_over,
self.levelup,
self.level_info]
def step(self, dt):
self.status.update(dt = dt)
self.field.update(dt = dt)
self.enemies.update(dt = dt)
self.enemies.hit_walls(self.field.active_sprites())
if self.level_info.active:
self.level_info.update(dt = dt)
elif self.ended:
if self.game_over.active:
self.game_over.update(dt = dt)
elif self.levelup.active:
self.levelup.update(dt = dt)
else:
return False
else:
self.player_single = pygame.sprite.GroupSingle(
sprite = self.player.get_top_sprite())
Stats.update_bonus(dt)
if self.gameplay.step():
self.player_single = pygame.sprite.Group()
self.ended = True
if Stats.lives:
self.levelup.active = True
else:
self.game_over.active = True
self.display.update(self.obj_classes+[self.player_single])
return True
|