]> git.lizzy.rs Git - shadowclad.git/blob - src/game/level.h
Add copyright and license notices in source code
[shadowclad.git] / src / game / level.h
1 /**
2  * Copyright 2018-2020 Iwo 'Outfrost' Bujkiewicz
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8
9 #ifndef LEVEL_H_
10 #define LEVEL_H_
11
12 #include <stdint.h>
13
14 #include "engine/asset.h"
15
16 enum BlockType {
17         BLOCKTYPE_SPACE = 0,
18         BLOCKTYPE_OBSTACLE_X = 1 << 0,
19         BLOCKTYPE_OBSTACLE_Z = 1 << 1
20 };
21
22 enum Obstacle {
23         OBSTACLE_NONE = 0,
24         OBSTACLE_XP = 1 << 0,
25         OBSTACLE_XN = 1 << 1,
26         OBSTACLE_ZP = 1 << 2,
27         OBSTACLE_ZN = 1 << 3,
28         OBSTACLE_XP_ZP = 1 << 4,
29         OBSTACLE_XP_ZN = 1 << 5,
30         OBSTACLE_XN_ZP = 1 << 6,
31         OBSTACLE_XN_ZN = 1 << 7
32 };
33
34 typedef enum BlockType BlockType;
35 typedef enum Obstacle Obstacle;
36 typedef struct Block Block;
37 typedef struct BlockGrid BlockGrid;
38 typedef struct GridLocation GridLocation;
39
40 struct Block {
41         BlockType type;
42         const Solid* solid;
43 };
44
45 struct BlockGrid {
46         size_t width;
47         size_t depth;
48         Block** blocks;
49 };
50
51 struct GridLocation {
52         size_t x;
53         size_t z;
54 };
55
56 static const float BLOCKGRID_CELL_SIZE = 2.5f;
57
58 extern BlockGrid levelGrid;
59
60 void initLevel();
61 void startLevel();
62 GridLocation gridLocationFromPosition(Vector pos);
63 Obstacle getObstacles(GridLocation loc);
64
65 static inline Block* getBlockFromGrid(BlockGrid grid, size_t x, size_t z) {
66         return grid.blocks[(z * grid.width) + x];
67 }
68
69 static inline void setBlockInGrid(BlockGrid grid, size_t x, size_t z, Block* block) {
70         grid.blocks[(z * grid.width) + x] = block;
71 }
72
73 static inline float cellBoundaryCoord(size_t cellIndex) {
74         return cellIndex * BLOCKGRID_CELL_SIZE;
75 }
76
77 #endif // LEVEL_H_