source: nagslang/engine.py@ 20:347667c941de

Last change on this file since 20:347667c941de was 20:347667c941de, checked in by Simon Cross <hodgestar@…>, 8 years ago

Hook up area.

File size: 1.3 KB
Line 
1"""Top-level event dispatching and area transition."""
2
3import pygame
4
5from nagslang import constants
6from nagslang.screens.menu import MenuScreen
7from nagslang.screens.area import AreaScreen
8from nagslang.events import ScreenChange
9
10
11class Engine(object):
12 def __init__(self, surface):
13 self._surface = surface
14 self._clock = pygame.time.Clock()
15 self._fps = constants.FPS
16 self._world = None # TODO: create the world
17 self._current_screen = None
18 self._screens = {
19 'menu': MenuScreen,
20 'level1': AreaScreen,
21 }
22 self.change_screen('menu')
23
24 def change_screen(self, new_screen):
25 if self._current_screen is not None:
26 self._current_screen.teardown()
27 self._current_screen = self._screens[new_screen]()
28 self._current_screen.setup(self._world)
29
30 def run(self):
31 running = True
32 while running:
33 for ev in pygame.event.get():
34 if ev.type == pygame.locals.QUIT:
35 running = False
36 elif ScreenChange.matches(ev):
37 self.change_screen(ev.screen)
38 else:
39 self._current_screen.handle_event(ev)
40 self._current_screen.render(self._surface)
41 pygame.display.flip()
42 self._clock.tick(self._fps)
Note: See TracBrowser for help on using the repository browser.