X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/blobdiff_plain/346a9b8e1fcfe30629f0d1ee4675e9e8f89890cf..4c4732c6ed8cb0aaa70fb2d4c6e5a958868c5349:/src/pgu/engine.py?ds=sidebyside diff --git a/src/pgu/engine.py b/src/pgu/engine.py deleted file mode 100644 index 76be583..0000000 --- a/src/pgu/engine.py +++ /dev/null @@ -1,154 +0,0 @@ -"""a state engine. -""" -import pygame -from pygame.locals import * - -class State: - """Template Class -- for a state. - -
State(game,value...)- -
For all of the template methods, they should return None unless they return - a new State to switch the engine to.
- """ - def __init__(self,game,value=None): - self.game,self.value = game,value - def init(self): - """Template Method - Initialize the state, called once the first time a state is selected. - -State.init()- """ - return - def paint(self,screen): - """Template Method - Paint the screen. Called once after the state is selected. - -
State is responsible for calling pygame.display.flip() or whatever.
- -State.paint(screen)- """ - return - - def repaint(self): - """Template Method - Request a repaint of this state. - -
State.repaint()- """ - self._paint = 1 - def update(self,screen): - """Template Method - Update the screen. - -
State is responsible for calling pygame.display.update(updates) or whatever.
- -State.update(screen)- """ - return - def loop(self): - """Template Method - Run a logic loop, called once per frame. - -
State.loop()- """ - return - def event(self,e): - """Template Method - Recieve an event. - -
State.event(e)- """ - return - -class Quit(State): - """A state to quit the state engine. - -
Quit(game,value)- """ - - def init(self): - self.game.quit = 1 - -class Game: - """Template Class - The state engine. - """ - def fnc(self,f,v=None): - s = self.state - if not hasattr(s,f): return 0 - f = getattr(s,f) - if v != None: r = f(v) - else: r = f() - if r != None: - self.state = r - self.state._paint = 1 - return 1 - return 0 - - def run(self,state,screen=None): - """Run the state engine, this is a infinite loop (until a quit occurs). - -
Game.run(state,screen=None)- -
Game.init()- """ - return - - def tick(self): - """Template Method - called once per frame, usually for timer purposes. - -
Game.tick()- """ - pygame.time.wait(10) - - def event(self,e): - """Template Method - called with each event, so the engine can capture special events. - -
Game.event(e): return captured- -
return a True value if the event is captured and does not need to be passed onto the current - state
- """ - if e.type is QUIT: - self.state = Quit(self) - return 1 - -# vim: set filetype=python sts=4 sw=4 noet si :