Clean-up text on intro.
[naja.git] / naja / scenes / introduction.py
1 """
2 Load and save scenes.
3 """
4
5 import pygame.locals as pgl
6 import pygame
7
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
20
21
22 class IntroductionScene(Scene):
23     def __init__(self, state):
24         super(IntroductionScene, self).__init__(state)
25
26         background = ImageBox(
27             (0, 0), "screens/splash.png")
28         self.add(background)
29
30         self.intro = 0
31
32         selector = SelectorWidget()
33         self.add(selector)
34
35         y_offset, y_diff = 270, 40
36         x_offset = 400
37
38         y_offset += y_diff
39         title = TextWidget(
40             (x_offset, y_offset), 'Getting started', colour='white',
41             centre=True)
42         self.add(title)
43
44         y_offset += y_diff
45         howto = TextWidget(
46             (x_offset, y_offset), 'How to play', colour='white', centre=True)
47         howto.add_callback('click', self.howto_scene)
48         selector.add(howto)
49
50         y_offset += y_diff
51         intro = TextWidget(
52             (x_offset, y_offset), 'Introductory Level', colour='white',
53             centre=True)
54         intro.add_callback('click', self.introduction_to_screen_1)
55         selector.add(intro)
56
57         y_offset += 2*y_diff
58         back = TextWidget(
59             (x_offset, y_offset), 'Press ESC to return to the main menu.',
60             colour='white', centre=True)
61         self.add(back)
62
63     def howto_scene(self, event):
64         SceneChangeEvent.post(HowtoScene)
65
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)
70
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))
78         return game_surface
79
80     def introduction_to_screen_1(self, event):
81         game_surface = self.make_game_surface()
82         self.intro = 1
83
84         self.add(TextBoxWidget(
85             (24, 72), '\n'.join([
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"
91                 " which are set.",
92                 "Enter to continue.",
93             ]), fontsize=32,
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)))
97
98         pygame.draw.rect(game_surface, PALETTE.GREEN, (0, 0, 480, 60), 8)
99
100     def introduction_to_screen_2(self, event):
101         game_surface = self.make_game_surface()
102         self.intro = 2
103
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.",
112             ]), fontsize=32,
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)))
116
117         pygame.draw.rect(game_surface, PALETTE.GREEN, (0, 540, 480, 60), 8)
118
119     def introduction_to_screen_3(self, event):
120         game_surface = self.make_game_surface()
121         self.intro = 3
122
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.",
132             ]), fontsize=32,
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)))
136
137         pygame.draw.rect(game_surface, PALETTE.GREEN, (488, 416, 304, 132), 8)
138
139     def introduction_to_screen_4(self, event):
140         game_surface = self.make_game_surface()
141         self.intro = 4
142
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 "
151                 "set.",
152                 "Enter to continue.",
153             ]), fontsize=32,
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)))
157
158         pygame.draw.rect(game_surface, PALETTE.GREEN, (488, 52, 304, 240), 8)
159
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)
164             return
165         if ev.type == pgl.KEYDOWN and ev.key in KEYS.SELECT:
166             if 0 < self.intro < 5:
167                 if self.intro == 1:
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)
173                 else:
174                     self.introduction_level(ev)
175             return