5 import pygame.locals as pgl
7 from naja.constants import KEYS
8 from naja.events import SceneChangeEvent, LoadGameEvent
9 from naja.gamestate import GameState
10 from naja.scenes.scene import Scene
11 from naja.widgets.image_box import ImageBox
12 from naja.widgets.selector import SelectorWidget
13 from naja.widgets.text import TextWidget
16 class NewGameScene(Scene):
17 def __init__(self, state):
18 super(NewGameScene, self).__init__(state)
20 background = ImageBox(
21 (0, 0), "screens/splash.png")
24 selector = SelectorWidget()
28 y_offset, y_diff = 270, 40
33 (x_offset, y_offset), 'NEW GAME', colour='white',
38 question = TextWidget(
39 (x_offset, y_offset), 'Select difficulty:', colour='white',
45 (x_offset, y_offset), 'Easy', fontsize=32, colour='white',
47 easy.add_callback('click', self.easy_game)
51 standard = TextWidget(
52 (x_offset, y_offset), 'Standard', fontsize=32, colour='white',
54 standard.add_callback('click', self.standard_game)
55 selector.add(standard)
59 (x_offset, y_offset), 'Hard', fontsize=32, colour='white',
61 hard.add_callback('click', self.hard_game)
64 def easy_game(self, event):
65 self.start_game(GameState.new(max_health=5, wins_required=3))
67 def standard_game(self, event):
68 self.start_game(GameState.new(max_health=4, wins_required=4))
70 def hard_game(self, event):
71 self.start_game(GameState.new(max_health=3, wins_required=5))
73 def start_game(self, state):
74 from naja.scenes.game import GameScene
75 LoadGameEvent.post(state=state)
76 SceneChangeEvent.post(GameScene)
78 def handle_scene_event(self, ev):
79 if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
80 from naja.scenes.menu import MenuScene
81 SceneChangeEvent.post(MenuScene)