Add walk animation
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
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()
|
||||
@@ -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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user