def __init__(self, width, height, fullscreen=False, opengl_mode=False): self._window = Window(width, height, fullscreen, opengl_mode) self._event_manager = EventManager() self._updateWorld = lambda : 0 self._clock = Clock() self.continue_pyguane = True self._keyboard_observable = Observable() @self._event_manager.keyboard def keyboardEmitter(keysdown, keysup): self._keyboard_observable.emit(keysdown, keysup) self._mouse_observable = Observable() @self._event_manager.mouse def mouseEmitter(buttons, pos, relpos): self._mouse_observable.emit(buttons, pos, relpos)
class Egg(object): def __init__(self, width, height, fullscreen=False, opengl_mode=False): self._window = Window(width, height, fullscreen, opengl_mode) self._event_manager = EventManager() self._updateWorld = lambda : 0 self._clock = Clock() self.continue_pyguane = True self._keyboard_observable = Observable() @self._event_manager.keyboard def keyboardEmitter(keysdown, keysup): self._keyboard_observable.emit(keysdown, keysup) self._mouse_observable = Observable() @self._event_manager.mouse def mouseEmitter(buttons, pos, relpos): self._mouse_observable.emit(buttons, pos, relpos) def updateWorld(self, obj): self._updateWorld = obj return self._updateWorld def observeKeyboard(self, *obj): self._keyboard_observable.subscribe(*obj) def unobserveKeyboard(self, *obj): self._keyboard_observable.unsubscribe(*obj) def observeMouse(self, *obj): self._mouse_observable.subscribe(*obj) def unobserveMouse(self, *obj): self._mouse_observable.unsubscribe(*obj) @property def window(self): return self._window @property def event_manager(self): return self._event_manager @property def clock(self): return self._clock @Singleton class Renderer(object): def __init__(self, surface): self.surface = surface #my default renderer drawing callback does nothing self._displayCallback = lambda : [] def __call__(self, func): self._displayCallback = lambda : func(self.surface) def draw(self): #do all the blits then update the screen surface displayUpdate(self._displayCallback()) @property def renderer(self): return self.Renderer() def run(self): self.Renderer(None) #make a default renderer if there is not event_update = self._event_manager.update draw = self.renderer.draw updateWorld = self._updateWorld while self.continue_pyguane: wait(2) #don't waste the cpu event_update() updateWorld() draw()