Changeset 18:9ecb1d222ee0


Ignore:
Timestamp:
Sep 1, 2013, 12:48:21 PM (7 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
rebase_source:
c0ef6f6af4f54f610018513225fb6d0ed8f92efb
Message:

Screens.

Location:
nagslang
Files:
4 added
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • nagslang/engine.py

    r15 r18  
    11"""Top-level event dispatching and area transition."""
    22
    3 from pygame import event
    4 from pygame import time
    5 import pygame.locals as pyl
     3import pygame
    64
    75from nagslang import constants
     6from nagslang.screens.menu import MenuScreen
    87
    98
    109class Engine(object):
    11     def __init__(self, screen):
    12         self._screen = screen
    13         self._clock = time.Clock()
     10    def __init__(self, surface):
     11        self._surface = surface
     12        self._clock = pygame.time.Clock()
    1413        self._fps = constants.FPS
     14        self._current_area = MenuScreen()
    1515
    1616    def run(self):
    1717        running = True
    1818        while running:
    19             for ev in event.get():
    20                 # TODO: dispatch these to an area
    21                 if ev.type == pyl.QUIT:
     19            for ev in pygame.event.get():
     20                if ev.type == pygame.locals.QUIT:
    2221                    running = False
    23                 elif ev.type == pyl.KEYDOWN and ev.key == pyl.K_ESCAPE:
    24                     running = False
     22                else:
     23                    self._current_area.handle_event(ev)
     24            self._current_area.render(self._surface)
     25            pygame.display.flip()
    2526            self._clock.tick(self._fps)
  • nagslang/screens/base.py

    r11 r18  
    11"""A screen or area in which action happens."""
    22
     3from pygame import event
    34import pymunk
    45
    56
    6 class Area(object):
     7class Screen(object):
    78
    89    def __init__(self):
    910        self.space = pymunk.Space()
     11
     12    def post_event(self, ev):
     13        event.post(ev)
     14
     15    def handle_event(self, ev):
     16        pass
    1017
    1118    def render(self, surface):
Note: See TracChangeset for help on using the changeset viewer.