40811877808423b6958d0512871110963c290e25
[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
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 class IntroductionScene(Scene):
22     def __init__(self, state):
23         super(IntroductionScene, self).__init__(state)
24
25         background = ImageBox(
26             (0, 0), "screens/splash.png")
27         self.add(background)
28
29         selector = SelectorWidget()
30         self.add(selector)
31
32         y_offset, y_diff = 270, 40
33         x_offset = 400
34
35         y_offset += y_diff
36         title = TextWidget(
37             (x_offset, y_offset), 'Getting started', colour='white',
38             centre=True)
39         self.add(title)
40
41         y_offset += y_diff
42         howto = TextWidget(
43             (x_offset, y_offset), 'How to play', colour='white', centre=True)
44         howto.add_callback('click', self.howto_scene)
45         selector.add(howto)
46
47         y_offset += y_diff
48         intro = TextWidget(
49             (x_offset, y_offset), 'Introductory Level', colour='white',
50             centre=True)
51         intro.add_callback('click', self.introduction_to_screen_1)
52         selector.add(intro)
53
54         y_offset += 2*y_diff
55         back = TextWidget(
56             (x_offset, y_offset), 'Press ESC to return to the main menu.',
57             colour='white', centre=True)
58         self.add(back)
59
60     def howto_scene(self, event):
61         SceneChangeEvent.post(HowtoScene)
62
63     def introduction_level(self, event):
64         from naja.scenes.game import GameScene
65         LoadGameEvent.post(state=GameState.new(deck='introduction'))
66         SceneChangeEvent.post(GameScene)
67
68     def introduction_to_screen_1(self, event):
69         self.container.widgets = []
70         state = resources.get_json('tutorial/tutorial_screen_1.json')
71         dummy_game = DummyGameScene(state)
72         game_surface = pygame.surface.Surface(SCREEN)
73         dummy_game.render(game_surface)
74         self.add(PreRenderedImageBox((0, 0), game_surface))
75
76         # self.add(TextBoxWidget(
77         #     (10, 50), '\n'.join([
78         #         "You are a robot, frantically trying to set the correct "
79         #         "bits to gain points for reasons that are unlikely ever "
80         #         "to become clear.",
81         #         "",
82         #         "You have 8 bits. Four bits control the directions "
83         #         "you can move in {NORTH,SOUTH,EAST,WEST}, 3 allow you "
84         #         "to unlock actions {RED,GREEN,BLUE} and the "
85         #         "last, the Most Significant Bit {MSB}, makes everything "
86         #         "work better.",
87         #         "",
88         #         "MOVEMENT",
89         #         "",
90         #         "During Movement, you can explore the board and learn about "
91         #         "the available tiles. Tiles you can legally move onto are "
92         #         "highlighted. It's always possible to stay in place.",
93         #         "",
94         #         "ACTIONS",
95         #         "",
96         #         "After moving, you must select an action. Some actions "
97         #         "require the correct bits to be set before they can be "
98         #         "selected. After the action, the tile will be replaced "
99         #         "(except in puzzle mode).",
100         #         "",
101         #         "Some actions cost health {HEALTH}. If you run out of "
102         #         "health {HEALTH}, you lose.",
103         #         "",
104         #         "Some actions gain you points {WINTOKEN}. Once you have "
105         #         "enough points, you win the game.",
106         #         "",
107         #         "Some tiles have a countdown timer {COUNTDOWN}. This "
108         #         "indicates the number of turns left before something "
109         #         "happens. The timer moves faster as the deadline approaches.",
110         #         "",
111         #         "Press ESC to return to the menu.",
112         #     ]), fontsize=32,
113         #     colour='white', padding=1, border=1,
114         #     bg_colour='black', border_colour='black',
115         #     box_width=740, view_port=(780, 540)))
116
117
118
119     def handle_scene_event(self, ev):
120         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
121             from naja.scenes.menu import MenuScene
122             SceneChangeEvent.post(MenuScene)
123             return