33 lines
853 B
C
33 lines
853 B
C
#include "entity.h"
|
|
#include "cells.h"
|
|
#include "vector.h"
|
|
#include "world.h"
|
|
|
|
#include "stdio.h"
|
|
int EntityMove(entity* e, vec2* pos) {
|
|
world* world = e->world;
|
|
vec2 p = *pos;
|
|
if(pos->x < 0) {
|
|
p.x = (world->size_x + (pos->x- 1)) ;
|
|
printf("x less then 0 setting p.x to %d\n", p.x);
|
|
pos->x = p.x;
|
|
}
|
|
if(pos->y < 0) {
|
|
p.y = (world->size_y + (pos->y - 1)) ;
|
|
printf("y less then 0 setting p.y to %d\n", p.y);
|
|
pos->y = p.y;
|
|
}
|
|
if(world->wells[at(p.x,p.y, world)].cell->flags & (CELL_FLAG_BLOCKING)){
|
|
return 1;
|
|
}
|
|
if(world->wells[at(p.x,p.y, world)].entityIds[0] != NULL){
|
|
return 2;
|
|
}
|
|
|
|
world->wells[at(e->position.x,e->position.y, world)].entityIds[0] = 0;
|
|
world->wells[at(p.x,p.y, world)].entityIds[0] = e;
|
|
e->position = p;
|
|
|
|
return 0;
|
|
}
|