comparison mamba/engine.py @ 64:fbb5cc655b47

More screen size fiddling hackery
author Neil Muller <drnlmuller@gmail.com>
date Sun, 11 Sep 2011 17:23:42 +0200
parents 40be38f4427c
children 2aa652b92449
comparison
equal deleted inserted replaced
63:07f18421f121 64:fbb5cc655b47
22 22
23 def run(self): 23 def run(self):
24 """Game loop.""" 24 """Game loop."""
25 get_events = pygame.event.get 25 get_events = pygame.event.get
26 flip = pygame.display.flip 26 flip = pygame.display.flip
27 surface = pygame.display.get_surface()
28 while True: 27 while True:
29 events = get_events() 28 events = get_events()
30 for ev in events: 29 for ev in events:
31 if ev.type is QUIT: 30 if ev.type is QUIT:
32 return 31 return
33 elif NewHabitatEvent.matches(ev): 32 elif NewHabitatEvent.matches(ev):
34 self.set_habitat(ev.habitat) 33 self.set_habitat(ev.habitat)
35 else: 34 else:
36 self._habitat.dispatch(ev) 35 self._habitat.dispatch(ev)
36 surface = pygame.display.get_surface()
37 self._habitat.draw(surface) 37 self._habitat.draw(surface)
38 flip() 38 flip()
39 39
40 40
41 class Habitat(object): 41 class Habitat(object):
42 42
43 def __init__(self): 43 def __init__(self):
44 self.surface = pygame.Surface(SCREEN) 44 self.surface = None
45 self.container = Container(pygame.Rect((0, 0), SCREEN)) 45 self.container = Container(pygame.Rect((0, 0), SCREEN))
46 46
47 def on_enter(self): 47 def on_enter(self):
48 """Called when this becomes the current habitat.""" 48 """Called when this becomes the current habitat."""
49 pass 49 # Create the surface here as flipping between editor and
50 # other things kills pygame.display
51 self.surface = pygame.Surface(SCREEN)
50 52
51 def on_exit(self): 53 def on_exit(self):
52 """Called when this stops being the current habitat.""" 54 """Called when this stops being the current habitat."""
53 pass 55 self.surface = None
54 56
55 def dispatch(self, ev): 57 def dispatch(self, ev):
56 self.container.event(ev) 58 self.container.event(ev)
57 59
58 def draw(self, surface): 60 def draw(self, surface):
59 self.surface.fill(pygame.Color('black')) 61 if self.surface:
60 self.container.draw(self.surface) 62 self.surface.fill(pygame.Color('black'))
61 surface.blit(self.surface, self.surface.get_rect()) 63 self.container.draw(self.surface)
64 surface.blit(self.surface, self.surface.get_rect())
62 65
63 66
64 class UserEvent(object): 67 class UserEvent(object):
65 68
66 TYPE = "UNKNOWN" 69 TYPE = "UNKNOWN"