Package fortuneengine :: Module GameEngine :: Class GameEngine
[hide private]
[frames] | no frames]

Class GameEngine

source code

object --+
         |
        GameEngine

The Fortune Engine GameEngine is a main loop wrapper around pygame. It manages the event and drawing loops allowing the user to just register for user events and drawing time in the draw loop.

Instance Methods [hide private]
 
__init__(self, width=1200, height=900, always_draw=False, fps_cap=15, version=False, title='FortuneEngine')
Constructor for the game engine.
source code
 
set_dirty(self)
Sets the dirty flag to force the engine to draw the next time it enters the draw flag.
source code
 
get_scene(self)
Returns the scene object
source code
 
start_event_timer(self, function_cb, time)
Starts a timer that fires a user event into the queue every "time" milliseconds
source code
 
stop_event_timer(self, function_cb)
Stops the timer that has id from firing
source code
 
list_event_timers(self)
returns a list of configured timers, if the timers has a time of 0 the timer is disabled
source code
 
list_timer_time(self)
Returns a string representation of the time the game spends in each timer callback.
source code
 
start_main_loop(self)
Starts the game loop.
source code
 
_draw(self, tick_time)
Draws all elements in draw callback to the screen
source code
 
_event_loop(self)
The main event loop.
source code
 
stop_event_loop(self)
Sends a pygame.QUIT event into the event queue which exits the event loop
source code
 
add_event_callback(self, cb)
Adds event callback to the event callback stack
source code
 
remove_event_callback(self, cb)
Removes an event from the event callback stack
source code
 
list_event_callbacks(self)
Returns a string representation of all events registered with the game engine
source code
 
list_event_time(self)
Returns a string representation of the time the game spends in each event callback.
source code
 
add_draw_callback(self, fnc)
Adds a callback to the draw list.
source code
 
pop_draw_callback(self)
Removes top of draw stack and returns it
source code
 
clear_draw_callback(self)
Empties draw callback stack
source code
 
remove_draw_callback(self, fnc)
Removes a draw callback from the game engine draw function
source code
 
list_draw_callbacks(self)
Lists all the draw callbacks currently registered with the game engine
source code
 
list_draw_time(self)
Returns a string representation of the time the game spends in each drawing callback.
source code
 
has_object(self, name)
Returns true if object is stored in game engine
source code
 
add_object(self, name, obj)
Adds an object to the game engine datastore
source code
 
get_object(self, name)
Returns an object from the game engine datastore
source code
 
remove_object(self, name)
Removes an object from the game engine datastore
source code
 
list_objects(self)
Returns a sting of registered objects
source code
 
toggle_fps(self)
Toggles fps display
source code
 
art_scale(self, original, expected, width=True) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  instance = None
hash(x)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, width=1200, height=900, always_draw=False, fps_cap=15, version=False, title='FortuneEngine')
(Constructor)

source code 

Constructor for the game engine.

Parameters:
  • width - Window width
  • height - Window height
  • always_draw - Boolean to set the animation mode to always draw vs draw when set_dirty is called
  • fps_cap - Sets the framerate cap. Set to 0 to disable the cap. Warning: setting the cap to 0 when always draw = False will cause cpu 100% when not driving.
  • version - If true, use new rendering system, false uses only the draw system
  • title - Window Title
Overrides: object.__init__

get_scene(self)

source code 

Returns the scene object

Returns:
Returns the scene object held by the game engine

start_event_timer(self, function_cb, time)

source code 

Starts a timer that fires a user event into the queue every "time" milliseconds

Parameters:
  • function_cb - The function to call when timer fires
  • time - Milliseconds between fires

stop_event_timer(self, function_cb)

source code 

Stops the timer that has id from firing

Parameters:
  • function_cb - The function registered with the timer that should be canceled

start_main_loop(self)

source code 

Starts the game loop.

This function does not return until after the game loop exits

_draw(self, tick_time)

source code 

Draws all elements in draw callback to the screen

Parameters:
  • tick_time - The amount of time passed since last draw cycle. (should be produced by pygamme.clock.tick method)

add_event_callback(self, cb)

source code 

Adds event callback to the event callback stack

Parameters:
  • cb - Callback to be added to the stack when events are fired.

remove_event_callback(self, cb)

source code 

Removes an event from the event callback stack

Parameters:
  • cb - The callback to remove from the event callback stack
Returns:
Returns true if successful in removing callback

add_draw_callback(self, fnc)

source code 

Adds a callback to the draw list. Function will be passed the game screen it should draw too.

Parameters:
  • fnc - The function to call when system is drawing

pop_draw_callback(self)

source code 

Removes top of draw stack and returns it

Returns:
Returns the top callback function that was removed

remove_draw_callback(self, fnc)

source code 

Removes a draw callback from the game engine draw function

Parameters:
  • fnc - The callback function to remove
Returns:
Returns true if successful removal of the function

has_object(self, name)

source code 

Returns true if object is stored in game engine

Parameters:
  • name - Name of the object to check if exists
Returns:
Returns true if object found

add_object(self, name, obj)

source code 

Adds an object to the game engine datastore

Parameters:
  • name - The name used to store the object
  • obj - The object to store

get_object(self, name)

source code 

Returns an object from the game engine datastore

Parameters:
  • name - The name of object to return
Returns:
Returns the object

remove_object(self, name)

source code 

Removes an object from the game engine datastore

Parameters:
  • name - The name of the object to remove