summaryrefslogtreecommitdiff
path: root/platformer/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--platformer/src/world.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/platformer/src/world.c b/platformer/src/world.c
index c999f41..4c088aa 100644
--- a/platformer/src/world.c
+++ b/platformer/src/world.c
@@ -29,7 +29,9 @@
* WORLD_NO_CEILING.
* world_find_overlap: the first box that overlaps the body's full volume
* (footprint AND height range).
- * - Zones (level_build_zones()): stored separately from the boxes, so no
+ * - world_object_at(point, radius, hit): the first object (never a zone)
+ * that, grown by `radius` on every side, contains the point.
+ * - Zones (level_build_zones()): stored separately from the objects, so no
* collision query ever sees them. world_in_zone(point, kind): is the point
* inside (edges count) any zone of that kind.
* - world_clamp_to_bounds, world_spawn_point (level_spawn_point()),
@@ -176,6 +178,20 @@ Vec3 world_spawn_point(void)
return level_spawn_point();
}
+bool world_object_at(Vec3 point, float radius, Box *hit)
+{
+ for (int i = 0; i < s_box_count; i++) {
+ Box b = s_boxes[i];
+ if (point.x > b.min.x - radius && point.x < b.max.x + radius &&
+ point.y > b.min.y - radius && point.y < b.max.y + radius &&
+ point.z > b.min.z - radius && point.z < b.max.z + radius) {
+ *hit = b;
+ return true;
+ }
+ }
+ return false;
+}
+
int world_zone_count(void)
{
return s_zone_count;