source: skaapsteker/menuscene.py

Last change on this file was 495:a5a57abd5472, checked in by Jeremy Thurgood <firxen@…>, 12 years ago

Allow K_SPACE wherever we allow K_RETURN.

File size: 2.3 KB
Line 
1import pygame
2from pygame.locals import K_ESCAPE, K_q, K_UP, K_DOWN, K_RETURN, K_SPACE, KEYDOWN, QUIT
3
4from .data import load_image
5from .cutscene import OpeningCutScene, UsageCutScene, CreditsCutScene
6from .engine import ChangeScene, Scene
7from .levelscene import LevelScene
8from .widgets.text import Text, TextChoice
9
10
11class MenuScene(Scene):
12 def __init__(self, game_state, soundsystem):
13 super(MenuScene, self).__init__(game_state, soundsystem)
14 self._background = load_image('backgrounds/main-menu.png')
15 self._cursor = load_image('sprites/main-menu-cursor.png')
16 self._selected = 0
17 self._options = ['restart', 'usage', 'credits', 'quit']
18 self._can_resume = self.game_state.world is not None
19 if self._can_resume:
20 resume = load_image('sprites/main-menu-resume.png')
21 self._background.blit(resume, (73, 180))
22 self._options.insert(0, 'resume')
23
24 def selected(self, option, data):
25 if data == 'resume':
26 fox = self.game_state.world.fox
27 ChangeScene.post((LevelScene, '.'.join([fox.level, fox.doorway])))
28 elif data == 'restart':
29 self.game_state.new_game()
30 ChangeScene.post(OpeningCutScene(self.game_state, self._soundsystem))
31 elif data == 'usage':
32 ChangeScene.post(UsageCutScene(self.game_state, self._soundsystem))
33 elif data == 'credits':
34 ChangeScene.post(CreditsCutScene(self.game_state, self._soundsystem))
35 elif data == 'quit':
36 pygame.event.post(pygame.event.Event(QUIT))
37
38 def draw(self, surface, engine):
39 cursor_x = 35
40 cursor_y = 232
41 if self._can_resume:
42 cursor_y -= 43
43 cursor_y += 43 * self._selected
44 surface.blit(self._background, (0, 0))
45 surface.blit(self._cursor, (cursor_x, cursor_y))
46
47 def dispatch(self, ev):
48 if ev.type is KEYDOWN:
49 if ev.key in (K_q, K_ESCAPE):
50 pygame.event.post(pygame.event.Event(QUIT))
51 elif ev.key == K_DOWN:
52 self._selected += 1
53 elif ev.key == K_UP:
54 self._selected -= 1
55 elif ev.key in [K_RETURN, K_SPACE]:
56 self.selected(self._selected, self._options[self._selected])
57
58 self._selected %= 4 + int(self._can_resume)
Note: See TracBrowser for help on using the repository browser.