J'ai parlé de gameloop ce qui n'est pas correct, les ennemis sont créés avant la gameloop (après toutes les instanciations et avant le début de la gameloop). De même, je créé mon thread une seule fois.
Voilà le code contenant la boucle de jeu :
void Jeu::start()
{
bool invincible(false);
int invincibleStart;
Timer timer;
//Gestionnaire d'images
image_manager imageManager;
imageManager.addResourceDirectory("images/" );
Projectile_manager projectile_manager(m_app);
//Variables :
const int PANNEL_WIDTH(300), PLAYER_WIDTH(118), PLAYER_HEIGHT(93);
const Input & input = m_app.GetInput();
//Variables player :
IntRect subRect(0, PLAYER_HEIGHT, PLAYER_WIDTH, 0);
double playerXSpeed = 10, playerYSpeed = 10;
const string filepath = "images/player.png";
Vector2f positionPlayer(m_SCREEN_WIDTH/2 -50, m_SCREEN_HEIGHT - 100);
Player player(1, playerXSpeed, playerYSpeed, filepath, positionPlayer, m_app, imageManager, projectile_manager);
//Variables enemy :
Vector2f positionEnemy(50, 50);
//Variable population
Population population(m_app, projectile_manager);
//**********************************************
//CREATION DU THREAD ICI
//**********************************************
Script s1( 1, "test s1", imageManager, player, projectile_manager, population);
s1.Launch();
/*
population.createShip(positionEnemy, player, imageManager);
positionEnemy.x +=100;
population.createShip(positionEnemy, player, imageManager);
positionEnemy.x +=100;
population.createShip(positionEnemy, player, imageManager);
positionEnemy.x +=100;
//population.createFlyingSaucer(positionEnemy, player, imageManager);
positionEnemy.x +=100;
population.createShip(positionEnemy, player, imageManager);
positionEnemy.x +=100;
population.createShip(positionEnemy, player, imageManager);
positionEnemy.x +=100;
//population.createFlyingSaucer(positionEnemy, player, imageManager);
positionEnemy.x +=100;
population.createShip(positionEnemy, player, imageManager);
positionEnemy.x +=100;
//population.createFlyingSaucer(positionEnemy, player, imageManager);*/
//pannel
const string filepathPanel = "images/pannel.png";
Vector2f positionPannel(m_SCREEN_WIDTH-PANNEL_WIDTH, 0);
Pannel pannel(m_app, filepathPanel, positionPannel, player, imageManager);
//Collision
Vector2f windowSize(m_SCREEN_WIDTH-PANNEL_WIDTH, m_SCREEN_HEIGHT);
Collision collision(windowSize, player, population, projectile_manager);
//Background
Background background(m_app, 1, m_SCREEN_WIDTH, m_SCREEN_HEIGHT, imageManager);
//Projectiles
list<Projectile*> projectiles;
while (m_app.IsOpened() )
{
//Boucle avec les évènements
}
player.draw();
population.checkPopulation();
population.manageExplosion();
population.drawPopulation();
pannel.checkPannel();
m_app.Draw(*pannel.getSprite());
m_app.Display();
timer.sleep(1);
}