merge
This commit is contained in:
		
						commit
						fdaa535b29
					
				@ -68,7 +68,7 @@ players:
 | 
				
			|||||||
 startXPosition: 600
 | 
					 startXPosition: 600
 | 
				
			||||||
 fireCooldown: 10
 | 
					 fireCooldown: 10
 | 
				
			||||||
 speed: 10
 | 
					 speed: 10
 | 
				
			||||||
 lives: 3
 | 
					 lives: 100
 | 
				
			||||||
 user1:
 | 
					 user1:
 | 
				
			||||||
  color: red
 | 
					  color: red
 | 
				
			||||||
  keys:
 | 
					  keys:
 | 
				
			||||||
 | 
				
			|||||||
@ -155,17 +155,17 @@ void ConfigBuilder::readInvaderType(const configKey& baseKey, InvaderTypeDef& in
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void ConfigBuilder::readConfig() {
 | 
					void ConfigBuilder::readConfig() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	collectedData.theme = getString("general.theme");
 | 
						collectedData.theme = getString("general.theme", "bad");
 | 
				
			||||||
	collectedData.maxFPS = getInt("general.maxFPS");
 | 
						collectedData.maxFPS = getInt("general.maxFPS", 30, 1, 60);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	readGrid("grid");
 | 
						readGrid("grid");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// players
 | 
						// 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.startXPosition = getInt("players.startXPosition",600 ,0 ,1200);
 | 
				
			||||||
	collectedData.playersSpeed = getInt("players.speed",1,0,100);
 | 
						collectedData.playersSpeed = getInt("players.speed",1,1,100);
 | 
				
			||||||
	collectedData.playersFireCooldown = getInt("players.fireCooldown",10,1,10000);
 | 
						collectedData.playersFireCooldown = getInt("players.fireCooldown",10,1,100);
 | 
				
			||||||
	collectedData.playersLives = getInt("players.lives",3,1,1000);
 | 
						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
 | 
						// 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
 | 
						// 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]);
 | 
						readPlayer("players.user2", collectedData.playerDefs[1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// invaders
 | 
						// invaders
 | 
				
			||||||
	collectedData.invadersSize = getInt("invaders.size",30,10,1000);
 | 
						collectedData.invadersSize = getInt("invaders.size",30,10,100);
 | 
				
			||||||
	collectedData.invadersSpeed = getInt("invaders.speed",7,1,1000);
 | 
						collectedData.invadersSpeed = getInt("invaders.speed",7,1,100);
 | 
				
			||||||
	collectedData.invadersDistance = getInt("invaders.distance",15,5,1000);
 | 
						collectedData.invadersDistance = getInt("invaders.distance",15,5,100);
 | 
				
			||||||
	collectedData.invadersFireCooldown = getInt("invaders.fireCooldown",0,0,1000);
 | 
						collectedData.invadersFireCooldown = getInt("invaders.fireCooldown",0,0,100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	readInvaderType("invaders.typeA", collectedData.invadersDef[InvaderType::TYPEA]);
 | 
						readInvaderType("invaders.typeA", collectedData.invadersDef[InvaderType::TYPEA]);
 | 
				
			||||||
	readInvaderType("invaders.typeB", collectedData.invadersDef[InvaderType::TYPEB]);
 | 
						readInvaderType("invaders.typeB", collectedData.invadersDef[InvaderType::TYPEB]);
 | 
				
			||||||
	readInvaderType("invaders.typeC", collectedData.invadersDef[InvaderType::TYPEC]);
 | 
						readInvaderType("invaders.typeC", collectedData.invadersDef[InvaderType::TYPEC]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// projectiles
 | 
						// 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.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);
 | 
						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.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);
 | 
						getColor("projectiles.torpedos.color", collectedData.torpedosColor);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -69,10 +69,11 @@ void Game::managedGames() {
 | 
				
			|||||||
		if(playMode==PlayMode::NONE){
 | 
							if(playMode==PlayMode::NONE){
 | 
				
			||||||
			playMode = pm->showInitialMenu();
 | 
								playMode = pm->showInitialMenu();
 | 
				
			||||||
		}else{
 | 
							}else{
 | 
				
			||||||
 | 
								DEBUG_MSG("Starting game")
 | 
				
			||||||
			initGame();
 | 
								initGame();
 | 
				
			||||||
			enterGameLoop(); // will read the playMode
 | 
								enterGameLoop(); // will read the playMode
 | 
				
			||||||
 | 
								DEBUG_MSG("END End of game")
 | 
				
			||||||
			handleScoreSaving();
 | 
								handleScoreSaving();
 | 
				
			||||||
			cout << "END OF GAME" << endl;
 | 
					 | 
				
			||||||
			if(!pm->showDeathMenu(sm.scores))playMode = PlayMode::NONE;
 | 
								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)
 | 
					 * @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::nanoseconds>(chrono::high_resolution_clock::now()-debugTime).count())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WinValue Game::enterGameLoop(){ // returns when game is finished
 | 
					WinValue Game::enterGameLoop(){ // returns when game is finished
 | 
				
			||||||
	// computed in advance for performance reasons
 | 
						// computed in advance for performance reasons
 | 
				
			||||||
	chrono::milliseconds maxFrameTime = chrono::milliseconds(1000/confData.maxFPS);
 | 
						chrono::milliseconds maxFrameTime = chrono::milliseconds(1000/confData.maxFPS);
 | 
				
			||||||
@ -121,7 +126,11 @@ WinValue Game::enterGameLoop(){ // returns when game is finished
 | 
				
			|||||||
	unsigned fps = 0;
 | 
						unsigned fps = 0;
 | 
				
			||||||
	typedef chrono::high_resolution_clock::time_point MyTimePoint;
 | 
						typedef chrono::high_resolution_clock::time_point MyTimePoint;
 | 
				
			||||||
	MyTimePoint fpsStartTime = {};
 | 
						MyTimePoint fpsStartTime = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						DEBUG_INSTR(MyTimePoint debugTime);
 | 
				
			||||||
	while(window.isOpen()){
 | 
						while(window.isOpen()){
 | 
				
			||||||
 | 
							DEBUG_INSTR(fflush(stdout));
 | 
				
			||||||
 | 
							DEBUG_MSG("------------")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		MyTimePoint startTime = chrono::high_resolution_clock::now();
 | 
							MyTimePoint startTime = chrono::high_resolution_clock::now();
 | 
				
			||||||
		if(fpsStartTime.time_since_epoch()==chrono::seconds(0)){
 | 
							if(fpsStartTime.time_since_epoch()==chrono::seconds(0)){
 | 
				
			||||||
@ -130,26 +139,38 @@ WinValue Game::enterGameLoop(){ // returns when game is finished
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		pm->startFrame();
 | 
							pm->startFrame();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							START_TIMER()
 | 
				
			||||||
		managePlayers();
 | 
							managePlayers();
 | 
				
			||||||
 | 
							PRINT_TIMER("manage players")
 | 
				
			||||||
 | 
							START_TIMER()
 | 
				
			||||||
		if(manageInvaders()) { // if they went down
 | 
							if(manageInvaders()) { // if they went down
 | 
				
			||||||
			if (invadersTouchPlayer())return WinValue::INVADERS;
 | 
								if (invadersTouchPlayer())return WinValue::INVADERS;
 | 
				
			||||||
			tryAwakeGod();
 | 
								tryAwakeGod();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							PRINT_TIMER("manage invaders")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							START_TIMER()
 | 
				
			||||||
		if(manageGod())return WinValue::PLAYERS;
 | 
							if(manageGod())return WinValue::PLAYERS;
 | 
				
			||||||
		if(arePlayersDead())return WinValue::GOD;
 | 
							if(arePlayersDead())return WinValue::GOD;
 | 
				
			||||||
 | 
							PRINT_TIMER("god")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							START_TIMER()
 | 
				
			||||||
		moveMissiles();
 | 
							moveMissiles();
 | 
				
			||||||
		remCollidingProjectiles();
 | 
							remCollidingProjectiles();
 | 
				
			||||||
		moveTorpedos();
 | 
							moveTorpedos();
 | 
				
			||||||
		remCollidingProjectiles();
 | 
							remCollidingProjectiles();
 | 
				
			||||||
 | 
							PRINT_TIMER("self collisions")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							START_TIMER()
 | 
				
			||||||
		checkMissilesAndPlayers();
 | 
							checkMissilesAndPlayers();
 | 
				
			||||||
		if(checkTorpedosAndInvaders())return WinValue::PLAYERS;
 | 
							if(checkTorpedosAndInvaders())return WinValue::PLAYERS;
 | 
				
			||||||
 | 
							PRINT_TIMER("collisions between entities")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(arePlayersDead())return WinValue::INVADERS;
 | 
							if(arePlayersDead())return WinValue::INVADERS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							START_TIMER()
 | 
				
			||||||
		displayAll(fps);
 | 
							displayAll(fps);
 | 
				
			||||||
 | 
							PRINT_TIMER("display")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pm->endFrame();
 | 
							pm->endFrame();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -62,6 +62,7 @@ bool Game::manageInvaders(){
 | 
				
			|||||||
	}else --fireCooldown;
 | 
						}else --fireCooldown;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// moving
 | 
						// moving
 | 
				
			||||||
 | 
						// TODO fix this lol
 | 
				
			||||||
	if(direction){ // go to the right
 | 
						if(direction){ // go to the right
 | 
				
			||||||
		int end = basePos.getX(); // start Position
 | 
							int end = basePos.getX(); // start Position
 | 
				
			||||||
		end+= grid.size() * confData.invadersSize; // add the invaders
 | 
							end+= grid.size() * confData.invadersSize; // add the invaders
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user