box_width=740, view_port=(780, 540)))
def handle_scene_event(self, ev):
- from naja.scenes.menu import MenuScene
+ from naja.scenes.introduction import IntroductionScene
if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
- SceneChangeEvent.post(MenuScene)
+ SceneChangeEvent.post(IntroductionScene)
return
--- /dev/null
+"""
+Load and save scenes.
+"""
+
+import pygame.locals as pgl
+
+from naja.constants import KEYS
+from naja.events import SceneChangeEvent, LoadGameEvent
+from naja.gamestate import GameState
+from naja.scenes.scene import Scene
+from naja.scenes.howto import HowtoScene
+from naja.widgets.image_box import ImageBox
+from naja.widgets.selector import SelectorWidget
+from naja.widgets.text import TextWidget
+
+
+class IntroductionScene(Scene):
+ def __init__(self, state):
+ super(IntroductionScene, self).__init__(state)
+
+ background = ImageBox(
+ (0, 0), "screens/splash.png")
+ self.add(background)
+
+ selector = SelectorWidget()
+ self.add(selector)
+
+ y_offset, y_diff = 270, 40
+ x_offset = 400
+
+ y_offset += y_diff
+ title = TextWidget(
+ (x_offset, y_offset), 'Getting started', colour='white',
+ centre=True)
+ self.add(title)
+
+ y_offset += y_diff
+ howto = TextWidget(
+ (x_offset, y_offset), 'How to play', colour='white', centre=True)
+ howto.add_callback('click', self.howto_scene)
+ selector.add(howto)
+
+ y_offset += y_diff
+ intro = TextWidget(
+ (x_offset, y_offset), 'Introductory Level', colour='white',
+ centre=True)
+ intro.add_callback('click', self.introduction_level)
+ selector.add(intro)
+
+ y_offset += 2*y_diff
+ back = TextWidget(
+ (x_offset, y_offset), 'Press ESC to return to the main menu.',
+ colour='white', centre=True)
+ self.add(back)
+
+ def howto_scene(self, event):
+ SceneChangeEvent.post(HowtoScene)
+
+ def introduction_level(self, event):
+ from naja.scenes.game import GameScene
+ LoadGameEvent.post(state=GameState.new(deck='introduction'))
+ SceneChangeEvent.post(GameScene)
+
+ def handle_scene_event(self, ev):
+ if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
+ from naja.scenes.menu import MenuScene
+ SceneChangeEvent.post(MenuScene)
+ return
from naja.scenes.scene import Scene
from naja.scenes.credits import CreditsScene
from naja.scenes.game import GameScene
-from naja.scenes.howto import HowtoScene
+from naja.scenes.introduction import IntroductionScene
from naja.scenes.load_save import LoadGameScene, SaveGameScene
from naja.scenes.new_game import NewGameScene
from naja.scenes.puzzlelist import PuzzleListScene
y_offset, y_diff = 270, 36
x_offset = 400
+ y_offset += y_diff
+ intro = TextWidget(
+ (x_offset, y_offset), 'Introduction', colour=PALETTE.WHITE,
+ centre=True)
+ intro.add_callback('click', self.scene_callback(IntroductionScene))
+ selector.add(intro)
+
y_offset += y_diff
resume = TextWidget(
(x_offset, y_offset), 'Resume Game', colour=PALETTE.WHITE,
resume.set_selectable_callback(lambda: state is not None)
selector.add(resume)
+ if state is None:
+ selector.position = 2
+ else:
+ selector.position = 1
+
y_offset += y_diff
new = TextWidget(
(x_offset, y_offset), 'New Random Game', colour=PALETTE.WHITE,
save.set_selectable_callback(lambda: state is not None)
selector.add(save)
- y_offset += y_diff
- howto = TextWidget(
- (x_offset, y_offset), 'How To Play', colour=PALETTE.WHITE,
- centre=True)
- howto.add_callback('click', self.scene_callback(HowtoScene))
- selector.add(howto)
-
y_offset += y_diff
credits = TextWidget(
(x_offset, y_offset), 'Credits', colour=PALETTE.WHITE,