eco2d/code/modules/source/system_onfoot.c

29 lines
934 B
C
Raw Normal View History

2021-08-10 11:19:45 +00:00
void MoveWalk(ecs_iter_t *it) {
Position *p = ecs_column(it, Position, 1);
Velocity *v = ecs_column(it, Velocity, 2);
for (int i = 0; i < it->count; i++) {
world_block_lookup lookup = world_block_from_realpos(p[i].x, p[i].y);
float drag = blocks_get_drag(lookup.block_id);
v[i].x = zpl_lerp(v[i].x, 0.0f, PHY_WALK_DRAG*drag);
v[i].y = zpl_lerp(v[i].y, 0.0f, PHY_WALK_DRAG*drag);
}
}
#define PLR_MOVE_SPEED 50.0
#define PLR_MOVE_SPEED_MULT 4.0
void MovementImpulse(ecs_iter_t *it) {
Input *in = ecs_column(it, Input, 1);
Velocity *v = ecs_column(it, Velocity, 2);
for (int i = 0; i < it->count; i++) {
double speed = PLR_MOVE_SPEED * (in[i].sprint ? PLR_MOVE_SPEED_MULT : 1.0);
if (zpl_abs(v[i].x) < speed && in[i].x)
v[i].x = in[i].x*speed;
if (zpl_abs(v[i].y) < speed && in[i].y)
v[i].y = in[i].y*speed;
}
}