movement.c (981B)
1 2 #include <stdlib.h> 3 #include <stdbool.h> 4 #include <stdio.h> 5 #include "stb_ds.h" 6 #include "actions/movement.h" 7 #include "core/ecs/entity.h" 8 #include "core/world.h" 9 10 bool Action_Movement(Entity *e, World *w) { 11 //printf("unit %d try movement\n", e->id); 12 MovementTarget mt = Entity_Find_Component(e, COMPONENT_MOVEMENT_TARGET)->movement_target; 13 Component *p = Entity_Find_Component(e, COMPONENT_POSITION); 14 // melee action already should've taken care of any neighbor enemies so we don't check for that 15 if (mt.x!=p->position.x||mt.y!=p->position.y) { 16 Position old = p->position; 17 // @todo dumb 18 if (mt.x>p->position.x) p->position.x++; 19 else if (mt.x<p->position.x) p->position.x--; 20 if (mt.y>p->position.y) p->position.y++; 21 else if (mt.y<p->position.y) p->position.y--; 22 printf("[%d] UNIT_MOVED unitId=%d x=%d y=%d\n", w->turn, e->id, p->position.x, p->position.y); 23 return true; 24 } 25 return false; 26 }