summaryrefslogtreecommitdiff
path: root/platformer/src/world.h
diff options
context:
space:
mode:
Diffstat (limited to 'platformer/src/world.h')
-rw-r--r--platformer/src/world.h59
1 files changed, 44 insertions, 15 deletions
diff --git a/platformer/src/world.h b/platformer/src/world.h
index 9da16c1..6cd1ce0 100644
--- a/platformer/src/world.h
+++ b/platformer/src/world.h
@@ -2,34 +2,52 @@
* ============================================================
* FILE: world.h
*
- * PURPOSE: Public interface for "the level": a flat square of ground with
- * a scatter of box-shaped platforms on it. This API is how other
- * modules ask questions about the level's geometry.
+ * PURPOSE: Public interface for "the level" while the game runs: a flat
+ * square of ground with box-shaped platforms and terrain on it
+ * (some of them moving). This API is how other modules ask
+ * questions about the level's geometry.
+ * What's IN the level is decided by level.c (level.h).
*
* FITS IN: physics.c asks what's under the feet, what's above the head,
* and what box a body overlaps. render.c asks for the extent and
* the boxes so it can draw them, and for the floor under the
- * player for the shadow. main.c asks for the spawn point.
+ * player for the shadow. main.c asks for the spawn point and calls
+ * world_update() once per tick to move the moving boxes.
*
* INTERFACE: Use these exact names:
*
+ * typedef enum BoxStyle { how render.c colors a box (nothing else reads it)
+ * BOX_STYLE_PLATFORM, the default: a color from the platform palette
+ * BOX_STYLE_CLIFF, rock: big terrain masses like the cliffs
+ * BOX_STYLE_WATER the river (still solid underfoot)
+ * } BoxStyle;
+ *
* typedef struct Box {
- * Vec3 min, max; axis-aligned corners, meters (min.y = bottom, max.y = top)
+ * Vec3 min, max; axis-aligned corners, meters (min.y = bottom, max.y = top)
+ * bool allows_wall_hang; its sides can be wall-hung (see player.c). FALSE
+ * by default: only boxes a level marks count.
+ * BoxStyle style; how it's drawn; BOX_STYLE_PLATFORM (0) by default
* } Box;
*
* void world_init(void);
- * Builds the level. Platforms are placed "randomly" from
- * WORLD_SEED, so the same seed always gives the same layout.
+ * Builds the level (level_build() in level.c).
+ * void world_update(float dt);
+ * Once per tick, BEFORE the player moves: moves every moving box
+ * along its loop.
+ * Vec3 world_box_moved(int i);
+ * How far box i moved in the last world_update (0 for still ones).
+ * physics.c uses it to carry a body standing on a moving box.
* int world_box_count(void);
- * Box world_box(int i); 0 <= i < world_box_count()
+ * Box world_box(int i); 0 <= i < world_box_count(); where it is now
*
* A "footprint" below is the square [x +- half_width] x [z +- half_width]
* around a body's center. Touching edges don't count as overlapping.
*
- * float world_floor_below(Vec3 feet, float half_width);
+ * float world_floor_below(Vec3 feet, float half_width, int *box);
* The highest surface under the footprint whose top is at or just
* below feet.y (a box top, or the ground at 0). This is what the
- * feet land on, and where the shadow goes.
+ * feet land on, and where the shadow goes. If box isn't NULL, *box
+ * = that box's index, or -1 for the ground.
* float world_ceiling_above(Vec3 head, float half_width);
* The lowest box bottom over the footprint that is at or just above
* head.y, or WORLD_NO_CEILING if there's none.
@@ -40,8 +58,8 @@
* Returns p with x and z clamped to [-WORLD_HALF_EXTENT,
* +WORLD_HALF_EXTENT]. y is untouched.
* Vec3 world_spawn_point(void);
- * Where the player starts / resets to: (0, 0, 0). The area around
- * it is kept clear of platforms.
+ * Where the player starts / resets to (level_spawn_point()). The
+ * area around it is kept clear of platforms.
* float world_half_extent(void);
* Returns WORLD_HALF_EXTENT (so render.c doesn't need config
* knowledge of the world's shape).
@@ -52,7 +70,7 @@
*
* CONVENTIONS: Include guard: WORLD_H.
*
- * NOT IN SCOPE: Level files, slopes, moving platforms, non-box shapes.
+ * NOT IN SCOPE: Level files, slopes, rotating boxes, non-box shapes.
*
* DONE WHEN: physics.c and render.c can be written using only this header.
* ============================================================
@@ -66,14 +84,25 @@
#define WORLD_NO_CEILING 1e9f /* returned when nothing is overhead */
+/* How render.c colors a box. Purely visual: collision ignores it. */
+typedef enum BoxStyle {
+ BOX_STYLE_PLATFORM, /* the default: a color from the platform palette */
+ BOX_STYLE_CLIFF, /* rock: big terrain masses like the cliffs */
+ BOX_STYLE_WATER /* the river (still solid underfoot; there's no swimming) */
+} BoxStyle;
+
typedef struct Box {
- Vec3 min, max; /* axis-aligned corners, meters (min.y = bottom, max.y = top) */
+ Vec3 min, max; /* axis-aligned corners, meters (min.y = bottom, max.y = top) */
+ bool allows_wall_hang; /* its sides can be wall-hung; false unless the level marks it */
+ BoxStyle style; /* how it's drawn; BOX_STYLE_PLATFORM unless the level says otherwise */
} Box;
void world_init(void);
+void world_update(float dt);
+Vec3 world_box_moved(int i);
int world_box_count(void);
Box world_box(int i);
-float world_floor_below(Vec3 feet, float half_width);
+float world_floor_below(Vec3 feet, float half_width, int *box);
float world_ceiling_above(Vec3 head, float half_width);
bool world_find_overlap(Vec3 feet, float half_width, float height, Box *hit);
Vec3 world_clamp_to_bounds(Vec3 p);