This commit is contained in:
Thomas 2022-01-09 21:13:38 +01:00
parent f2984fffb8
commit 947665d306
No known key found for this signature in database
GPG Key ID: E538821A6CDFDAD7
5 changed files with 18 additions and 10 deletions

View File

@ -69,6 +69,7 @@ public:
* @return
* @fn
*/
unsigned validColsNumber() const;
unsigned randomValidCol() const;
};

View File

@ -84,7 +84,7 @@ void PixelManager::askPlayerNameMenu(playerID pID, string& name) {
while (window.isOpen()){
startFrame();
drawSprite(menuBackground);
displayText(Position(600,100),"Nom du joueur "+ string(1,pID));
displayText(Position(600,100),"Nom du joueur "+to_string(pID+1));
for (size_t i = 0; i < name.size(); ++i){
displayText(Position(600+30*i,200),string(1,name[i]),(i == currentSelected) ? nsGraphics::KRed : nsGraphics::KWhite);
}

View File

@ -64,6 +64,9 @@ void Game::initGame(){
// we re-construct players objects, we don't have to clear all members and can rely on the construction value (set in .h file)
players.clear();
missiles.clear();
torpedos.clear();
if(playMode==PlayMode::SINGLE){
players.resize(1);
}else{

View File

@ -49,7 +49,8 @@ void Game::managePlayers(){
}
bool Game::manageInvaders(){
if(grid.empty())return false; // If there are no more invaders we don't need to manage them
if(!areThereInvadersLeft())return false; // If there are no more invaders we don't need to manage them
// shoot
if(fireCooldown==0) {
fireCooldown = confData.invadersFireCooldown + rand() % 60;

View File

@ -58,7 +58,8 @@ bool Game::manageGod() {
return false;
}
if (grid.size() > god.thrownInvPosY && grid[god.thrownInvPosX][god.thrownInvPosY] != InvaderType::NONE) {
if (grid[god.thrownInvPosX].size() > god.thrownInvPosY &&
grid[god.thrownInvPosX][god.thrownInvPosY] != InvaderType::NONE) {
god.thrownInvType = grid[god.thrownInvPosX][god.thrownInvPosY];
grid[god.thrownInvPosX][god.thrownInvPosY] = InvaderType::NONE;
}
@ -113,6 +114,11 @@ bool Game::manageGod() {
if (invaderPos.getY() + confData.invadersSize >= pm.getScreenWidth() ||
(invaderPos.getX() < 0 || invaderPos.getX() + confData.invadersSize >= pm.getScreenWidth())) {
touched = true;
/* there are no invaders in the grid anymore, and the one thrown just went out of bound
* So... return true, the playere wins*/
if(!areThereInvadersLeft())return true;
// check player collision
} else if (invaderPos.getY() + confData.invadersSize >= pm.getScreenHeight() - PLAYER_HEIGHT) {
for (Player &p: players) {
@ -131,16 +137,13 @@ bool Game::manageGod() {
if (touched) {
god.state = GodState::WAIT;
god.counter = 0;
if(!areThereInvadersLeft())return true;
}
/*
* we do not need to reset other members, they'll be treated as non-initialized
* When we cycle back between states
*/
/* we do not need to reset other members, they'll be treated as non-initialized
* When we cycle back between states*/
// We could have optimized that, but it's more readable like this and hopefully the compiler will optimize it itself
if(areThereInvadersLeft())return false;
else return true;
return false;
}
case GodState::YOLO: {