Code Documentation
At the top level, the __main__.py
file will create an instance of the
GameWindow
class. This class manages the GUI and responds to events.
The next layer down is the GameEngine
. This is more of a logic layer, although
it isn’t completely divorced from the display.
Game Window
Main Window Manager.
-
class
source.game_window.
MyGame
(width, height, title)[source]
Main application class.
Manage the GUI
-
__init__
(width, height, title)[source]
- Parameters
-
-
check_for_player_movement
()[source]
Figure out if we should move the player or not based on keys currently
held down.
-
draw_character_screen
()[source]
-
draw_hp_and_status_bar
()[source]
-
draw_in_normal_state
()[source]
-
draw_in_select_location_state
()[source]
-
draw_inventory
()[source]
-
draw_messages
()[source]
-
draw_mouse_over_text
()[source]
-
draw_sprites_and_status_panel
()[source]
-
handle_character_screen_click
(x, y)[source]
-
handle_messages
()[source]
-
load
()[source]
Load the game from disk.
-
on_draw
()[source]
Render the screen.
-
on_key_press
(key, modifiers)[source]
Manage key-down events
- Parameters
-
-
on_key_release
(key, modifiers)[source]
Called when the user releases a key.
- Parameters
-
-
on_mouse_motion
(x, y, dx, dy)[source]
Handle mouse motion, mostly just used for mouse-over text.
-
on_mouse_press
(x, y, button, modifiers)[source]
Handle mouse-down events
- Parameters
-
-
on_update
(delta_time)[source]
Manage regular updates for the game
- Parameters
delta_time (float
) –
-
save
()[source]
Save the current game to disk.
-
setup
()[source]
Set up the game here. Call this function to restart the game.
-
source.game_window.
main
()[source]
Main method for starting the rogue-like game
Game Engine
Define the game engine
-
class
source.game_engine.
GameEngine
[source]
This is the main game engine class, that manages the game and its actions.
-
__init__
()[source]
Set the game engine’s attributes
-
check_experience_level
()[source]
See if the player should level up
-
dying
(target)[source]
Handle event of an entity dying
- Parameters
target (Entity
) –
- Return type
list
-
get_dict
()[source]
Get a dictionary object for the entire game. Used in serializing
the game state for saving to disk or sending over the network.
-
grid_click
(grid_x, grid_y)[source]
Handle a click on the grid
-
move_enemies
()[source]
Process enemy movement.
-
move_player
(cx, cy)[source]
Process player movement
- Parameters
-
-
pick_up
()[source]
Handle a pick-up item entity request.
-
process_action_queue
(delta_time)[source]
Process the action queue, kind of a dispatch-center for the game.
- Parameters
delta_time (float
) –
-
restore_from_dict
(data)[source]
Restore this object from a dictionary object. Used in recreating a game from a
saved state, or from over the network.
- Parameters
data (dict
) –
-
setup
()[source]
Set up the game here. Call this function to restart the game.
-
setup_level
(level_number)[source]
- Parameters
level_number (int
) –
- Return type
GameLevel
-
use_stairs
()[source]
-
class
source.game_engine.
GameLevel
[source]
-
__init__
()[source]
Initialize level instance.