gale.game module
This file contains the implementation of the class Game: the window, virtual-resolution scaling, and game loop (fixed-ish update/render, driven by real elapsed time) every gale game is built on top of.
Importing this module calls pygame.init().
Author: Alejandro Mujica (aledrums@gmail.com)
- class gale.game.Game(title=None, window_width=800, window_height=600, virtual_width=None, virtual_height=None, fps=60, *args, **kwargs)[source]
Bases:
InputListenerBase class to implemente a game by using pygame.
This class handles the window to show the game an a virtual screen with the resolution that you want to emulate. This also handles timer and the game loop.
Usage example:
- class MyGame(Game):
- def init(self) -> None:
# Set your own initial configuration of the game. self.player = Player() self.world = World()
- def on_input(self, input_id: str, input_data: InputData) -> None:
# Make your action when an input is detected. if input_id == “quit” and input_data.pressed:
self.quit()
- def update(self, dt: float) -> None:
# Update of all your game elements here. # dt is the elapsed time in secconds. self.world.update(dt) self.player.update(dt) self.player.interact_with(self.world)
- def render(self, surface: pygame.Surface) -> None:
# Render all of your game elements on the virtual # screen surface. self.world.render(surface) self.player.render(surface)
game = MyGame(title=’Title of my game’) game.exec()
- Parameters:
title (str | None)
window_width (int)
window_height (int)
virtual_width (int | None)
virtual_height (int | None)
fps (int)
args (Tuple[Any])
kwargs (Dict[str, Any])
- on_input(input_id, input_data)[source]
Empty. This should be implemented by the extension class.
- Parameters:
input_id (str)
input_data (InputData)
- Return type:
None
- update(dt)[source]
Empty. This should be implemented by the extension class.
- Parameters:
dt (float) – Time elapsed (in seconds) since the last time this function has been executed.
- Return type:
None