Ignore:
Timestamp:
09/01/13 13:18:11 (8 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Message:

Hook up area.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/engine.py

    r18 r20  
    55from nagslang import constants
    66from nagslang.screens.menu import MenuScreen
     7from nagslang.screens.area import AreaScreen
     8from nagslang.events import ScreenChange
    79
    810
     
    1214        self._clock = pygame.time.Clock()
    1315        self._fps = constants.FPS
    14         self._current_area = MenuScreen()
     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)
    1529
    1630    def run(self):
     
    2034                if ev.type == pygame.locals.QUIT:
    2135                    running = False
     36                elif ScreenChange.matches(ev):
     37                    self.change_screen(ev.screen)
    2238                else:
    23                     self._current_area.handle_event(ev)
    24             self._current_area.render(self._surface)
     39                    self._current_screen.handle_event(ev)
     40            self._current_screen.render(self._surface)
    2541            pygame.display.flip()
    2642            self._clock.tick(self._fps)
Note: See TracChangeset for help on using the changeset viewer.