eco2d/code/modules/source/system_onfoot.c

24 lines
831 B
C
Raw Normal View History

#include "entity.h"
2021-11-03 18:04:34 +00:00
#define PLR_MOVE_SPEED 800.0f
#define PLR_MOVE_SPEED_MULT 1.5f
2021-08-10 11:19:45 +00:00
void MovementImpulse(ecs_iter_t *it) {
2022-07-31 14:34:47 +00:00
Input *in = ecs_field(it, Input, 1);
Velocity *v = ecs_field(it, Velocity, 2);
Position *p = ecs_field(it, Position, 3);
2021-08-10 11:19:45 +00:00
for (int i = 0; i < it->count; i++) {
2021-08-11 10:22:46 +00:00
world_block_lookup lookup = world_block_from_realpos(p[i].x, p[i].y);
2021-11-03 18:04:34 +00:00
float drag = zpl_clamp(blocks_get_drag(lookup.bid), 0.0f, 1.0f);
float speed = PLR_MOVE_SPEED * (in[i].sprint ? PLR_MOVE_SPEED_MULT : 1.0f);
v[i].x += in[i].x*speed*drag*safe_dt(it);
v[i].y -= in[i].y*speed*drag*safe_dt(it);
if ( zpl_abs(v[i].x) > ENTITY_ACTION_VELOCITY_THRESHOLD
|| zpl_abs(v[i].y) > ENTITY_ACTION_VELOCITY_THRESHOLD) {
entity_wake(it->entities[i]);
}
2021-08-10 11:19:45 +00:00
}
}