summaryrefslogtreecommitdiff
path: root/src/sliceitoff/game/level.py
blob: 08e44953ed963963ab07f256032ad44d6f27cfaf (plain)
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
""" game.level - This is what runs invidual levels """
import pygame

from sliceitoff.status import Status
from sliceitoff.player import Player, Life
from sliceitoff.field import Field
from sliceitoff.enemies import Enemies
from sliceitoff.screens import levelup_screen, gameover_screen, level_screen
from sliceitoff.sfx import sfx
from .gameplay import Gameplay
from .show import Show

class Level(pygame.sprite.Group):
    """ One level that can be played """
    # pylint: disable = too-many-instance-attributes
    def __init__(self, stats = None):
        super().__init__()
        self.stats = stats
        self.status = Status(stats = self.stats)
        self.field = Field(stats = self.stats, level = stats.level)
        self.enemies = Enemies(count = self.stats.enemies)
        self.player = Player()
        self.life = Life()
        self.level_info = Show(level_screen(stats.level))
        self.ended = False
        self.active = True
        self.endscreen = None

        self.gameplay = Gameplay(
                player = self.player,
                field = self.field,
                enemies = self.enemies,
                stats = self.stats,
                life = self.life)

        sfx.music("uhkapeli")

    def update(self, dt = 0):
        """ Updates groups, calls gameplay and adds sprites for drawing """
        self.empty()
        self.status.update(dt = dt)
        self.field.update(dt = dt)
        self.enemies.update(dt = dt, field_rects = self.field.active_rects())
        self.life.update(dt = dt)
        self.add(self.status, self.field, self.enemies)

        if self.level_info.active:
            self.level_info.update(dt = dt)
            self.add(self.level_info)

        elif self.ended:
            if self.endscreen.active:
                self.endscreen.update(dt = dt)
                self.add(self.endscreen)
            else:
                self.active = False
        else:
            self.add(self.player)
            self.stats.update_bonus(dt)
            if self.gameplay.step():
                self.ended = True
                if self.stats.lives:
                    self.endscreen = Show(levelup_screen(self.stats))
                else:
                    self.endscreen = Show(gameover_screen())
        self.add(self.life)