1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*
* ============================================================
* 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 384
* #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 384
#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 */
|