X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fgame%2Flevel.c;h=0dd1d6146ee20416bc159faf3a5bfcc26c4d57cf;hb=84cce77638aa2b6a367589fb15b8b705a809cbd5;hp=21275dd797cbd40e8e7a664fed17c5b748398cdf;hpb=1893fe5b901f5ed50039b27f1c97d03d1ff21d28;p=shadowclad.git diff --git a/src/game/level.c b/src/game/level.c index 21275dd..0dd1d61 100644 --- a/src/game/level.c +++ b/src/game/level.c @@ -2,14 +2,15 @@ #include #include "engine/logger.h" +#include "engine/scene.h" #include "level.h" #include "player.h" static Block blockEmpty = { .type = BLOCKTYPE_SPACE, - .asset3D = NULL }; + .solid = NULL }; static Block blockWall01 = { .type = BLOCKTYPE_OBSTACLE, - .asset3D = NULL }; + .solid = NULL }; static Block* testBlocks[9] = { &blockWall01, &blockWall01, &blockWall01, &blockEmpty, &blockEmpty, &blockEmpty, @@ -25,9 +26,24 @@ Vector3D playerSpawnPos = DEFAULT_PLAYER_SPAWN_POS; void initLevel() { - blockWall01.asset3D = importAsset("assets/wall01.3ds"); + blockWall01.solid = importSolid("assets/wall01.3ds"); buildLevelFromImage(readTga("assets/level01.tga")); + + Scene* levelScene = newScene(); + + for (size_t z = 0; z < levelGrid.depth; ++z) { + for (size_t x = 0; x < levelGrid.width; ++x) { + Scene* blockScene = newScene(); + translate(&blockScene->transform, (Vector3D) { .x = x * BLOCKGRID_CELL_SIZE, + .y = 0.0f, + .z = z * BLOCKGRID_CELL_SIZE }); + blockScene->solid = getBlockFromGrid(levelGrid, x, z)->solid; + insertChildScene(levelScene, blockScene); + } + } + + currentScene = levelScene; } void buildLevelFromImage(TgaImage* image) { @@ -48,10 +64,10 @@ void buildLevelFromImage(TgaImage* image) { * sizeof(Block*)) }; playerSpawnPos = (Vector3D) DEFAULT_PLAYER_SPAWN_POS; - for (int row = 0; row < newGrid.depth; ++row) { - for (int x = 0; x < newGrid.width; ++x) { + for (size_t row = 0; row < newGrid.depth; ++row) { + for (size_t x = 0; x < newGrid.width; ++x) { // Flip the image vertically due to (0, 0) being bottom left - int z = newGrid.depth - row - 1; + size_t z = newGrid.depth - row - 1; uint32_t pixelColorARGB = ((uint32_t*) image->bytes)[(row * newGrid.width) + x]; Block* block;