eco2d/code/modules/source/physics.c

35 lines
967 B
C
Raw Normal View History

2021-05-04 17:41:30 +00:00
#include "modules/physics.h"
2021-05-07 14:43:54 +00:00
#include "world/world.h"
#include "zpl.h"
2021-05-04 17:41:30 +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++) {
// TODO: handle collisions
p[i].x += v[i].x * it->delta_time;
p[i].y += v[i].y * it->delta_time;
2021-05-07 14:43:54 +00:00
librg_entity_chunk_set(world_tracker(), it->entities[i], librg_chunk_from_realpos(world_tracker(), p[i].x, p[i].y, 0));
2021-05-04 17:41:30 +00:00
}
}
void PhysicsImport(ecs_world_t *ecs) {
ECS_MODULE(ecs, Physics);
ecs_set_name_prefix(ecs, "Physics");
2021-05-07 14:43:54 +00:00
2021-05-04 17:41:30 +00:00
ECS_TAG(ecs, Walking);
ECS_TAG(ecs, Flying);
ECS_TYPE(ecs, Movement, Walking, Flying);
2021-05-07 14:43:54 +00:00
ECS_META(ecs, Velocity);
2021-05-04 17:41:30 +00:00
2021-05-07 14:43:54 +00:00
ECS_SYSTEM(ecs, MoveWalk, EcsOnUpdate, general.Position, Velocity);
2021-05-04 17:41:30 +00:00
ECS_SET_TYPE(Movement);
ECS_SET_ENTITY(Walking);
ECS_SET_ENTITY(Flying);
ECS_SET_COMPONENT(Velocity);
ECS_SET_ENTITY(MoveWalk);
}