]> git.lizzy.rs Git - shadowclad.git/blob - src/game/level.h
3ce8241f8a85b33e060ffa63182bd716c631e589
[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,
10         BLOCKTYPE_OBSTACLE_X,
11         BLOCKTYPE_OBSTACLE_Z,
12         BLOCKTYPE_OBSTACLE
13 };
14
15 typedef enum BlockType BlockType;
16 typedef struct Block Block;
17 typedef struct BlockGrid BlockGrid;
18 typedef struct GridLocation GridLocation;
19
20 struct Block {
21         BlockType type;
22         const Solid* solid;
23 };
24
25 struct BlockGrid {
26         size_t width;
27         size_t depth;
28         Block** blocks;
29 };
30
31 struct GridLocation {
32         size_t x;
33         size_t z;
34 };
35
36 extern BlockGrid levelGrid;
37
38 void initLevel();
39 void startLevel();
40 GridLocation gridLocationFromTransform(Transform transform);
41
42 static inline Block* getBlockFromGrid(BlockGrid grid, size_t x, size_t z) {
43         return grid.blocks[(z * grid.width) + x];
44 }
45
46 static inline void setBlockInGrid(BlockGrid grid, size_t x, size_t z, Block* block) {
47         grid.blocks[(z * grid.width) + x] = block;
48 }
49
50 #endif // LEVEL_H_