termgame.base package

Submodules

termgame.base.engine module

Description: The base game engine. Author: Gregory Glatzer Date: 10/22/2022

class termgame.base.engine.Engine(width: int, height: int, gameobjects: List[Gameobject] | None = None)

Bases: object

add_gameobject(gameobject: Gameobject) None

Add a gameobject to the engine.

clear() None

Clear the screen without any blinking.

property elapsed_time: float
property frame: int
property gameobjects: List[Gameobject]
get_gameobjects(names: str | List[str] = '') List[Gameobject]

Get all gameobjects with given name(s). Empty returns all gameobjects.

run() None

Run the engine.

termgame.base.gameobject module

Description: The game object class. Author: Gregory Glatzer Date: 10/23/2022

class termgame.base.gameobject.Gameobject(x: 'int' = 0, y: 'int' = 0, depth: 'int' = 0, update_order: 'int' = 0, sprites: 'List | None' = None, meshes: 'List | None' = None, on_start: 'Callable' = <function Gameobject.<lambda> at 0x7f7d9efaeb00>, on_update: 'Callable' = <function Gameobject.<lambda> at 0x7f7d9efaeb90>, name: 'str' = '')

Bases: object

get_active_mesh() Any

Access the active mesh (3D) of the gameobject, if any.

get_active_sprite() Any

Access the active sprite (2D) of the gameobject, if any.

get_meshes() Any

Access the meshes (3D) of the gameobject, if any.

get_sprites() Any

Access the sprites (2D) of the gameobject, if any.

property has_physics: bool
property height: int | float
property name: str
set_meshes(meshes) None
set_sprites(sprites) None
property width: int | float
class termgame.base.gameobject.GameobjectAnimator(elements: List)

Bases: object

Class for animating gameobjects by looping through a list of sprites or meshes.

get_active_element() Any
next(frame: int) None

Move the animation to the next frame in the list of elements.

start() None

Start the animation.

termgame.base.physics_engine module

Description: Wrapper around the base engine to add physics with pymunk. Author: Gregory Glatzer Date: 12/12/2022

class termgame.base.physics_engine.PhysicsEngine(width: int, height: int, gravity: tuple[float, float] = (0, 98.1), **engine_kwargs)

Bases: Engine

add_gameobject(gameobject: Gameobject) None
Add a gameobject to the engine. Will also add the rigidbody

to the physics space, if it has one.

run() None

Run the engine.

property space: Space

The pymunk space for 2d physics.

termgame.base.physics_gameobject module

class termgame.base.physics_gameobject.PhysicsGameobject(on_fixed_update: ~typing.Callable = <function PhysicsGameobject.<lambda>>, static_body: bool = False, max_velocity: int | None = None, **gameobject_kwargs)

Bases: Gameobject

static from_gameobject(gameobject: Gameobject, static_body: bool = True) PhysicsGameobject

Convert a Gameobject to a PhysicsGameobject.

property has_physics: bool
property rb: Body

Shorthand for self.rigidbody

property rigidbody: Body

Module contents

This module contains the base classes for the engine, including the engine itself, a physics engine wrapper, gameobjects and a physics gameobject wrapper.

class termgame.base.Engine(width: int, height: int, gameobjects: List[Gameobject] | None = None)

Bases: object

add_gameobject(gameobject: Gameobject) None

Add a gameobject to the engine.

clear() None

Clear the screen without any blinking.

property elapsed_time: float
property frame: int
property gameobjects: List[Gameobject]
get_gameobjects(names: str | List[str] = '') List[Gameobject]

Get all gameobjects with given name(s). Empty returns all gameobjects.

run() None

Run the engine.

class termgame.base.Gameobject(x: 'int' = 0, y: 'int' = 0, depth: 'int' = 0, update_order: 'int' = 0, sprites: 'List | None' = None, meshes: 'List | None' = None, on_start: 'Callable' = <function Gameobject.<lambda> at 0x7f7d9efaeb00>, on_update: 'Callable' = <function Gameobject.<lambda> at 0x7f7d9efaeb90>, name: 'str' = '')

Bases: object

get_active_mesh() Any

Access the active mesh (3D) of the gameobject, if any.

get_active_sprite() Any

Access the active sprite (2D) of the gameobject, if any.

get_meshes() Any

Access the meshes (3D) of the gameobject, if any.

get_sprites() Any

Access the sprites (2D) of the gameobject, if any.

property has_physics: bool
property height: int | float
property name: str
set_meshes(meshes) None
set_sprites(sprites) None
property width: int | float
class termgame.base.PhysicsEngine(width: int, height: int, gravity: tuple[float, float] = (0, 98.1), **engine_kwargs)

Bases: Engine

add_gameobject(gameobject: Gameobject) None
Add a gameobject to the engine. Will also add the rigidbody

to the physics space, if it has one.

run() None

Run the engine.

property space: Space

The pymunk space for 2d physics.

class termgame.base.PhysicsGameobject(on_fixed_update: ~typing.Callable = <function PhysicsGameobject.<lambda>>, static_body: bool = False, max_velocity: int | None = None, **gameobject_kwargs)

Bases: Gameobject

static from_gameobject(gameobject: Gameobject, static_body: bool = True) PhysicsGameobject

Convert a Gameobject to a PhysicsGameobject.

property has_physics: bool
property rb: Body

Shorthand for self.rigidbody

property rigidbody: Body