5 import pygame.locals as pgl
8 from naja.constants import KEYS, SCREEN, PALETTE
9 from naja.events import SceneChangeEvent, LoadGameEvent
10 from naja.gamestate import GameState
11 from naja.scenes.scene import Scene
12 from naja.scenes.howto import HowtoScene
13 from naja.widgets.image_box import ImageBox
14 from naja.widgets.selector import SelectorWidget
15 from naja.widgets.text import TextWidget
16 from naja.widgets.text import TextBoxWidget
17 from naja.resources import resources
18 from naja.scenes.dummygame import DummyGameScene
19 from naja.widgets.image_box import PreRenderedImageBox
22 class IntroductionScene(Scene):
23 def __init__(self, state):
24 super(IntroductionScene, self).__init__(state)
26 background = ImageBox(
27 (0, 0), "screens/splash.png")
32 selector = SelectorWidget()
35 y_offset, y_diff = 270, 40
40 (x_offset, y_offset), 'Getting started', colour='white',
46 (x_offset, y_offset), 'How to play', colour='white', centre=True)
47 howto.add_callback('click', self.howto_scene)
52 (x_offset, y_offset), 'Introductory Level', colour='white',
54 intro.add_callback('click', self.introduction_to_screen_1)
59 (x_offset, y_offset), 'Press ESC to return to the main menu.',
60 colour='white', centre=True)
63 def howto_scene(self, event):
64 SceneChangeEvent.post(HowtoScene)
66 def introduction_level(self, event):
67 from naja.scenes.game import GameScene
68 LoadGameEvent.post(state=GameState.new(deck='introduction'))
69 SceneChangeEvent.post(GameScene)
71 def make_game_surface(self):
72 self.container.widgets = []
73 state = resources.get_json('tutorial/tutorial_screen_1.json')
74 dummy_game = DummyGameScene(state)
75 game_surface = pygame.surface.Surface(SCREEN)
76 dummy_game.render(game_surface)
77 self.add(PreRenderedImageBox((0, 0), game_surface))
80 def introduction_to_screen_1(self, event):
81 game_surface = self.make_game_surface()
84 self.add(TextBoxWidget(
86 "These are your robot's status bits. On the left we have"
87 " the Most Signiticant Bit (MSB, currently set), then the"
88 " Red (unset), Green (set) and Blue (set) key bits, and"
89 " finally the four bits which control movement options, of"
90 " which only left is set. You can only move in directions"
94 colour=PALETTE.GREEN, padding=12, border=8,
95 bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
96 box_width=400, view_port=(500, 800)))
98 pygame.draw.rect(game_surface, PALETTE.GREEN, (0, 0, 480, 60), 8)
100 def introduction_to_screen_2(self, event):
101 game_surface = self.make_game_surface()
104 self.add(TextBoxWidget(
105 (24, 172), '\n'.join([
106 "These are your health and score. On the left we have four "
107 "health bits. The robot has taken one damage, so only three "
108 "are lit. The stars are points you have scored. Once you have "
109 "all of them you win the game! Total health and required "
110 "points vary according to the game. \n"
111 "Enter to continue.",
113 colour=PALETTE.GREEN, padding=12, border=8,
114 bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
115 box_width=400, view_port=(500, 800)))
117 pygame.draw.rect(game_surface, PALETTE.GREEN, (0, 540, 480, 60), 8)
119 def introduction_to_screen_3(self, event):
120 game_surface = self.make_game_surface()
123 self.add(TextBoxWidget(
124 (24, 132), '\n'.join([
125 "This text box describes the current game mode. The game is "
126 "divided into movements and actions, and each mode has "
127 "different options, shown here.",
128 "During movement, you can examine the entire board, but you "
129 "can only move to highlighted tiles (including the one you"
130 " are on). Actions come next ...",
131 "Enter to continue.",
133 colour=PALETTE.GREEN, padding=12, border=8,
134 bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
135 box_width=400, view_port=(500, 800)))
137 pygame.draw.rect(game_surface, PALETTE.GREEN, (488, 416, 304, 132), 8)
139 def introduction_to_screen_4(self, event):
140 game_surface = self.make_game_surface()
143 self.add(TextBoxWidget(
144 (24, 72), '\n'.join([
145 "This text box shows actions available on the tile. "
146 "Some actions have requirements and are only selectable if "
147 "you have the correct bits set (unavailable actions are "
148 "greyed out). Actions usually change the bits set on "
149 "your robot. This is often not beneficial.",
150 "Some actions have additional effects if the MSB is "
152 "Enter to continue.",
154 colour=PALETTE.GREEN, padding=12, border=8,
155 bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
156 box_width=400, view_port=(500, 800)))
158 pygame.draw.rect(game_surface, PALETTE.GREEN, (488, 52, 304, 240), 8)
160 def handle_scene_event(self, ev):
161 if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
162 from naja.scenes.menu import MenuScene
163 SceneChangeEvent.post(MenuScene)
165 if ev.type == pgl.KEYDOWN and ev.key in KEYS.SELECT:
166 if 0 < self.intro < 5:
168 self.introduction_to_screen_2(ev)
169 elif self.intro == 2:
170 self.introduction_to_screen_3(ev)
171 elif self.intro == 3:
172 self.introduction_to_screen_4(ev)
174 self.introduction_level(ev)