Skip to content

API Reference

This page documents the public aj. namespace. All functions and classes listed here are available directly from ajishio.

Game Objects

ajishio.game_object.GameObject

Bases: IGameObject

place_meeting

place_meeting(
    x: float,
    y: float,
    obj: IGameObject | type[IGameObject] | UUID,
) -> IGameObject | None

With this function you can check a position for a collision with another instance or all instances of an object using the collision mask of the instance that runs the code for the check. When you use this you are effectively asking Ajishio to move the instance to the new position, check for a collision, move back and tell you if a collision was found or not.

This function will return the unique instance id of the object being collided. This function will return None if no collision occurs, or the exact instance found if a collision does occur.

Rendering

ajishio.rendering.load_font

load_font(font_path: Path | str, size: int) -> pg.font.Font

ajishio.rendering.make_color_hsv

make_color_hsv(hue: float, sat: float, val: float) -> Color

Input

ajishio.input.keyboard_check

keyboard_check(key: int) -> bool

ajishio.input.keyboard_check_pressed

keyboard_check_pressed(key: int) -> bool

ajishio.input.keyboard_check_released

keyboard_check_released(key: int) -> bool

ajishio.input.mouse_check_button

mouse_check_button(mb: int) -> bool

ajishio.input.mouse_check_button_pressed

mouse_check_button_pressed(mb: int) -> bool

ajishio.input.mouse_check_button_released

mouse_check_button_released(mb: int) -> bool

ajishio.input.ord

ord(char: str) -> int

Utilities

ajishio.utils.clamp

clamp(value: float, min: float, max: float) -> float

ajishio.utils.lengthdir_x

lengthdir_x(length: float, direction: float) -> float

Returns the length of the x component of a vector with the given length and direction (in radians).

ajishio.utils.lengthdir_y

lengthdir_y(length: float, direction: float) -> float

Returns the length of the y component of a vector with the given length and direction (in radians).

ajishio.utils.lerp

lerp(start: float, end: float, t: float) -> float

ajishio.utils.map_value

map_value(
    value: float,
    min: float,
    max: float,
    new_min: float,
    new_max: float,
) -> float

ajishio.utils.point_distance

point_distance(
    x1: float, y1: float, x2: float, y2: float
) -> float

ajishio.utils.profile

profile(fn: Callable[_P, _R]) -> Callable[_P, _R]

Decorator that profiles fn when --profile is passed on the command line.

The .prof file is saved to the current working directory and named after the module that owns the decorated function (e.g. platformer.prof). Without --profile the function runs completely unmodified.

Example::

@aj.profile
def main() -> None:
    aj.game_start()

main()

ajishio.utils.room_set_caption

room_set_caption(caption: str) -> None

ajishio.utils.sign

sign(value: float) -> int

Types & Constants

ajishio.types.CollisionMask dataclass

ajishio.CustomFields

CustomFields = dict[str, object]

ajishio.types.Entity

Bases: TypedDict

ajishio.types.GameLevel dataclass

ajishio.types.GameObjectKwargs

Bases: TypedDict

ajishio.types.GameSprite dataclass

ajishio.types.IGameObject

Bases: Protocol

on_destroy

on_destroy() -> None

This event is the event to be executed when an instance is destroyed. It is often overlooked when adding behaviours to objects, but it can be very useful, for example by creating explosion or particle effects when an enemy is killed, or for respawning a new instance of the object in another part of the room, or even for adding points to a score.

Asset Loaders

ajishio.sprite_loader.load_aseprite_sprite

load_aseprite_sprite(sprite_dir: Path) -> GameSprite

ajishio.sprite_loader.load_aseprite_sprites

load_aseprite_sprites(
    sprites_directory: Path,
) -> dict[str, GameSprite]

ajishio.sprite_loader.sprite_set_offset

sprite_set_offset(
    sprite: GameSprite, x_offset: float, y_offset: float
) -> None

Asset Loaders

ajishio.sound_loader.load_sound

load_sound(sound_file: Path) -> GameSound

ajishio.sound_loader.load_sounds

load_sounds(sounds_directory: Path) -> dict[str, GameSound]

Asset Loaders

ajishio.level_loader.load_ldtk_levels

load_ldtk_levels(
    ldtk_super_simple_export_simplified_path: Path,
) -> list[GameLevel]

Audio

ajishio.game_sound.GameSound

Other

ajishio.c_aqua module-attribute

c_aqua = Color(0, 255, 255)

ajishio.c_black module-attribute

c_black = Color(0, 0, 0)

ajishio.c_blue module-attribute

c_blue = Color(0, 0, 255)

ajishio.c_dkgray module-attribute

c_dkgray = Color(64, 64, 64)

ajishio.c_fuchsia module-attribute

c_fuchsia = Color(255, 0, 255)

ajishio.c_gray module-attribute

c_gray = Color(128, 128, 128)

ajishio.c_green module-attribute

c_green = Color(0, 128, 0)

ajishio.c_lime module-attribute

c_lime = Color(0, 255, 0)

ajishio.c_ltgray module-attribute

c_ltgray = Color(192, 192, 192)

ajishio.c_maroon module-attribute

c_maroon = Color(128, 0, 0)

ajishio.c_navy module-attribute

c_navy = Color(0, 0, 128)

ajishio.c_olive module-attribute

c_olive = Color(128, 128, 0)

ajishio.c_orange module-attribute

c_orange = Color(255, 160, 64)

ajishio.c_purple module-attribute

c_purple = Color(128, 0, 128)

ajishio.c_red module-attribute

c_red = Color(255, 0, 0)

ajishio.c_silver module-attribute

c_silver = Color(192, 192, 192)

ajishio.c_teal module-attribute

c_teal = Color(0, 128, 128)

ajishio.c_white module-attribute

c_white = Color(255, 255, 255)

ajishio.c_yellow module-attribute

c_yellow = Color(255, 255, 0)

ajishio.mb_left module-attribute

mb_left: int = 1

ajishio.mb_middle module-attribute

mb_middle: int = 2

ajishio.mb_right module-attribute

mb_right: int = 3

ajishio.view_current module-attribute

view_current: int

ajishio.view_hport module-attribute

view_hport = view_hport

ajishio.view_wport module-attribute

view_wport = view_wport

ajishio.view_xport module-attribute

view_xport = view_xport

ajishio.view_yport module-attribute

view_yport = view_yport

ajishio.vk_down module-attribute

vk_down: int = K_DOWN

ajishio.vk_enter module-attribute

vk_enter: int = K_RETURN

ajishio.vk_escape module-attribute

vk_escape: int = K_ESCAPE

ajishio.vk_left module-attribute

vk_left: int = K_LEFT

ajishio.vk_right module-attribute

vk_right: int = K_RIGHT

ajishio.vk_space module-attribute

vk_space: int = K_SPACE

ajishio.vk_up module-attribute

vk_up: int = K_UP

ajishio.window_height module-attribute

window_height: int

ajishio.window_width module-attribute

window_width: int