From 323bd67577594355eade9a15f97a63b13527fcae Mon Sep 17 00:00:00 2001 From: fischerth80683 Date: Mon, 1 Dec 2025 13:20:18 +0100 Subject: [PATCH] added dynamic cube count --- src/main.cpp | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c421f4e..7be4707 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,9 @@ int main() // gespielte Zeit int playTime = 0; + // anzahl an wuerfeln -> immer gerade anzahl und groeßer null + int numberOfCubes = 12; + // Zufall initialisieren srand(time(NULL)); @@ -25,7 +28,8 @@ int main() SetTargetFPS(60); Camera3D camera{}; - camera.position = {6.0f, 6.0f, 6.0f}; + //camera.position = {6.0f, 6.0f, 6.0f}; // changed camera position to show all cubes if number very high + camera.position = {12.0f, 9.0f, 12.0f}; camera.target = {0.0f, 0.0f, 0.0f}; camera.up = {0.0f, 1.0f, 0.0f}; camera.fovy = 45.0f; @@ -34,15 +38,39 @@ int main() // Nur 3 Farben für 3 Paare Color colors[] = { RED, GREEN, BLUE }; - // 6 Karten-Positionen im 3x2 Raster - std::vector positions = {{-2, 0, -2}, {0, 0, -2}, {2, 0, -2},{-2, 0, 0}, {0, 0, 0}, {2, 0, 0}}; + //==================================================================================== (alter comment) + // 6 Karten-Positionen im 3x2 Raster + //std::vector positions = {{-2, 0, -2}, {0, 0, -2}, {2, 0, -2}, + // {-2, 0, 0}, {0, 0, 0}, {2, 0, 0}}; + //==================================================================================== + + // Positionen bestimmen für dynamisches NumberOfCubes + std::vector positions; //noch leer, wird später befüllt in der schleife + int columns = ceil(sqrt(numberOfCubes)); + int rows = ceil(numberOfCubes / (float)columns); + float posi_x = 0; + float posi_z = 0; + + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < columns; j++) + { + positions.push_back({posi_x, 0, posi_z}); + posi_z += 2; + } + posi_z = 0; + posi_x += 2;; + } + + // Farben doppelt in einen Pool legen und mischen std::vector colorPool; - for (int i = 0; i < 3; i++) + int numberOfPairs = numberOfCubes / 2; + for (int i = 0; i < numberOfPairs; i++) { - colorPool.push_back(colors[i]); - colorPool.push_back(colors[i]); + colorPool.push_back(colors[i % 3]); // i % 3, weil nur 3 Farben zur Zeit im Pool sein können -> keine out of range exception + colorPool.push_back(colors[i % 3]); } // Fisher-Yates Shuffle mit rand() @@ -54,7 +82,7 @@ int main() // Karten/Würfel erstellen std::vector cubes; - for (int i = 0; i < 6; i++) + for (int i = 0; i < numberOfCubes; i++) cubes.emplace_back(positions[i], colorPool[i]); gamecube* first = nullptr;