added dynamic cube count

This commit is contained in:
Thomas Fischer 2025-12-01 13:20:18 +01:00
parent 3c7ae2a9b3
commit 323bd67577

View File

@ -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 };
//==================================================================================== (alter comment)
// 6 Karten-Positionen im 3x2 Raster
std::vector<Vec3> positions = {{-2, 0, -2}, {0, 0, -2}, {2, 0, -2},{-2, 0, 0}, {0, 0, 0}, {2, 0, 0}};
//std::vector<Vec3> 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<Vec3> 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<Color> 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<gamecube> 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;