/* * ============================================================ * FILE: level.h * * PURPOSE: Public interface for "what's in the level": the list of boxes * the test world is made of, and how the moving ones move. * level.c only DECIDES the content; world.c stores it, moves it * each tick and answers geometry questions about it. * * FITS IN: world.c calls level_build() once from world_init(), and * level_motion_offset() every tick for each moving box. level.h * uses the Box type from world.h (types only: level.c never * calls world.c, so there is no cycle). * * INTERFACE: Use these exact names: * * typedef enum MotionKind { * MOTION_NONE, stays put * MOTION_SLIDE, back and forth: offset = a * sin(angle) * MOTION_LOOP round a circle through its start: * offset = a * (cos(angle) - 1) + b * sin(angle) * } MotionKind; * typedef struct BoxMotion { * MotionKind kind; * Vec3 a, b; the motion's axes, meters (see above; b unused by SLIDE) * float period; s for one full cycle * float phase; 0..1, how far into its cycle the box is at time 0 * } BoxMotion; * angle = 2 * PI * (time / period + phase). Both kinds pass through * offset 0 (the box's built position) once or twice every cycle. * * typedef struct LevelBox { Box box; BoxMotion motion; } LevelBox; * box is where the box sits at offset 0. * * #define LEVEL_MAX_BOXES 256 * #define LEVEL_MAX_ZONES 16 * int level_build(LevelBox *out, int capacity); * Fills out[] with every box in the level and returns how many. * The same seeds always build the same level. * int level_build_zones(Zone *out, int capacity); * Fills out[] with the level's zones (non-solid regions such as * locked-pan zones; see world.h) and returns how many. * Vec3 level_motion_offset(BoxMotion m, float time); * How far a moving box is from its built position at `time`. * Vec3 level_spawn_point(void); * Where the player starts; the level keeps it clear. * * Include "world.h" (for Box). * * CONVENTIONS: Include guard: LEVEL_H. * * NOT IN SCOPE: Loading levels from files, triggers, anything but boxes. * * DONE WHEN: world.c can build and animate the whole level through this. * ============================================================ */ #ifndef LEVEL_H #define LEVEL_H #include "world.h" typedef enum MotionKind { MOTION_NONE, /* stays put */ MOTION_SLIDE, /* back and forth: offset = a * sin(angle) */ MOTION_LOOP /* round a circle through its start: offset = a * (cos(angle) - 1) + b * sin(angle) */ } MotionKind; typedef struct BoxMotion { MotionKind kind; Vec3 a, b; /* the motion's axes, meters; b is unused by MOTION_SLIDE */ float period; /* s for one full cycle */ float phase; /* 0..1, how far into its cycle the box is at time 0 */ } BoxMotion; typedef struct LevelBox { Box box; /* where it sits at offset 0 */ BoxMotion motion; } LevelBox; #define LEVEL_MAX_BOXES 256 #define LEVEL_MAX_ZONES 16 int level_build(LevelBox *out, int capacity); int level_build_zones(Zone *out, int capacity); Vec3 level_motion_offset(BoxMotion m, float time); Vec3 level_spawn_point(void); #endif /* LEVEL_H */