/** * Copyright (c) 2025 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "entity.h" #include "assert/assert.h" #include "rpg/rpgcamera.h" #include "util/memory.h" #include "time/time.h" void playerInit(entity_t *entity) { assertNotNull(entity, "Entity pointer cannot be NULL"); } void playerInput(entity_t *entity) { assertNotNull(entity, "Entity pointer cannot be NULL"); // Turn const playerinputdirmap_t *dirMap = PLAYER_INPUT_DIR_MAP; do { if(!inputIsDown(dirMap->action)) continue; if(entity->direction == dirMap->direction) continue; return entityTurn(entity, dirMap->direction); } while((++dirMap)->action != 0xFF); // Walk dirMap = PLAYER_INPUT_DIR_MAP; do { if(!inputIsDown(dirMap->action)) continue; if(entity->direction != dirMap->direction) continue; return entityWalk(entity, dirMap->direction); } while((++dirMap)->action != 0xFF); // Interaction if(inputPressed(INPUT_ACTION_ACCEPT)) { worldunit_t x, y, z; { worldunits_t relX, relY; entityDirGetRelative(entity->direction, &relX, &relY); x = entity->position.x + relX; y = entity->position.y + relY; z = entity->position.z; } entity_t *interact = entityGetAt((worldpos_t){ x, y, z }); if(interact != NULL && ENTITY_CALLBACKS[interact->type].interact != NULL) { if(ENTITY_CALLBACKS[interact->type].interact(entity, interact)) return; } } }