5 import pygame.locals as pgl
8 from naja import constants
9 from naja.constants import KEYS, SCREEN, PALETTE
10 from naja.events import SceneChangeEvent, LoadGameEvent
11 from naja.gamestate import GameState
12 from naja.scenes.scene import Scene
13 from naja.scenes.howto import HowtoScene
14 from naja.widgets.image_box import ImageBox
15 from naja.widgets.selector import SelectorWidget
16 from naja.widgets.text import TextWidget
17 from naja.widgets.text import TextBoxWidget
18 from naja.resources import resources
19 from naja.scenes.dummygame import DummyGameScene
20 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 Red, "
88 "Green (set) and Blue (set) key bits, and finally the four "
89 "bits which control movement options, of which only left is "
90 "set. You can only move in directions which are set. \n"
93 colour=PALETTE.GREEN, padding=12, border=8,
94 bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
95 box_width=400, view_port=(500, 800)))
97 pygame.draw.rect(game_surface, PALETTE.GREEN, (0, 0, 480, 60), 8)
99 def introduction_to_screen_2(self, event):
100 game_surface = self.make_game_surface()
103 self.add(TextBoxWidget(
104 (24, 172), '\n'.join([
105 "These are your health and score. On the left we have four "
106 "health bits. The robot has taken one damage, so only three "
107 "are lit. The stars are points you have scored. Once you have "
108 "all of them you win the game! Total health and required "
109 "points vary according to the game. \n"
110 "Enter to continue.",
112 colour=PALETTE.GREEN, padding=12, border=8,
113 bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
114 box_width=400, view_port=(500, 800)))
116 pygame.draw.rect(game_surface, PALETTE.GREEN, (0, 540, 480, 60), 8)
118 def introduction_to_screen_3(self, event):
119 game_surface = self.make_game_surface()
122 self.add(TextBoxWidget(
123 (24, 132), '\n'.join([
124 "This text box describes the current game mode. The game is "
125 "divided into movements and actions, and each mode has "
126 "different options, shown here.\n"
127 "During movement, you can examine the entire board, but you "
128 "can only move to hi-lighted tiles (including the one you are "
129 "on. Actions come next... \n"
130 "Enter to continue.",
132 colour=PALETTE.GREEN, padding=12, border=8,
133 bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
134 box_width=400, view_port=(500, 800)))
136 pygame.draw.rect(game_surface, PALETTE.GREEN, (488, 416, 304, 132), 8)
138 def introduction_to_screen_4(self, event):
139 game_surface = self.make_game_surface()
142 self.add(TextBoxWidget(
143 (24, 72), '\n'.join([
144 "This text box shows actions available on the tile. "
145 "Some actions have requirements and are only selectable if "
146 "you have the correct bits set (unavailable actions are "
147 "greyed out). Actions usually change the bits set on "
148 "your robot. This is often not beneficial.\n"
149 "Some actions have additional effects if the MSB is "
151 "Enter to continue.",
153 colour=PALETTE.GREEN, padding=12, border=8,
154 bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
155 box_width=400, view_port=(500, 800)))
157 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)