core.engine package

Submodules

core.engine.color module

RGBA colors in Forge.

class core.engine.color.Color(red: int, green: int, blue: int, alpha: int = 255)

Bases: object

Forge’s representation of an 8-bit RGBA color.

alpha: int
as_pygame_color() Color

Return the color as a Pygame color. Beneficial for internal interoperability with Pygame.

Returns

Pygame color from the color’s R, G, B and A components respectively.

Return type

pygame.color.Color

as_tuple(with_alpha: bool = False) tuple[int, int, int] | tuple[int, int, int, int]

Return the R, G, B and (optionally) A components of the Color in a tuple. Beneficial for internal interoperability with Pygame.

Parameters

with_alpha (bool) – Whether to include the alpha values in the tuple.

Returns

Tuple of the color’s R, G, B and (optionally) A components respectively.

Return type

tuple[int, int, int] | tuple[int, int, int, int]

blue: int
green: int
red: int
core.engine.color.random(with_alpha: bool = False) Color

Create a new random color.

Parameters

with_alpha (bool) – Whether to include the alpha value during the random number generation.

Returns

New random color.

Return type

Color

core.engine.constants module

Global constants for Forge.

core.engine.display module

Base display for Forge.

class core.engine.display.Display(width: int, height: int, title: str, max_fps: int = 0, background_color: ~core.engine.color.Color = Color -> R: 0, G: 0, B: 0, A: 255)

Bases: object

Display class for Forge which is independent of its users.

background_color
static height() int

Get the height of the display.

Returns

Height of the display.

Return type

int

max_fps
object_renderer
render() None

Render the display background color and call all the display renderers to render from their pools.

static size() Vector2D

Get the size of the display as a Forge Vector2D.

Returns

Size of the display.

Return type

core.physics.vector.Vector2D

title
update() None

Update the display and all the display renderers. Also calculate the delta time after each update loop.

static width() int

Get the width of the display.

Returns

Width of the display.

Return type

int

core.engine.image module

Images in Forge.

class core.engine.image.Image(name: str, filename: str, position: Vector2D)

Bases: Renderable

Forge’s representation of a unique image.

add_to_renderer(renderer_name: str = 'display-object-renderer') None

Add the image to a renderer.

Parameters

renderer_name (str) – Name of the renderer to which the image is to be added; defaults to the base object renderer.

as_pygame_surface() Surface

Return the image as a Pygame surface. Beneficial for internal interoperability with Pygame.

Returns

Pygame surface containing the image data without the position.

Return type

core.utils.aliases.Surface

filename: str
name: str
position: Vector2D
render(display: Surface) None

Render the Forge image as a Pygame surface to the display at its given position.

Parameters

display (core.utils.aliases.Surface) – Display to which the image is to be rendered.

class core.engine.image.ImagePool(name: str, _images: list[core.engine.image.Image] = <factory>)

Bases: Renderable

Forge’s image pool utility.

add_to_renderer(renderer_name: str = 'display-object-renderer') None

Add the image pool to a renderer.

Parameters

renderer_name (str) – Name of the renderer to which the image pool is to be added; defaults to the base object renderer.

images() list[core.engine.image.Image]

Return the images of the pool.

Returns

List of images stored within the image pool.

Return type

list[Image]

name: str
core.engine.image.delete_image(image_name: str, pool_name: str = '') None

Delete a particular image which may either be a standalone image or part of a pool.

Parameters
  • image_name (str) – Name of the image to delete.

  • pool_name (str) – Name of the pool, if any; defaults to an empty string.

Raises

KeyError – An image must be registered if it is to be deleted.

core.engine.image.delete_images(pool_name: str) None

Delete all the images from a particular image pool.

Parameters

pool_name (str) – Name of the pool to which the images belong.

Raises

ResourceWarning – A pool of the given name must ideally exist otherwise in effect, no images will be deleted.

core.engine.image.get_image(image_name: str, pool_name: str = '') Image

