8 static Block blockEmpty = { .type = BLOCKTYPE_SPACE,
10 static Block blockWall01 = { .type = BLOCKTYPE_OBSTACLE,
13 static Block* testBlocks[9] = { &blockWall01, &blockWall01, &blockWall01,
14 &blockEmpty, &blockEmpty, &blockEmpty,
15 &blockWall01, &blockEmpty, &blockWall01 };
17 BlockGrid levelGrid = { .width = 3,
19 .blocks = testBlocks };
21 #define DEFAULT_PLAYER_SPAWN_POS { -BLOCKGRID_CELL_SIZE, 0.0f, -BLOCKGRID_CELL_SIZE }
22 Vector3D playerSpawnPos = DEFAULT_PLAYER_SPAWN_POS;
27 blockWall01.asset3D = importAsset("assets/wall01.3ds");
29 buildLevelFromImage(readTga("assets/level01.tga"));
32 void buildLevelFromImage(TgaImage* image) {
34 logError("Null image received, cannot build level");
38 if (image->header.imageBpp != 32) {
39 logError("Invalid level image format (%d bpp)", image->header.imageBpp);
43 BlockGrid newGrid = { .width = image->header.imageWidth,
44 .depth = image->header.imageHeight,
45 .blocks = malloc(image->header.imageWidth
46 * image->header.imageHeight
48 playerSpawnPos = (Vector3D) DEFAULT_PLAYER_SPAWN_POS;
50 for (int row = 0; row < newGrid.depth; ++row) {
51 for (int x = 0; x < newGrid.width; ++x) {
52 // Flip the image vertically due to (0, 0) being bottom left
53 int z = newGrid.depth - row - 1;
55 uint32_t pixelColorARGB = ((uint32_t*) image->bytes)[(row * newGrid.width) + x];
57 switch (pixelColorARGB) {
63 playerSpawnPos = (Vector3D) { x * BLOCKGRID_CELL_SIZE, 0.0f, z * BLOCKGRID_CELL_SIZE };
69 setBlockInGrid(newGrid, x, z, block);