Package motherhamster :: Module hamsterwheel :: Class HamsterWheel

Class HamsterWheel



The base class for a game in the MotherHamster framework

A game class can set it's screen_width, screen_height, updates_per_second, max_frame_skip to customize itself.

To run your game, you should call run_game on an instance of your class. Other modules may use HamsterWheel.the_game to access the instance of the game class currently running

modules may access the screen, fullscreen, run_time & is_playing attributes of the instance of the game

Instance Methods
 
__init__(self, title='HamsterWheel')
 
__del__(self)
 
run_game(self)
The main game loop, should be called on a derived class to run the game.
 
update(self, seconds)
Should be defined in a derived class to update the game state seconds is the amount of game time that should pass
 
draw(self)
Should be defined in a derived class to draw the game
 
draw_debug(self)
Should be defined in a derived class to draw the game
 
process_sdl_event(self, event)
derived classes should call the base classes process function
 
quit(self)
called when a quit message is posted
 
register_for_events(self, obj)
call this with self to get your function "hamsterwheel_event" called before and after updates, draws and frames hamsterwheel_event will be called with one arg eventtype which will be one of the HamsterWheel.event members
 
unregister_for_events(self, obj)
called to stop getting event calls
Class Variables
  the_game = None
  events = Enum("FrameStart", "FrameEnd", "UpdateStart", "Update...
Method Details

run_game(self)

 
The main game loop, should be called on a derived class to run the game. this routine controls synchronization with the editor & the game clock

quit(self)

 

called when a quit message is posted

the HamsterWheel base class responds by setting is_playing to false in order to end the update a loop. derived classes should call the base class, but may conditionally ignore quit messages by not doing so

Class Variable Details

events

Value:
Enum("FrameStart", "FrameEnd", "UpdateStart", "UpdateEnd", "DrawStart"\
, "DrawEnd")