diff options
Diffstat (limited to '')
| -rw-r--r-- | platformer/src/world.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/platformer/src/world.c b/platformer/src/world.c index 7bbde8e..c999f41 100644 --- a/platformer/src/world.c +++ b/platformer/src/world.c @@ -29,6 +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 + * 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()), * world_half_extent. * @@ -54,6 +57,8 @@ static Box s_boxes[LEVEL_MAX_BOXES]; /* where each box is now */ static Vec3 s_moved[LEVEL_MAX_BOXES]; /* how far each box moved in the last world_update */ static int s_box_count; static float s_time; /* s since world_init */ +static Zone s_zones[LEVEL_MAX_ZONES]; /* non-solid regions, kept apart from the boxes */ +static int s_zone_count; /* Where box i is at the current time. */ static Box box_now(int i) @@ -67,7 +72,8 @@ static Box box_now(int i) void world_init(void) { - s_box_count = level_build(s_level, LEVEL_MAX_BOXES); + s_box_count = level_build(s_level, LEVEL_MAX_BOXES); + s_zone_count = level_build_zones(s_zones, LEVEL_MAX_ZONES); s_time = 0.0f; for (int i = 0; i < s_box_count; i++) { s_boxes[i] = box_now(i); @@ -170,6 +176,29 @@ Vec3 world_spawn_point(void) return level_spawn_point(); } +int world_zone_count(void) +{ + return s_zone_count; +} + +Zone world_zone(int i) +{ + return s_zones[i]; +} + +bool world_in_zone(Vec3 point, ZoneKind kind) +{ + for (int i = 0; i < s_zone_count; i++) { + Box b = s_zones[i].bounds; + if (s_zones[i].kind == kind && + point.x >= b.min.x && point.x <= b.max.x && + point.y >= b.min.y && point.y <= b.max.y && + point.z >= b.min.z && point.z <= b.max.z) + return true; + } + return false; +} + float world_half_extent(void) { return WORLD_HALF_EXTENT; |
