]> git.lizzy.rs Git - shadowclad.git/blobdiff - src/game/level.h
But we shouldn't yet, because we're using extensions without asking for them
[shadowclad.git] / src / game / level.h
index 4795d5de7d7819544c391ecf33604d85cec6965e..cca8a8e469202e0a54e8c52a8486c4ac80e7f062 100644 (file)
@@ -4,33 +4,55 @@
 #include <stdint.h>
 
 #include "engine/asset.h"
-#include "engine/tga.h"
 
-typedef enum {
-       BLOCKTYPE_SPACE,
-       BLOCKTYPE_OBSTACLE_X,
-       BLOCKTYPE_OBSTACLE_Z,
-       BLOCKTYPE_OBSTACLE
-} BlockType;
+enum BlockType {
+       BLOCKTYPE_SPACE = 0,
+       BLOCKTYPE_OBSTACLE_X = 1 << 0,
+       BLOCKTYPE_OBSTACLE_Z = 1 << 1
+};
 
-typedef struct {
-       const BlockType type;
+enum Obstacle {
+       OBSTACLE_NONE = 0,
+       OBSTACLE_XP = 1 << 0,
+       OBSTACLE_XN = 1 << 1,
+       OBSTACLE_ZP = 1 << 2,
+       OBSTACLE_ZN = 1 << 3,
+       OBSTACLE_XP_ZP = 1 << 4,
+       OBSTACLE_XP_ZN = 1 << 5,
+       OBSTACLE_XN_ZP = 1 << 6,
+       OBSTACLE_XN_ZN = 1 << 7
+};
+
+typedef enum BlockType BlockType;
+typedef enum Obstacle Obstacle;
+typedef struct Block Block;
+typedef struct BlockGrid BlockGrid;
+typedef struct GridLocation GridLocation;
+
+struct Block {
+       BlockType type;
        const Solid* solid;
-} Block;
+};
 
-typedef struct {
+struct BlockGrid {
        size_t width;
        size_t depth;
        Block** blocks;
-} BlockGrid;
+};
+
+struct GridLocation {
+       size_t x;
+       size_t z;
+};
 
-#define BLOCKGRID_CELL_SIZE 2.5f
+static const float BLOCKGRID_CELL_SIZE = 2.5f;
 
-BlockGrid levelGrid;
+extern BlockGrid levelGrid;
 
 void initLevel();
 void startLevel();
-void buildLevelFromImage(TgaImage* image);
+GridLocation gridLocationFromPosition(Vector pos);
+Obstacle getObstacles(GridLocation loc);
 
 static inline Block* getBlockFromGrid(BlockGrid grid, size_t x, size_t z) {
        return grid.blocks[(z * grid.width) + x];
@@ -40,4 +62,8 @@ static inline void setBlockInGrid(BlockGrid grid, size_t x, size_t z, Block* blo
        grid.blocks[(z * grid.width) + x] = block;
 }
 
-#endif
+static inline float cellBoundaryCoord(size_t cellIndex) {
+       return cellIndex * BLOCKGRID_CELL_SIZE;
+}
+
+#endif // LEVEL_H_