diff --git a/src/entity/entity.c b/src/entity/entity.c index ceeaa2b..7e8ce0c 100755 --- a/src/entity/entity.c +++ b/src/entity/entity.c @@ -17,6 +17,19 @@ void entityInit(entity_t *entity, const entitytype_t type) { void entityTick(entity_t *entity) { if(entity->type == ENTITY_TYPE_NULL) return; + // Handle animation + switch(entity->animation) { + case ENTITY_ANIM_WALK: + entity->animWalk--; + if(entity->animWalk == 0) { + entity->animation = ENTITY_ANIM_NONE; + } + return; + + default: + break; + } + // Let entities move (if they do) if(entity->type == ENTITY_TYPE_PLAYER) { playerTickInput(entity); @@ -76,6 +89,9 @@ void entityWalk(entity_t *entity, const direction_t direction) { // Move. entity->position.x = newX; entity->position.y = newY; + + entity->animation = ENTITY_ANIM_WALK; + entity->animWalk = ENTITY_ANIM_WALK_DURATION;// TODO: Running vs walking } void entityInteract(entity_t *entity) { diff --git a/src/entity/entity.h b/src/entity/entity.h index eabf3d1..5e3bfdc 100755 --- a/src/entity/entity.h +++ b/src/entity/entity.h @@ -11,6 +11,11 @@ #include "player.h" #include "sign.h" +#define ENTITY_ANIM_NONE 0 +#define ENTITY_ANIM_WALK 1 + +#define ENTITY_ANIM_WALK_DURATION 8 + typedef struct entity_s { struct { // Relative to top-left position of the top-left chunk of the map. @@ -20,6 +25,11 @@ typedef struct entity_s { direction_t direction; entitytype_t type; + uint8_t animation; + union { + uint8_t animWalk; + }; + union { sign_t sign; }; diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt index 40d0bc8..5549d1c 100755 --- a/src/platform/CMakeLists.txt +++ b/src/platform/CMakeLists.txt @@ -3,6 +3,16 @@ # This software is released under the MIT License. # https://opensource.org/licenses/MIT -# add_subdirectory(raylib) -add_subdirectory(term) -add_subdirectory(tty) \ No newline at end of file +if(NOT DEFINED PLATFORM) + set(PLATFORM "raylib" CACHE STRING "Select the platform to build for (options: raylib, term, tty)") +endif() + +if(PLATFORM STREQUAL "tty") + add_subdirectory(term) + add_subdirectory(tty) +elseif(PLATFORM STREQUAL "raylib") + add_subdirectory(raylib) + add_subdirectory(term) +else() + message(FATAL_ERROR "Unknown PLATFORM: ${PLATFORM}.") +endif() \ No newline at end of file diff --git a/src/platform/term/termoverworld.c b/src/platform/term/termoverworld.c index 586d913..43ea56e 100644 --- a/src/platform/term/termoverworld.c +++ b/src/platform/term/termoverworld.c @@ -24,6 +24,12 @@ void termDrawOverworld( // Draw entities termDrawEntity(&GAME.player, chars, colors, w, h); + + entity_t *start = GAME.overworld.map.entities; + while(start != GAME.overworld.map.entities + MAP_ENTITY_COUNT) { + termDrawEntity(start, chars, colors, w, h); + start++; + } } void termDrawEntity( @@ -40,7 +46,26 @@ void termDrawEntity( int32_t index = ent->position.y * w + ent->position.x; if(ent->type == ENTITY_TYPE_PLAYER) { - chars[index] = '@'; + switch(ent->direction) { + case DIRECTION_UP: + chars[index] = '^'; + break; + case DIRECTION_DOWN: + chars[index] = 'v'; + break; + case DIRECTION_LEFT: + chars[index] = '<'; + break; + case DIRECTION_RIGHT: + chars[index] = '>'; + break; + default: + chars[index] = '@'; + break; + } + colors[index] = TERM_COLOR_WHITE; + } else if(ent->type == ENTITY_TYPE_SIGN) { + chars[index] = '!'; colors[index] = TERM_COLOR_YELLOW; } } \ No newline at end of file