source: nagslang/engine.py@ 25:e93eac7cf8c2

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

Consider a spherical werewolf.

File size: 1.4 KB
RevLine 
[15]1"""Top-level event dispatching and area transition."""
2
[18]3import pygame
[15]4
5from nagslang import constants
[18]6from nagslang.screens.menu import MenuScreen
[20]7from nagslang.screens.area import AreaScreen
8from nagslang.events import ScreenChange
[15]9
10
11class Engine(object):
[18]12 def __init__(self, surface):
13 self._surface = surface
14 self._clock = pygame.time.Clock()
[15]15 self._fps = constants.FPS
[20]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)
[15]29
30 def run(self):
31 running = True
32 while running:
[18]33 for ev in pygame.event.get():
34 if ev.type == pygame.locals.QUIT:
[15]35 running = False
[20]36 elif ScreenChange.matches(ev):
37 self.change_screen(ev.screen)
[18]38 else:
[20]39 self._current_screen.handle_event(ev)
40 self._current_screen.render(self._surface)
[18]41 pygame.display.flip()
[25]42 ms = self._clock.tick(self._fps)
43 self._current_screen.tick(ms / 1000.)
Note: See TracBrowser for help on using the repository browser.