Get a particular image which may either be a standalone image or part of a pool.

Parameters
  • image_name (str) – Name of the image to retrieve.

  • pool_name (str) – Name of the pool, if any; defaults to an empty string.

Returns

Forge image, if it exists.

Return type

Image

Raises

KeyError – An image must be registered if it is to be retrieved.

core.engine.image.get_images(pool_name: str) list[core.engine.image.Image]

Get all the images from a particular image pool.

Parameters

pool_name (str) – Name of the pool to which the images belong.

Returns

List of images belonging to that pool.

Return type

list[Image]

Raises

ResourceWarning – A pool of the given name must ideally exist otherwise, the returned list will be empty.

core.engine.renderer module

Renderers for Forge.

class core.engine.renderer.ObjectRenderer(name: str, images: list[core.engine.image.Image], static_bodies: list['core.physics.static_body.StaticBody2D'], rigid_bodies: list['core.physics.rigid_body.RigidBody2D'], lines: list['core.physics.line.Line'])

Bases: Renderer

Forge’s base object renderer to render physics based objects to the display.

lines
render(display: Surface) None

Render all the images from the pool, static bodies, rigid bodies and lines to the display.

Parameters

display (core.utils.aliases.Surface) – Display to which the objects are to be rendered.

rigid_bodies
static_bodies
class core.engine.renderer.Renderer(name: str, images: list[core.engine.image.Image])

Bases: Renderable

Forge’s base renderer which only supports images.

image_pool
name
render(display: Surface) None

Render all the images from the pool to the display.

Parameters

display (core.utils.aliases.Surface) – Display to which the images are to be rendered.

update(delta_time: float) None

Update the renderer; called every frame.

Parameters

delta_time (float) – Delta time between frames.

class core.engine.renderer.UIRenderer(name: str, images: list[core.engine.image.Image])

Bases: Renderer

Forge’s base UI renderer to render Hearth UI elements to the display.

image_pool
name
core.engine.renderer.delete_renderer(renderer_name: str) None

Delete a particular renderer.

Parameters

renderer_name (str) – Name of the renderer to delete.

Raises

KeyError – A renderer must be registered if it is to be deleted.

core.engine.renderer.get_renderer(renderer_name: str) core.engine.renderer.Renderer | core.engine.renderer.ObjectRenderer | core.engine.renderer.UIRenderer

Get a particular renderer.

Parameters

renderer_name (str) – Name of the renderer to retrieve.

Returns

Forge renderer, if it exists.

Return type

Renderer | ObjectRenderer | UIRenderer

Raises

KeyError – A renderer must be registered if it is to be retrieved.

core.engine.settings module

Global settings for Forge.

core.engine.sprite module

Sprites in Forge.

class core.engine.sprite.Sprite(filename: str)

Bases: object

Forge’s representation of a generic sprite, without positional data.

as_pygame_surface() Surface

Return the sprite as a Pygame surface. Beneficial for internal interoperability with Pygame.

Returns

Pygame surface containing the image data.

Return type

core.utils.aliases.Surface

filename: str
render(display: Surface, position: Vector2D) None

Render the sprite as a Pygame surface to the display at its given position.

Parameters
  • display (core.utils.aliases.Surface) – Display to which the sprite is to be rendered.

  • position (core.physics.vector.Vector2D) – Position at which the sprite is to be rendered.

core.engine.timer module

Basic timer in Forge.

class core.engine.timer.Timer(rounding: int = 2, _start: Optional[float] = None)

Bases: object

Forge’s basic timer using real-world time data as opposed to an in-built game timer for greater accuracy.

reset() None

Reset the timer; essentially start it over again.

rounding: int
start() None

Start the timer.

stop() None

Stop the timer.

time() float

Get the elapsed time since the timer was started in seconds. Also round the elapsed time to a specified precision.

Returns

Elapsed time since the timer was started.

Return type

float

Raises

RuntimeError – A stopped timer cannot output the elapsed time.

Module contents