Hello everyone this is my code in my main.cpp and I am trying to create an array for the enemies instead of writing 44 of them like this. What would you suggest me to do or how can I create an array of this. I need to create 44 enemies with 3 different colors.
Enemy red_enemy1(
windowWidth / 2 - 16, // x
windowHeight - 400, // y
"images/GalaxianRedAlien.gif");
Enemy red_enemy2(
windowWidth / 2 - 16 + 34, // x
windowHeight - 400,
"images/GalaxianRedAlien.gif");
Enemy red_enemy3(
windowWidth / 2 - 16 + 64, // x
windowHeight - 400,
"images/GalaxianRedAlien.gif");
// create a blue enemy
Enemy blue_enemy1(
windowWidth / 2 - 16, // x
windowHeight - 400 + 32, // y
"images/GalaxianAquaAlien.gif");
Solución del problema
usar std::vector
std::vector<Enemy> enemies;
enemies.emplace_back(
windowWidth / 2 - 16, // x
windowHeight - 400, // y
"images/GalaxianRedAlien.gif");
enemies.emplace_back(
windowWidth / 2 - 16 + 34, // x
windowHeight - 400, // y
"images/GalaxianRedAlien.gif");
etc.
ahora puedes referirte a enemies[0]
...
No hay comentarios:
Publicar un comentario