Ramps fixed
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
|
#include "rpg/overworld/map.h"
|
||||||
|
#include "rpg/overworld/tile.h"
|
||||||
#include "time/time.h"
|
#include "time/time.h"
|
||||||
|
|
||||||
const entityanimcallback_t ENTITY_ANIM_CALLBACKS[ENTITY_ANIM_COUNT] = {
|
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 },
|
[ENTITY_ANIM_RUN] = { entityAnimRunUpdate },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
float_t entityAnimTileZOffset(const worldpos_t pos) {
|
||||||
|
return tileIsRamp(mapGetTile(pos)) ? 0.5f : 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
void entityAnimUpdate(entity_t *entity) {
|
void entityAnimUpdate(entity_t *entity) {
|
||||||
if(entity->animation != ENTITY_ANIM_IDLE) {
|
if(entity->animation != ENTITY_ANIM_IDLE) {
|
||||||
entity->animTime -= TIME.delta;
|
entity->animTime -= TIME.delta;
|
||||||
|
|||||||
@@ -35,3 +35,12 @@ extern const entityanimcallback_t ENTITY_ANIM_CALLBACKS[ENTITY_ANIM_COUNT];
|
|||||||
* @param entity Pointer to the entity to update.
|
* @param entity Pointer to the entity to update.
|
||||||
*/
|
*/
|
||||||
void entityAnimUpdate(entity_t *entity);
|
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);
|
||||||
|
|||||||
@@ -6,9 +6,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
|
#include "entityanim.h"
|
||||||
|
|
||||||
void entityAnimIdleUpdate(entity_t *entity) {
|
void entityAnimIdleUpdate(entity_t *entity) {
|
||||||
entity->renderPosition[0] = (float_t)entity->position.x;
|
entity->renderPosition[0] = (float_t)entity->position.x;
|
||||||
entity->renderPosition[1] = (float_t)entity->position.y;
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
|
#include "entityanim.h"
|
||||||
|
|
||||||
void entityAnimRunUpdate(entity_t *entity) {
|
void entityAnimRunUpdate(entity_t *entity) {
|
||||||
float_t t = 1.0f - (entity->animTime / ENTITY_ANIM_RUN_DURATION);
|
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 * (
|
entity->renderPosition[0] = (float_t)entity->lastPosition.x + t * (
|
||||||
(float_t)entity->position.x - (float_t)entity->lastPosition.x
|
(float_t)entity->position.x - (float_t)entity->lastPosition.x
|
||||||
);
|
);
|
||||||
entity->renderPosition[1] = (float_t)entity->lastPosition.y + t * (
|
entity->renderPosition[1] = (float_t)entity->lastPosition.y + t * (
|
||||||
(float_t)entity->position.y - (float_t)entity->lastPosition.y
|
(float_t)entity->position.y - (float_t)entity->lastPosition.y
|
||||||
);
|
);
|
||||||
entity->renderPosition[2] = (float_t)entity->lastPosition.z + t * (
|
entity->renderPosition[2] = zFrom + t * (zTo - zFrom);
|
||||||
(float_t)entity->position.z - (float_t)entity->lastPosition.z
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
|
#include "entityanim.h"
|
||||||
|
|
||||||
void entityAnimTurnUpdate(entity_t *entity) {
|
void entityAnimTurnUpdate(entity_t *entity) {
|
||||||
entity->renderPosition[0] = (float_t)entity->position.x;
|
entity->renderPosition[0] = (float_t)entity->position.x;
|
||||||
entity->renderPosition[1] = (float_t)entity->position.y;
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
|
#include "entityanim.h"
|
||||||
|
|
||||||
void entityAnimWalkUpdate(entity_t *entity) {
|
void entityAnimWalkUpdate(entity_t *entity) {
|
||||||
float_t t = 1.0f - (entity->animTime / ENTITY_ANIM_WALK_DURATION);
|
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 * (
|
entity->renderPosition[0] = (float_t)entity->lastPosition.x + t * (
|
||||||
(float_t)entity->position.x - (float_t)entity->lastPosition.x
|
(float_t)entity->position.x - (float_t)entity->lastPosition.x
|
||||||
);
|
);
|
||||||
entity->renderPosition[1] = (float_t)entity->lastPosition.y + t * (
|
entity->renderPosition[1] = (float_t)entity->lastPosition.y + t * (
|
||||||
(float_t)entity->position.y - (float_t)entity->lastPosition.y
|
(float_t)entity->position.y - (float_t)entity->lastPosition.y
|
||||||
);
|
);
|
||||||
entity->renderPosition[2] = (float_t)entity->lastPosition.z + t * (
|
entity->renderPosition[2] = zFrom + t * (zTo - zFrom);
|
||||||
(float_t)entity->position.z - (float_t)entity->lastPosition.z
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,14 +118,16 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
|
|||||||
// Must be able to walk up.
|
// 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;
|
worldpos_t abovePos = newPos;
|
||||||
abovePos.z += 1;
|
abovePos.z += 1;
|
||||||
tile_t tileAbove = mapGetTile(abovePos);
|
tile_t tileAbove = mapGetTile(abovePos);
|
||||||
|
|
||||||
if(tileAbove != TILE_SHAPE_NULL && tileIsWalkable(tileAbove)) {
|
if(tileAbove != TILE_SHAPE_NULL && tileIsWalkable(tileAbove)) {
|
||||||
// We can go up the ramp.
|
|
||||||
raise = true;
|
raise = true;
|
||||||
|
} else {
|
||||||
|
tileNew = tileNewSaved;
|
||||||
}
|
}
|
||||||
} else if(tileNew == TILE_SHAPE_NULL && newPos.z > 0) {
|
} else if(tileNew == TILE_SHAPE_NULL && newPos.z > 0) {
|
||||||
// Falling down?
|
// Falling down?
|
||||||
|
|||||||
Reference in New Issue
Block a user