improve player movement
parent
489b75d9c1
commit
8b3e26667e
|
@ -13,9 +13,9 @@ void MovementImpulse(ecs_iter_t *it) {
|
||||||
|
|
||||||
for (int i = 0; i < it->count; i++) {
|
for (int i = 0; i < it->count; i++) {
|
||||||
double speed = PLR_MOVE_SPEED * (in[i].sprint ? PLR_MOVE_SPEED_MULT : 1.0);
|
double speed = PLR_MOVE_SPEED * (in[i].sprint ? PLR_MOVE_SPEED_MULT : 1.0);
|
||||||
if (zpl_abs(v[i].x) < speed)
|
if (zpl_abs(v[i].x) < speed && in[i].x)
|
||||||
v[i].x = in[i].x*speed;
|
v[i].x = in[i].x*speed;
|
||||||
if (zpl_abs(v[i].y) < speed)
|
if (zpl_abs(v[i].y) < speed && in[i].y)
|
||||||
v[i].y = in[i].y*speed;
|
v[i].y = in[i].y*speed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,13 @@
|
||||||
#include "world/world.h"
|
#include "world/world.h"
|
||||||
#include "zpl.h"
|
#include "zpl.h"
|
||||||
|
|
||||||
#define PHY_WALK_DRAG 0.02
|
#define PHY_WALK_DRAG 0.12
|
||||||
|
|
||||||
void MoveWalk(ecs_iter_t *it) {
|
void MoveWalk(ecs_iter_t *it) {
|
||||||
Position *p = ecs_column(it, Position, 1);
|
Position *p = ecs_column(it, Position, 1);
|
||||||
Velocity *v = ecs_column(it, Velocity, 2);
|
Velocity *v = ecs_column(it, Velocity, 2);
|
||||||
|
|
||||||
for (int i = 0; i < it->count; i++) {
|
for (int i = 0; i < it->count; i++) {
|
||||||
// TODO: handle collisions
|
|
||||||
p[i].x += v[i].x * it->delta_time;
|
p[i].x += v[i].x * it->delta_time;
|
||||||
p[i].y += v[i].y * it->delta_time;
|
p[i].y += v[i].y * it->delta_time;
|
||||||
v[i].x = zpl_lerp(v[i].x, 0.0f, PHY_WALK_DRAG);
|
v[i].x = zpl_lerp(v[i].x, 0.0f, PHY_WALK_DRAG);
|
||||||
|
@ -25,8 +24,8 @@ void HandleCollisions(ecs_iter_t *it) {
|
||||||
// NOTE(zaklaus): world bounds
|
// NOTE(zaklaus): world bounds
|
||||||
{
|
{
|
||||||
double w = (double)world_dim()/2.0;
|
double w = (double)world_dim()/2.0;
|
||||||
p[i].x = zpl_clamp(p[i].x, -w, w);
|
p[i].x = zpl_clamp(p[i].x, -w+1, w-1);
|
||||||
p[i].y = zpl_clamp(p[i].y, -w, w);
|
p[i].y = zpl_clamp(p[i].y, -w+1, w-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue