Purpose
Represent physical and visual objects in the game world.
Definitions
object_t
Abstract representation of a physical object in a game. Can be drawn, updated, or moved by physics. The sprite's position is used as the 'real' position in the engine.
struct object_t {
sprite_t sprite;
int active;
int wants_to_be_deleted;
physics_t physics;
uintptr_t timer;
tick_fn evt_update;
draw_fn evt_draw;
}
tick_fn
void(*tick_fn)(object_t*)
The frame update event of an object.
draw_fn
void(*tick_fn)(object_t*)
The render event of an object.
Fields
sprite: sprite_t
the sprite element defines most of the object. The sprite x
, y
and rot
are the position and rotation of the entire object.
Default value: sprite_default()
active: int
If this is set to 0
the object's draw and update events will not be evoked by the core game loop.
Default value: 1
wants_to_be_deleted: int
If this is set to 1
the object is queued for deletion. It is now unsafe to access, and any pointers should be treated as if null.
Default value: 0
physics: physics_t
The physics component defines the collider and physics solver of the object. If the object needs to be an obstructive force, or needs to be moved around through input, this is where to adjust things.
Default value: physics_default()
timer: uintptr_t
A pointer-sized number that is not adjusted by the engine. Free to be used for whatever.
Default value: undefined
evt_update: tick_fn
typedef void(*tick_fn)(object_t*)
The update event. Called after game_update, right before the draw event. All update events will be called before the the draw event is triggered.
Default value: NULL
evt_draw: draw_fn
typedef void(*draw_fn)(object_t*)
The draw event. Called after the update events for all objects have finished.
Default value: &object_draw_sprite
Functions
object_t object_default()
Creates a stack allocated default object. Does not allocate any heap memory. Deleting this only requires letting the object go out of scope.
returns: A new default object.
int object_is_valid(const object_t* this)
Check if the object is usable. If return value is 0
, treat the pointer contents as garbage data.
returns: 1
if the object is valid
returns: 0
if the object should not be accessed