diff --git a/config.yml b/config.yml index 08ae95f..460e3f9 100644 --- a/config.yml +++ b/config.yml @@ -68,7 +68,7 @@ players: startXPosition: 600 fireCooldown: 10 speed: 10 - lives: 3 + lives: 100 user1: color: red keys: diff --git a/src/configManagement.cpp b/src/configManagement.cpp index a5ac6d6..3cb4a1e 100644 --- a/src/configManagement.cpp +++ b/src/configManagement.cpp @@ -155,17 +155,17 @@ void ConfigBuilder::readInvaderType(const configKey& baseKey, InvaderTypeDef& in void ConfigBuilder::readConfig() { - collectedData.theme = getString("general.theme"); - collectedData.maxFPS = getInt("general.maxFPS"); + collectedData.theme = getString("general.theme", "bad"); + collectedData.maxFPS = getInt("general.maxFPS", 30, 1, 60); readGrid("grid"); // players - collectedData.playersWidth = getInt("players.width", 100, 0, 500); + collectedData.playersWidth = getInt("players.width", 100, 50, 500); collectedData.startXPosition = getInt("players.startXPosition",600 ,0 ,1200); - collectedData.playersSpeed = getInt("players.speed",1,0,100); - collectedData.playersFireCooldown = getInt("players.fireCooldown",10,1,10000); - collectedData.playersLives = getInt("players.lives",3,1,1000); + collectedData.playersSpeed = getInt("players.speed",1,1,100); + collectedData.playersFireCooldown = getInt("players.fireCooldown",10,1,100); + collectedData.playersLives = getInt("players.lives",3,1,100); // the scalability behind the vector of players is only an illusion, because we force player count to be 1 or 2 // It was done so the 2+ players implementation could be easier in the future, if wanted @@ -174,24 +174,24 @@ void ConfigBuilder::readConfig() { readPlayer("players.user2", collectedData.playerDefs[1]); // invaders - collectedData.invadersSize = getInt("invaders.size",30,10,1000); - collectedData.invadersSpeed = getInt("invaders.speed",7,1,1000); - collectedData.invadersDistance = getInt("invaders.distance",15,5,1000); - collectedData.invadersFireCooldown = getInt("invaders.fireCooldown",0,0,1000); + collectedData.invadersSize = getInt("invaders.size",30,10,100); + collectedData.invadersSpeed = getInt("invaders.speed",7,1,100); + collectedData.invadersDistance = getInt("invaders.distance",15,5,100); + collectedData.invadersFireCooldown = getInt("invaders.fireCooldown",0,0,100); readInvaderType("invaders.typeA", collectedData.invadersDef[InvaderType::TYPEA]); readInvaderType("invaders.typeB", collectedData.invadersDef[InvaderType::TYPEB]); readInvaderType("invaders.typeC", collectedData.invadersDef[InvaderType::TYPEC]); // projectiles - collectedData.missilesWidth = getInt("projectiles.missiles.width",10,5,1000); + collectedData.missilesWidth = getInt("projectiles.missiles.width",10,5,100); collectedData.missilesLength = collectedData.missilesWidth*PROJ_LENGTH_FACTOR; - collectedData.missilesSpeed = getInt("projectiles.missiles.speed",10,5,1000); + collectedData.missilesSpeed = getInt("projectiles.missiles.speed",10,5,100); getColor("projectiles.missiles.color", collectedData.missilesColor); - collectedData.torpedosWidth = getInt("projectiles.torpedos.width",10,1,1000); + collectedData.torpedosWidth = getInt("projectiles.torpedos.width",10,1,100); collectedData.torpedosLength = collectedData.torpedosWidth*PROJ_LENGTH_FACTOR; - collectedData.torpedosSpeed = getInt("projectiles.torpedos.speed",10,1,1000); + collectedData.torpedosSpeed = getInt("projectiles.torpedos.speed",10,1,100); getColor("projectiles.torpedos.color", collectedData.torpedosColor); } diff --git a/src/game/gameBasics.cpp b/src/game/gameBasics.cpp index 7a53c77..67a6024 100644 --- a/src/game/gameBasics.cpp +++ b/src/game/gameBasics.cpp @@ -69,10 +69,11 @@ void Game::managedGames() { if(playMode==PlayMode::NONE){ playMode = pm->showInitialMenu(); }else{ + DEBUG_MSG("Starting game") initGame(); enterGameLoop(); // will read the playMode + DEBUG_MSG("END End of game") handleScoreSaving(); - cout << "END OF GAME" << endl; if(!pm->showDeathMenu(sm.scores))playMode = PlayMode::NONE; } } @@ -113,6 +114,10 @@ void Game::initGame(){ * * @return @WinValue::PLAYERS if the players won, @WinValue::INVADERS is the invaders won, WinValue::NOBODY else (also in case of error) */ + +#define START_TIMER() DEBUG_INSTR(debugTime = chrono::high_resolution_clock::now()) +#define PRINT_TIMER(X) DEBUG_MSG((X) << " :" << chrono::duration_cast(chrono::high_resolution_clock::now()-debugTime).count()) + WinValue Game::enterGameLoop(){ // returns when game is finished // computed in advance for performance reasons chrono::milliseconds maxFrameTime = chrono::milliseconds(1000/confData.maxFPS); @@ -121,7 +126,11 @@ WinValue Game::enterGameLoop(){ // returns when game is finished unsigned fps = 0; typedef chrono::high_resolution_clock::time_point MyTimePoint; MyTimePoint fpsStartTime = {}; + + DEBUG_INSTR(MyTimePoint debugTime); while(window.isOpen()){ + DEBUG_INSTR(fflush(stdout)); + DEBUG_MSG("------------") MyTimePoint startTime = chrono::high_resolution_clock::now(); if(fpsStartTime.time_since_epoch()==chrono::seconds(0)){ @@ -130,26 +139,38 @@ WinValue Game::enterGameLoop(){ // returns when game is finished pm->startFrame(); + START_TIMER() managePlayers(); + PRINT_TIMER("manage players") + START_TIMER() if(manageInvaders()) { // if they went down if (invadersTouchPlayer())return WinValue::INVADERS; tryAwakeGod(); } + PRINT_TIMER("manage invaders") + START_TIMER() if(manageGod())return WinValue::PLAYERS; if(arePlayersDead())return WinValue::GOD; + PRINT_TIMER("god") + START_TIMER() moveMissiles(); remCollidingProjectiles(); moveTorpedos(); remCollidingProjectiles(); + PRINT_TIMER("self collisions") + START_TIMER() checkMissilesAndPlayers(); if(checkTorpedosAndInvaders())return WinValue::PLAYERS; + PRINT_TIMER("collisions between entities") if(arePlayersDead())return WinValue::INVADERS; + START_TIMER() displayAll(fps); + PRINT_TIMER("display") pm->endFrame(); diff --git a/src/game/gameManagers.cpp b/src/game/gameManagers.cpp index f180945..9f3a420 100644 --- a/src/game/gameManagers.cpp +++ b/src/game/gameManagers.cpp @@ -62,6 +62,7 @@ bool Game::manageInvaders(){ }else --fireCooldown; // moving + // TODO fix this lol if(direction){ // go to the right int end = basePos.getX(); // start Position end+= grid.size() * confData.invadersSize; // add the invaders