2025-08-03 10:07:35 -04:00
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
|
#include <SDL3_image/SDL_image.h>
|
|
|
|
|
#include <string.h>
|
2026-01-05 08:58:06 -05:00
|
|
|
#include <akerror.h>
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-25 21:29:18 -04:00
|
|
|
#include <akgl/physics.h>
|
2026-05-07 22:20:10 -04:00
|
|
|
#include <akgl/game.h>
|
|
|
|
|
#include <akgl/sprite.h>
|
|
|
|
|
#include <akgl/actor.h>
|
|
|
|
|
#include <akgl/heap.h>
|
|
|
|
|
#include <akgl/registry.h>
|
|
|
|
|
#include <akgl/staticstring.h>
|
|
|
|
|
#include <akgl/iterator.h>
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext *akgl_actor_initialize(akgl_Actor *obj, char *name)
|
2025-08-03 10:07:35 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-06 23:18:42 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "akgl_actor_initialize received null actor pointer");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, name, AKERR_NULLPOINTER, "akgl_actor_initialize received null name string pointer");
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
memset(obj, 0x00, sizeof(akgl_Actor));
|
|
|
|
|
strncpy((char *)obj->name, name, AKGL_ACTOR_MAX_NAME_LENGTH);
|
2025-08-03 10:07:35 -04:00
|
|
|
obj->curSpriteReversing = false;
|
2026-05-13 16:56:24 -04:00
|
|
|
obj->scale = 1.0;
|
2025-08-03 10:07:35 -04:00
|
|
|
obj->movement_controls_face = true;
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
obj->updatefunc = &akgl_actor_update;
|
|
|
|
|
obj->renderfunc = &akgl_actor_render;
|
|
|
|
|
obj->facefunc = &akgl_actor_automatic_face;
|
|
|
|
|
obj->movementlogicfunc = &akgl_actor_logic_movement;
|
|
|
|
|
obj->changeframefunc = &akgl_actor_logic_changeframe;
|
|
|
|
|
obj->addchild = &akgl_actor_add_child;
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
FAIL_ZERO_RETURN(
|
|
|
|
|
errctx,
|
2026-05-06 23:18:42 -04:00
|
|
|
SDL_SetPointerProperty(AKGL_REGISTRY_ACTOR, name, (void *)obj),
|
2026-05-03 23:57:55 -04:00
|
|
|
AKERR_KEY,
|
2025-08-03 10:07:35 -04:00
|
|
|
"Unable to add actor to registry"
|
|
|
|
|
);
|
|
|
|
|
obj->refcount += 1;
|
|
|
|
|
SDL_Log("Actor %s initialized and added to the registry", (char *)obj->name);
|
|
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext *akgl_actor_set_character(akgl_Actor *obj, char *basecharname)
|
2025-08-03 10:07:35 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, basecharname, AKERR_NULLPOINTER, "Null character reference");
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
obj->basechar = SDL_GetPointerProperty(AKGL_REGISTRY_CHARACTER, basecharname, NULL);
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "Character not found in the registry");
|
2025-08-03 10:07:35 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext *akgl_actor_automatic_face(akgl_Actor *obj)
|
2025-08-03 10:07:35 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference");
|
2025-08-03 10:07:35 -04:00
|
|
|
ATTEMPT {
|
|
|
|
|
if ( obj->movement_controls_face == true ) {
|
|
|
|
|
// TODO : This doesn't really work properly
|
2026-05-06 23:18:42 -04:00
|
|
|
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_FACE_ALL);
|
|
|
|
|
if ( AKGL_BITMASK_HAS(obj->state, AKGL_ACTOR_STATE_MOVING_LEFT) ) {
|
|
|
|
|
AKGL_BITMASK_ADD(obj->state, AKGL_ACTOR_STATE_FACE_LEFT);
|
|
|
|
|
} else if ( AKGL_BITMASK_HAS(obj->state, AKGL_ACTOR_STATE_MOVING_RIGHT) ) {
|
|
|
|
|
AKGL_BITMASK_ADD(obj->state, AKGL_ACTOR_STATE_FACE_RIGHT);
|
|
|
|
|
} else if ( AKGL_BITMASK_HAS(obj->state, AKGL_ACTOR_STATE_MOVING_UP) ) {
|
|
|
|
|
AKGL_BITMASK_ADD(obj->state, AKGL_ACTOR_STATE_FACE_UP);
|
|
|
|
|
} else if ( AKGL_BITMASK_HAS(obj->state, AKGL_ACTOR_STATE_MOVING_DOWN) ) {
|
|
|
|
|
AKGL_BITMASK_ADD(obj->state, AKGL_ACTOR_STATE_FACE_DOWN);
|
2025-08-03 10:07:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} CLEANUP {
|
|
|
|
|
} PROCESS(errctx) {
|
|
|
|
|
} FINISH(errctx, true);
|
|
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext *akgl_actor_logic_changeframe(akgl_Actor *obj, akgl_Sprite *curSprite, SDL_Time curtime)
|
2025-08-03 10:07:35 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference");
|
2025-08-03 10:07:35 -04:00
|
|
|
ATTEMPT {
|
|
|
|
|
// are we currently looping in reverse?
|
|
|
|
|
if ( curSprite->loop == true && obj->curSpriteReversing == true ) {
|
|
|
|
|
// are we at the beginning of the loop?
|
|
|
|
|
if ( obj->curSpriteFrameId == 0 ) {
|
|
|
|
|
obj->curSpriteReversing = false;
|
|
|
|
|
obj->curSpriteFrameId += 1;
|
|
|
|
|
} else {
|
|
|
|
|
obj->curSpriteFrameId -= 1;
|
|
|
|
|
}
|
|
|
|
|
// are we at the end of the animation?
|
2025-08-09 08:54:12 -04:00
|
|
|
} else if ( obj->curSpriteFrameId >= (curSprite->frames-1) ) {
|
2025-08-03 10:07:35 -04:00
|
|
|
// are we set to loop in reverse?
|
|
|
|
|
if ( curSprite->loop == true && curSprite->loopReverse == true ) {
|
|
|
|
|
obj->curSpriteReversing = true;
|
|
|
|
|
obj->curSpriteFrameId -= 1;
|
|
|
|
|
// are we set to loop forward?
|
2025-08-09 08:54:12 -04:00
|
|
|
} else {
|
|
|
|
|
// we are at the end of the animation and we either loop forward or do not loop
|
2025-08-03 10:07:35 -04:00
|
|
|
obj->curSpriteFrameId = 0;
|
2025-08-09 08:54:12 -04:00
|
|
|
}
|
2025-08-03 10:07:35 -04:00
|
|
|
// we are not looping in reverse and we are not at the end of the animation
|
|
|
|
|
} else {
|
|
|
|
|
obj->curSpriteFrameId += 1;
|
|
|
|
|
}
|
|
|
|
|
} CLEANUP {
|
|
|
|
|
} PROCESS(errctx) {
|
|
|
|
|
} FINISH(errctx, true);
|
|
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-25 21:29:18 -04:00
|
|
|
// raises AKGL_ERR_LOGICINTERRUPT if we don't want the physics object to process us
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext *akgl_actor_logic_movement(akgl_Actor *obj, SDL_Time curtime)
|
2025-08-03 10:07:35 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-26 10:36:31 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "obj");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "obj->basechar");
|
|
|
|
|
if ( obj->vx > obj->basechar->sx ) {
|
|
|
|
|
obj->vx = obj->basechar->sx;
|
|
|
|
|
}
|
|
|
|
|
if ( obj->vy > obj->basechar->sy ) {
|
|
|
|
|
obj->vy = obj->basechar->sy;
|
|
|
|
|
}
|
2026-05-25 21:29:18 -04:00
|
|
|
// Effectively a NOOP, this is handled by the physics engine now
|
|
|
|
|
// These functions are still present in case the library user wants per-actor behavior
|
2025-08-03 10:07:35 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext *akgl_actor_update(akgl_Actor *obj)
|
2025-08-03 10:07:35 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
|
|
|
|
SDL_Time curtime = 0;
|
2026-05-06 23:18:42 -04:00
|
|
|
akgl_Sprite *curSprite = NULL;
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor reference");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "Actor has NULL base character reference");
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-25 21:29:18 -04:00
|
|
|
SDL_GetCurrentTime(&curtime);
|
|
|
|
|
PASS(errctx, obj->facefunc(obj));
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
ATTEMPT {
|
2026-05-06 23:18:42 -04:00
|
|
|
CATCH(errctx, akgl_character_sprite_get(obj->basechar, obj->state, &curSprite));
|
2026-05-05 20:39:58 -04:00
|
|
|
if ( ((curtime) - obj->curSpriteFrameTimer) >= curSprite->speed) {
|
|
|
|
|
CATCH(errctx, obj->changeframefunc(obj, curSprite, curtime));
|
|
|
|
|
obj->curSpriteFrameTimer = curtime;
|
2025-08-03 10:07:35 -04:00
|
|
|
}
|
|
|
|
|
} CLEANUP {
|
|
|
|
|
} PROCESS(errctx) {
|
2026-05-03 23:57:55 -04:00
|
|
|
} HANDLE(errctx, AKERR_KEY) {
|
2026-05-25 21:29:18 -04:00
|
|
|
// TODO : Why are we passing this error? It could only come from akgl_character_sprite_get
|
|
|
|
|
// or changeframefunc, both of which should never return AKERR_KEY...
|
2025-08-03 10:07:35 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
} FINISH(errctx, true);
|
|
|
|
|
|
|
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
static akerr_ErrorContext *actor_visible(akgl_Actor *obj, SDL_FRect *camera, bool *visible)
|
2025-08-03 10:07:35 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-06 23:18:42 -04:00
|
|
|
akgl_Sprite *curSprite = NULL;
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "Actor has NULL base character reference");
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
ATTEMPT {
|
2026-05-06 23:18:42 -04:00
|
|
|
CATCH(errctx, akgl_character_sprite_get(obj->basechar, obj->state, &curSprite));
|
2025-08-03 10:07:35 -04:00
|
|
|
} CLEANUP {
|
|
|
|
|
} PROCESS(errctx) {
|
2026-05-03 23:57:55 -04:00
|
|
|
} HANDLE(errctx, AKERR_KEY) {
|
2025-08-03 10:07:35 -04:00
|
|
|
// TODO: Actor has no sprite matching the current state. Should we treat this as an error and throw?
|
|
|
|
|
*visible = false;
|
|
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
} FINISH(errctx, true);
|
|
|
|
|
|
|
|
|
|
if ( (obj->x < (camera->x - curSprite->width)) ||
|
|
|
|
|
(obj->x > (camera->x + camera->w)) ||
|
|
|
|
|
(obj->y < (camera->y - curSprite->height)) ||
|
|
|
|
|
(obj->y > (camera->y + camera->h)) ) {
|
|
|
|
|
*visible = false;
|
|
|
|
|
} else {
|
|
|
|
|
*visible = obj->visible;
|
|
|
|
|
}
|
|
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 21:59:29 -04:00
|
|
|
akerr_ErrorContext *akgl_actor_render(akgl_Actor *obj)
|
2025-08-03 10:07:35 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-06 23:18:42 -04:00
|
|
|
akgl_Sprite *curSprite = NULL;
|
2025-08-03 10:07:35 -04:00
|
|
|
bool visible = false;
|
|
|
|
|
SDL_FRect src;
|
|
|
|
|
SDL_FRect dest;
|
|
|
|
|
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "Actor has NULL base character reference");
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
ATTEMPT {
|
2026-05-06 23:18:42 -04:00
|
|
|
CATCH(errctx, akgl_character_sprite_get(obj->basechar, obj->state, &curSprite));
|
2025-08-03 10:07:35 -04:00
|
|
|
CATCH(errctx, actor_visible(obj, &camera, &visible));
|
|
|
|
|
} CLEANUP {
|
|
|
|
|
} PROCESS(errctx) {
|
2026-05-03 23:57:55 -04:00
|
|
|
} HANDLE(errctx, AKERR_KEY) {
|
|
|
|
|
} HANDLE_GROUP(errctx, AKERR_OUTOFBOUNDS) {
|
2025-08-03 10:07:35 -04:00
|
|
|
// If an actor doesn't have a sprite for a state, just log it and move on
|
|
|
|
|
LOG_ERROR(errctx);
|
|
|
|
|
} FINISH(errctx, true);
|
|
|
|
|
|
|
|
|
|
if ( ! visible ) {
|
|
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
2026-05-25 21:29:18 -04:00
|
|
|
|
2025-08-09 08:54:12 -04:00
|
|
|
if ( (obj->curSpriteFrameId > curSprite->frames) ) {
|
|
|
|
|
// This isn't necessarily an error - this actor's frame index is outside the range of
|
|
|
|
|
// their current sprite. There are a number of reasons this could happen, and it will
|
|
|
|
|
// get cleaned up on the next logic update. Just pass on rendering them this frame.
|
|
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
2026-05-12 15:21:36 -04:00
|
|
|
|
|
|
|
|
ATTEMPT {
|
|
|
|
|
CATCH(errctx,
|
|
|
|
|
akgl_sprite_sheet_coords_for_frame(
|
|
|
|
|
curSprite,
|
|
|
|
|
&src,
|
|
|
|
|
obj->curSpriteFrameId)
|
|
|
|
|
);
|
|
|
|
|
} CLEANUP {
|
|
|
|
|
} PROCESS(errctx) {
|
|
|
|
|
} FINISH(errctx, true);
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
if ( obj->parent != NULL ) {
|
|
|
|
|
dest.x = (obj->parent->x + obj->x - camera.x);
|
|
|
|
|
dest.y = (obj->parent->y + obj->y - camera.y);
|
|
|
|
|
} else {
|
|
|
|
|
dest.x = (obj->x - camera.x);
|
|
|
|
|
dest.y = (obj->y - camera.y);
|
|
|
|
|
}
|
2026-05-13 09:57:24 -04:00
|
|
|
dest.w = curSprite->width * obj->scale;
|
|
|
|
|
dest.h = curSprite->width * obj->scale;
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-24 21:59:29 -04:00
|
|
|
PASS(errctx, renderer.draw_texture(&renderer, curSprite->sheet->texture, &src, &dest, 0, NULL, SDL_FLIP_NONE));
|
2025-08-03 10:07:35 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext *akgl_actor_add_child(akgl_Actor *obj, akgl_Actor *child)
|
2025-08-03 10:07:35 -04:00
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL parent pointer");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, child, AKERR_NULLPOINTER, "NULL child pointer");
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_NONZERO_RETURN(errctx, child->parent, AKERR_RELATIONSHIP, "Child object already has a parent");
|
2026-05-06 23:18:42 -04:00
|
|
|
for ( i = 0; i < AKGL_ACTOR_MAX_CHILDREN ; i++ ) {
|
2025-08-03 10:07:35 -04:00
|
|
|
if ( obj->children[i] == NULL ) {
|
|
|
|
|
obj->children[i] = child;
|
|
|
|
|
child->parent = obj;
|
|
|
|
|
child->refcount += 1;
|
|
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_RETURN(errctx, AKERR_OUTOFBOUNDS, "Parent object has no remaining child slots left");
|
2025-08-03 10:07:35 -04:00
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_left_on(akgl_Actor *obj, SDL_Event *event)
|
2025-08-08 22:39:48 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("event %d (button %d / key %d) moves actor left", event->type, event->gbutton.which, event->key.key);
|
2026-05-06 23:18:42 -04:00
|
|
|
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
|
|
|
|
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_MOVING_LEFT | AKGL_ACTOR_STATE_FACE_LEFT));
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("new target actor state: %b", obj->state);
|
2025-08-08 22:39:48 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_left_off(akgl_Actor *obj, SDL_Event *event)
|
2025-08-08 22:39:48 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("event %d (button %d / key %d) stops moving actor left", event->type, event->gbutton.which, event->key.key);
|
2026-05-26 10:36:31 -04:00
|
|
|
obj->vx = 0;
|
2026-05-06 23:18:42 -04:00
|
|
|
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_LEFT);
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("new target actor state: %b", obj->state);
|
2025-08-08 22:39:48 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_right_on(akgl_Actor *obj, SDL_Event *event)
|
2025-08-08 22:39:48 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("event %d (button %d / key %d) moves actor right", event->type, event->gbutton.which, event->key.key);
|
2026-05-06 23:18:42 -04:00
|
|
|
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
|
|
|
|
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_MOVING_RIGHT | AKGL_ACTOR_STATE_FACE_RIGHT));
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("new target actor state: %b", obj->state);
|
2025-08-08 22:39:48 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_right_off(akgl_Actor *obj, SDL_Event *event)
|
2025-08-08 22:39:48 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("event %d (button %d / key %d) stops moving actor right", event->type, event->gbutton.which, event->key.key);
|
2026-05-26 10:36:31 -04:00
|
|
|
obj->vx = 0;
|
2026-05-06 23:18:42 -04:00
|
|
|
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_RIGHT);
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("new target actor state: %b", obj->state);
|
2025-08-08 22:39:48 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_up_on(akgl_Actor *obj, SDL_Event *event)
|
2025-08-08 22:39:48 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("event %d (button %d / key %d) moves actor up", event->type, event->gbutton.which, event->key.key);
|
2026-05-06 23:18:42 -04:00
|
|
|
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
|
|
|
|
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_FACE_UP | AKGL_ACTOR_STATE_MOVING_UP));
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("new target actor state: %b", obj->state);
|
2025-08-08 22:39:48 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_up_off(akgl_Actor *obj, SDL_Event *event)
|
2025-08-08 22:39:48 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("event %d (button %d / key %d) stops moving actor up", event->type, event->gbutton.which, event->key.key);
|
2026-05-26 10:36:31 -04:00
|
|
|
obj->vy = 0;
|
2026-05-06 23:18:42 -04:00
|
|
|
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_UP);
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("new target actor state: %b", obj->state);
|
2025-08-08 22:39:48 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_down_on(akgl_Actor *obj, SDL_Event *event)
|
2025-08-08 22:39:48 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("event %d (button %d / key %d) moves actor down", event->type, event->gbutton.which, event->key.key);
|
2026-05-06 23:18:42 -04:00
|
|
|
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
|
|
|
|
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_MOVING_DOWN | AKGL_ACTOR_STATE_FACE_DOWN));
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("new target actor state: %b", obj->state);
|
2025-08-08 22:39:48 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_down_off(akgl_Actor *obj, SDL_Event *event)
|
2025-08-08 22:39:48 -04:00
|
|
|
{
|
|
|
|
|
PREPARE_ERROR(errctx);
|
2026-05-03 23:57:55 -04:00
|
|
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
|
|
|
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("event %d (button %d / key %d) stops moving actor down", event->type, event->gbutton.which, event->key.key);
|
2026-05-26 10:36:31 -04:00
|
|
|
obj->vy = 0;
|
2026-05-06 23:18:42 -04:00
|
|
|
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_DOWN);
|
2025-08-09 09:28:28 -04:00
|
|
|
//SDL_Log("new target actor state: %b", obj->state);
|
2025-08-08 22:39:48 -04:00
|
|
|
SUCCEED_RETURN(errctx);
|
|
|
|
|
}
|