Add a dummygame scene
[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 KEYS, PALETTE, SCREEN
9 from naja.events import SceneChangeEvent, LoadGameEvent
10 from naja.sound import sound
11 from naja.scenes.scene import Scene
12 from naja.scenes.game import GameScene
13 from naja.gamestate import GameState
14 from naja.widgets.image_box import PreRenderedImageBox
15 from naja.widgets.text import TextWidget, TextBoxWidget
16
17
18 class DummyGameScene(Scene):
19
20     def __init__(self, state=None):
21         super(DummyGameScene, self).__init__(state)
22         if not state:
23             game_state = GameState.new(max_health=4, wins_required=4)
24         else:
25             game_state = state
26         game = GameScene(game_state, play_sound=False)
27         game_surface = pygame.surface.Surface(SCREEN)
28         game.render(game_surface)
29         # Force tiles past the animation stage
30         game.board_widget.force_skip_animation()
31         game.render(game_surface)
32         self.add(PreRenderedImageBox((0, 0), game_surface))
33
34     def handle_scene_event(self, ev):
35         from naja.scenes.menu import MenuScene
36         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
37             # drop current state
38             LoadGameEvent.post(None)
39             SceneChangeEvent.post(MenuScene)
40             return