#include #include #include "collide.h" #include "conf.h" #include "level.h" uint8_t collide_point(Vec point, const Level *level, uint layer_id) { Vec cursor; /* the final position to test */ vec_cpy(&cursor, point); vec_div(&cursor, TILE_SIZE); /* get the expected tile ID */ if (point.x < 0 || point.y < 0 || cursor.x >= level->width || cursor.y >= level->height) { return 0; /* the point is out of bounds */ } else { return level->layers[layer_id][cursor.x + cursor.y * level->width]; } } bool player_collide(Player *player, Vec position, const Level *level, uint layer_id) { Vec pos; vec_cpy(&pos, position); if (collide_point(pos, level, layer_id)) { return true; } pos.x += player->hbox.x; if (collide_point(pos, level, layer_id)) { return true; } pos.y += player->hbox.y; if (collide_point(pos, level, layer_id)) { return true; } pos.x -= player->hbox.x; if (collide_point(pos, level, layer_id)) { return true; } return false; }