From f5afccb93da63988655817cf49741f9c0955f1a5 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 27 Mar 2021 17:17:53 -0400 Subject: map: Add functions to query tile collisions --- diff --git a/src/map.c b/src/map.c index add4c3e..53dadaf 100644 --- a/src/map.c +++ b/src/map.c @@ -988,3 +988,21 @@ struct db_ball *db_map_get_balls(struct db_map *map) { return map->ball_head; } + +int +db_map_tile_player_collides(struct db_map *map, int x, int y) +{ + int i; + + i = y * map->w + x; + return (map->p_col[i / 8] & (1 << (i % 8))) != 0; +} + +int +db_map_tile_ball_collides(struct db_map *map, int x, int y) +{ + int i; + + i = y * map->w + x; + return (map->b_col[i / 8] & (1 << (i % 8))) != 0; +} diff --git a/src/map.h b/src/map.h index bfd544d..a2cd112 100644 --- a/src/map.h +++ b/src/map.h @@ -34,5 +34,9 @@ void db_map_get_player(struct db_map *map, int *x, int *y, int *r, int *gid); void db_map_get_target(struct db_map *map, int *x, int *y, int *r, int *gid); struct db_ball *db_map_get_balls(struct db_map *map) __attribute__((__pure__)); +int db_map_tile_player_collides(struct db_map *map, int x, int y) + __attribute__((__pure__)); +int db_map_tile_ball_collides(struct db_map *map, int x, int y) + __attribute__((__pure__)); #endif /* DB_MAP_H_ */ -- cgit v0.9.1