Back to floats.
This commit is contained in:
@@ -51,27 +51,16 @@ void entityUpdate(entity_t *entity) {
|
||||
playerMovement(entity);
|
||||
}
|
||||
|
||||
// Velocity
|
||||
for(uint8_t i = 0; i < WORLD_DIMENSIONS; i++) {
|
||||
if(entity->velocity[i] == 0) continue;
|
||||
// Add velcoity
|
||||
glm_vec3_muladds(entity->velocity, TIME.delta, entity->position);
|
||||
|
||||
worldPosAddSubtile(&entity->position[i], entity->velocity[i]);
|
||||
// Apply friction
|
||||
glm_vec3_muladds(
|
||||
entity->velocity, -ENTITY_FRICTION * TIME.delta, entity->velocity
|
||||
);
|
||||
|
||||
// Friction
|
||||
worldsubtile_t v = entity->velocity[i];
|
||||
|
||||
if (v > 0) {
|
||||
v -= ENTITY_FRICTION;
|
||||
if (v < ENTITY_MIN_VELOCITY) v = 0;
|
||||
} else if (v < 0) {
|
||||
v += ENTITY_FRICTION;
|
||||
if (v > -ENTITY_MIN_VELOCITY) v = 0;
|
||||
}
|
||||
|
||||
if ((v > 0 && v < ENTITY_FRICTION) || (v < 0 && v > -ENTITY_FRICTION)) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
entity->velocity[i] = v;
|
||||
// Clamp small velocities to zero
|
||||
if(glm_vec3_norm(entity->velocity) < ENTITY_MIN_VELOCITY) {
|
||||
glm_vec3_zero(entity->velocity);
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,9 @@
|
||||
#include "rpg/entity/player.h"
|
||||
#include "npc.h"
|
||||
#include "physics/physics.h"
|
||||
#include "rpg/world/worldunit.h"
|
||||
|
||||
#define ENTITY_FRICTION 2
|
||||
#define ENTITY_MIN_VELOCITY 1
|
||||
#define ENTITY_FRICTION 16.0f
|
||||
#define ENTITY_MIN_VELOCITY 0.1f
|
||||
#define ENTITY_COUNT 256
|
||||
|
||||
typedef struct map_s map_t;
|
||||
@@ -30,8 +29,8 @@ typedef struct entity_s {
|
||||
uint8_t id;
|
||||
entitytype_t type;
|
||||
direction_t direction;
|
||||
worldpos_t position[WORLD_DIMENSIONS];
|
||||
worldsubtile_t velocity[WORLD_DIMENSIONS];
|
||||
vec3 position;
|
||||
vec3 velocity;
|
||||
|
||||
union {
|
||||
player_t player;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "display/tileset/tileset_entities.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");
|
||||
@@ -27,8 +28,8 @@ void playerMovement(entity_t *entity) {
|
||||
if(dir[0] == 0 && dir[1] == 0) return;
|
||||
glm_vec2_normalize(dir);
|
||||
|
||||
entity->velocity[0] += (worldsubtile_t)((float_t)PLAYER_SPEED * dir[0]);
|
||||
entity->velocity[1] += (worldsubtile_t)((float_t)PLAYER_SPEED * dir[1]);
|
||||
entity->velocity[0] += PLAYER_SPEED * dir[0] * TIME.fixedDelta;
|
||||
entity->velocity[1] += PLAYER_SPEED * dir[1] * TIME.fixedDelta;
|
||||
|
||||
// Update direction.
|
||||
if(dir[0] > 0) {
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
#define PLAYER_SPEED 4
|
||||
#define PLAYER_SPEED 32.0f
|
||||
#define PLAYER_SPEED_RUNNING 64.0f
|
||||
#define PLAYER_INTERACTION_RANGE 1.0f
|
||||
#define PLAYER_INTERACTION_SIZE 0.5f
|
||||
|
||||
|
||||
Reference in New Issue
Block a user