3 import pygame.locals as pgl
5 from .base import BaseScene
6 from ..events import QuitEvent, SceneChangeEvent
7 from ..loader import loader
8 from ..constants import FONTS
9 from ..widgets import TextButton
12 class MenuScene(BaseScene):
13 def enter(self, gamestate):
14 if gamestate.station is None:
15 print "Loading Station Alpha ..."
16 gamestate.set_station(loader.load_station("station-alpha.json"))
17 font_title = loader.load_font(FONTS['bold'], size=32)
18 self._title = font_title.render('A Game with a title', True,
21 TextButton("Load Level", (255, 255, 255), name='load level'),
22 TextButton("Start Game (Day)", (255, 255, 255), name='start game'),
23 TextButton("Load Saved Game", (255, 255, 255), name='load game'),
24 TextButton("Help", (255, 255, 255), name='help'),
27 def render(self, surface, gamestate):
28 surface.fill((0, 128, 0))
30 pos = ((surface.get_width() - self._title.get_width()) / 2, 50)
31 surface.blit(self._title, pos, None)
34 for item in self._menu:
36 item.position = ((surface.get_width() - item.get_width()) / 2,
39 height += item.get_height() + 30
41 def _get_pressed(self, ev):
42 for button in self._menu:
43 if button.pressed(ev):
48 from .day import DayScene
49 SceneChangeEvent.post(scene=DayScene())
51 def _do_load_level(self):
52 from .load_level import LoadLevelScene
53 SceneChangeEvent.post(scene=LoadLevelScene())
56 from .help import HelpScene
57 SceneChangeEvent.post(scene=HelpScene())
59 def event(self, ev, gamestate):
60 if ev.type == pgl.KEYDOWN:
61 if ev.key in (pgl.K_q, pgl.K_ESCAPE):
63 elif ev.key == pgl.K_n:
64 from .night import NightScene
65 SceneChangeEvent.post(scene=NightScene())
66 elif ev.key == pgl.K_d:
68 elif ev.key == pgl.K_l:
70 elif ev.key == pgl.K_h:
72 elif ev.type == pgl.MOUSEBUTTONDOWN:
73 pressed = self._get_pressed(ev)
74 if pressed == 'load level':
76 elif pressed == 'start game':
78 elif pressed == 'help':
81 print 'Pressed', pressed