PEP8.
[naja.git] / naja / scenes / dummygame.py
1 """
2 Dummy scene that overlays a static rendering of a a game scene
3 """
4
5 import pygame.locals as pgl
6 import pygame
7
8 from naja.constants import SCREEN, KEYS
9 from naja.events import SceneChangeEvent, LoadGameEvent
10 from naja.scenes.scene import Scene
11 from naja.scenes.game import GameScene
12 from naja.gamestate import GameState
13 from naja.widgets.image_box import PreRenderedImageBox
14
15
16 class DummyGameScene(Scene):
17
18     def __init__(self, state=None):
19         super(DummyGameScene, self).__init__(state)
20         if not state:
21             game_state = GameState.new(max_health=4, wins_required=4)
22         else:
23             game_state = GameState.load(state['data'])
24         game = GameScene(game_state, play_sound=False)
25         game_surface = pygame.surface.Surface(SCREEN)
26         game.render(game_surface)
27         # Force tiles past the animation stage
28         game.board_widget.force_skip_animation()
29         game.render(game_surface)
30         self.add(PreRenderedImageBox((0, 0), game_surface))
31
32     def handle_scene_event(self, ev):
33         from naja.scenes.menu import MenuScene
34         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
35             # drop current state
36             LoadGameEvent.post(None)
37             SceneChangeEvent.post(MenuScene)
38             return