]> git.lizzy.rs Git - shadowclad.git/blob - src/game/level.h
cca8a8e469202e0a54e8c52a8486c4ac80e7f062
[shadowclad.git] / src / game / level.h
1 #ifndef LEVEL_H_
2 #define LEVEL_H_
3
4 #include <stdint.h>
5
6 #include "engine/asset.h"
7
8 enum BlockType {
9         BLOCKTYPE_SPACE = 0,
10         BLOCKTYPE_OBSTACLE_X = 1 << 0,
11         BLOCKTYPE_OBSTACLE_Z = 1 << 1
12 };
13
14 enum Obstacle {
15         OBSTACLE_NONE = 0,
16         OBSTACLE_XP = 1 << 0,
17         OBSTACLE_XN = 1 << 1,
18         OBSTACLE_ZP = 1 << 2,
19         OBSTACLE_ZN = 1 << 3,
20         OBSTACLE_XP_ZP = 1 << 4,
21         OBSTACLE_XP_ZN = 1 << 5,
22         OBSTACLE_XN_ZP = 1 << 6,
23         OBSTACLE_XN_ZN = 1 << 7
24 };
25
26 typedef enum BlockType BlockType;
27 typedef enum Obstacle Obstacle;
28 typedef struct Block Block;
29 typedef struct BlockGrid BlockGrid;
30 typedef struct GridLocation GridLocation;
31
32 struct Block {
33         BlockType type;
34         const Solid* solid;
35 };
36
37 struct BlockGrid {
38         size_t width;
39         size_t depth;
40         Block** blocks;
41 };
42
43 struct GridLocation {
44         size_t x;
45         size_t z;
46 };
47
48 static const float BLOCKGRID_CELL_SIZE = 2.5f;
49
50 extern BlockGrid levelGrid;
51
52 void initLevel();
53 void startLevel();
54 GridLocation gridLocationFromPosition(Vector pos);
55 Obstacle getObstacles(GridLocation loc);
56
57 static inline Block* getBlockFromGrid(BlockGrid grid, size_t x, size_t z) {
58         return grid.blocks[(z * grid.width) + x];
59 }
60
61 static inline void setBlockInGrid(BlockGrid grid, size_t x, size_t z, Block* block) {
62         grid.blocks[(z * grid.width) + x] = block;
63 }
64
65 static inline float cellBoundaryCoord(size_t cellIndex) {
66         return cellIndex * BLOCKGRID_CELL_SIZE;
67 }
68
69 #endif // LEVEL_H_