diff --git a/src/dusk/rpg/entity/anim/entityanim.c b/src/dusk/rpg/entity/anim/entityanim.c index 1d472662..b22ceaa5 100644 --- a/src/dusk/rpg/entity/anim/entityanim.c +++ b/src/dusk/rpg/entity/anim/entityanim.c @@ -6,6 +6,8 @@ */ #include "rpg/entity/entity.h" +#include "rpg/overworld/map.h" +#include "rpg/overworld/tile.h" #include "time/time.h" const entityanimcallback_t ENTITY_ANIM_CALLBACKS[ENTITY_ANIM_COUNT] = { @@ -15,6 +17,10 @@ const entityanimcallback_t ENTITY_ANIM_CALLBACKS[ENTITY_ANIM_COUNT] = { [ENTITY_ANIM_RUN] = { entityAnimRunUpdate }, }; +float_t entityAnimTileZOffset(const worldpos_t pos) { + return tileIsRamp(mapGetTile(pos)) ? 0.5f : 0.0f; +} + void entityAnimUpdate(entity_t *entity) { if(entity->animation != ENTITY_ANIM_IDLE) { entity->animTime -= TIME.delta; diff --git a/src/dusk/rpg/entity/anim/entityanim.h b/src/dusk/rpg/entity/anim/entityanim.h index 548c289f..ff4cde20 100644 --- a/src/dusk/rpg/entity/anim/entityanim.h +++ b/src/dusk/rpg/entity/anim/entityanim.h @@ -35,3 +35,12 @@ extern const entityanimcallback_t ENTITY_ANIM_CALLBACKS[ENTITY_ANIM_COUNT]; * @param entity Pointer to the entity to update. */ void entityAnimUpdate(entity_t *entity); + +/** + * Returns 0.5 if the tile at pos is a ramp, 0.0 otherwise. + * Used to lift entity render position to mid-ramp height. + * + * @param pos World position to sample. + * @returns float_t The Z offset to apply. + */ +float_t entityAnimTileZOffset(const worldpos_t pos); diff --git a/src/dusk/rpg/entity/anim/entityanimidle.c b/src/dusk/rpg/entity/anim/entityanimidle.c index 53836258..af4b493c 100644 --- a/src/dusk/rpg/entity/anim/entityanimidle.c +++ b/src/dusk/rpg/entity/anim/entityanimidle.c @@ -6,9 +6,11 @@ */ #include "rpg/entity/entity.h" +#include "entityanim.h" void entityAnimIdleUpdate(entity_t *entity) { entity->renderPosition[0] = (float_t)entity->position.x; entity->renderPosition[1] = (float_t)entity->position.y; - entity->renderPosition[2] = (float_t)entity->position.z; + entity->renderPosition[2] = (float_t)entity->position.z + + entityAnimTileZOffset(entity->position); } diff --git a/src/dusk/rpg/entity/anim/entityanimrun.c b/src/dusk/rpg/entity/anim/entityanimrun.c index f3ce19d8..abab5e6d 100644 --- a/src/dusk/rpg/entity/anim/entityanimrun.c +++ b/src/dusk/rpg/entity/anim/entityanimrun.c @@ -6,16 +6,19 @@ */ #include "rpg/entity/entity.h" +#include "entityanim.h" void entityAnimRunUpdate(entity_t *entity) { float_t t = 1.0f - (entity->animTime / ENTITY_ANIM_RUN_DURATION); + float_t zFrom = (float_t)entity->lastPosition.z + + entityAnimTileZOffset(entity->lastPosition); + float_t zTo = (float_t)entity->position.z + + entityAnimTileZOffset(entity->position); entity->renderPosition[0] = (float_t)entity->lastPosition.x + t * ( (float_t)entity->position.x - (float_t)entity->lastPosition.x ); entity->renderPosition[1] = (float_t)entity->lastPosition.y + t * ( (float_t)entity->position.y - (float_t)entity->lastPosition.y ); - entity->renderPosition[2] = (float_t)entity->lastPosition.z + t * ( - (float_t)entity->position.z - (float_t)entity->lastPosition.z - ); + entity->renderPosition[2] = zFrom + t * (zTo - zFrom); } diff --git a/src/dusk/rpg/entity/anim/entityanimturn.c b/src/dusk/rpg/entity/anim/entityanimturn.c index feab189b..358de4c1 100644 --- a/src/dusk/rpg/entity/anim/entityanimturn.c +++ b/src/dusk/rpg/entity/anim/entityanimturn.c @@ -6,9 +6,11 @@ */ #include "rpg/entity/entity.h" +#include "entityanim.h" void entityAnimTurnUpdate(entity_t *entity) { entity->renderPosition[0] = (float_t)entity->position.x; entity->renderPosition[1] = (float_t)entity->position.y; - entity->renderPosition[2] = (float_t)entity->position.z; + entity->renderPosition[2] = (float_t)entity->position.z + + entityAnimTileZOffset(entity->position); } diff --git a/src/dusk/rpg/entity/anim/entityanimwalk.c b/src/dusk/rpg/entity/anim/entityanimwalk.c index e5af80ff..52c9a488 100644 --- a/src/dusk/rpg/entity/anim/entityanimwalk.c +++ b/src/dusk/rpg/entity/anim/entityanimwalk.c @@ -6,16 +6,19 @@ */ #include "rpg/entity/entity.h" +#include "entityanim.h" void entityAnimWalkUpdate(entity_t *entity) { float_t t = 1.0f - (entity->animTime / ENTITY_ANIM_WALK_DURATION); + float_t zFrom = (float_t)entity->lastPosition.z + + entityAnimTileZOffset(entity->lastPosition); + float_t zTo = (float_t)entity->position.z + + entityAnimTileZOffset(entity->position); entity->renderPosition[0] = (float_t)entity->lastPosition.x + t * ( (float_t)entity->position.x - (float_t)entity->lastPosition.x ); entity->renderPosition[1] = (float_t)entity->lastPosition.y + t * ( (float_t)entity->position.y - (float_t)entity->lastPosition.y ); - entity->renderPosition[2] = (float_t)entity->lastPosition.z + t * ( - (float_t)entity->position.z - (float_t)entity->lastPosition.z - ); + entity->renderPosition[2] = zFrom + t * (zTo - zFrom); } diff --git a/src/dusk/rpg/entity/entity.c b/src/dusk/rpg/entity/entity.c index 8cfdffc9..c806ea10 100644 --- a/src/dusk/rpg/entity/entity.c +++ b/src/dusk/rpg/entity/entity.c @@ -118,14 +118,16 @@ void entityWalk(entity_t *entity, const entitydir_t direction) { // Must be able to walk up. ) ) { - tileNew = TILE_SHAPE_NULL;// Force check for ramp above. + tile_t tileNewSaved = tileNew; + tileNew = TILE_SHAPE_NULL; worldpos_t abovePos = newPos; abovePos.z += 1; tile_t tileAbove = mapGetTile(abovePos); if(tileAbove != TILE_SHAPE_NULL && tileIsWalkable(tileAbove)) { - // We can go up the ramp. raise = true; + } else { + tileNew = tileNewSaved; } } else if(tileNew == TILE_SHAPE_NULL && newPos.z > 0) { // Falling down?