Mercurial > boomslang
comparison pyntnclick/engine.py @ 600:fabce47e542f pyntnclick
Stop using albow (at least for the menu). Breaks the world. Please fix it, kthx
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sat, 11 Feb 2012 19:56:30 +0200 |
parents | 5496dcd16a84 |
children | f2b1ddcc4986 |
comparison
equal
deleted
inserted
replaced
599:2d2ea51b73ad | 600:fabce47e542f |
---|---|
29 events = get_events() | 29 events = get_events() |
30 for ev in events: | 30 for ev in events: |
31 if ev.type == QUIT: | 31 if ev.type == QUIT: |
32 return | 32 return |
33 elif ScreenChangeEvent.matches(ev): | 33 elif ScreenChangeEvent.matches(ev): |
34 self.set_habitat(ev.habitat) | 34 self.set_screen(ev.screen) |
35 else: | 35 else: |
36 self._screen.dispatch(ev) | 36 self._screen.dispatch(ev) |
37 surface = pygame.display.get_surface() | 37 surface = pygame.display.get_surface() |
38 self._habitat.draw(surface) | 38 self._screen.draw(surface) |
39 flip() | 39 flip() |
40 self._fps = 1000.0 / clock.tick( | 40 self._fps = 1000.0 / clock.tick( |
41 self.game_description.constants.fps) | 41 self._game_description.constants.frame_rate) |
42 | |
43 | |
44 class Screen(object): | |
45 """A top level object for the screen being displayed""" | |
46 | |
47 def __init__(self, game_description): | |
48 # Avoid import loop | |
49 from pyntnclick.widgets.base import Container | |
50 | |
51 self.game_description = game_description | |
52 self.resource = game_description.resource | |
53 | |
54 self.surface_size = game_description.constants.screen | |
55 self.surface = None | |
56 self.container = Container(pygame.Rect((0, 0), self.surface_size)) | |
57 self.setup() | |
58 | |
59 def on_enter(self): | |
60 """Called when this becomes the current screen.""" | |
61 # Create the surface here as flipping between editor and | |
62 # other things kills pygame.display | |
63 self.surface = pygame.Surface(self.surface_size) | |
64 | |
65 def on_exit(self): | |
66 """Called when this stops being the current screen.""" | |
67 self.surface = None | |
68 | |
69 def setup(self): | |
70 """Override for initialization""" | |
71 pass | |
72 | |
73 def dispatch(self, ev): | |
74 self.container.event(ev) | |
75 | |
76 def draw_background(self): | |
77 self.surface.fill(pygame.Color('gray')) | |
78 | |
79 def draw(self, surface): | |
80 if self.surface: | |
81 self.draw_background() | |
82 self.container.draw(self.surface) | |
83 surface.blit(self.surface, self.surface.get_rect()) | |
84 | |
85 def display_dialog(self, dialog): | |
86 self.container.paused = True | |
87 self.container.add(dialog) | |
88 dialog.grab_focus() | |
42 | 89 |
43 | 90 |
44 class UserEvent(object): | 91 class UserEvent(object): |
45 """A user event type allowing subclassing, | 92 """A user event type allowing subclassing, |
46 to provide an infinate number of user-defined events | 93 to provide an infinate number of user-defined events |