Ca compile. J'ai peur maman
This commit is contained in:
		
							parent
							
								
									14fef65b95
								
							
						
					
					
						commit
						bb61fbaac3
					
				| @ -19,6 +19,8 @@ public: | ||||
| 	unsigned torpedo_length; // auto defined from width
 | ||||
| 	unsigned player_width; | ||||
| 
 | ||||
| 	unsigned alien_speed; | ||||
| 
 | ||||
| 	bool loadConfig(); | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -13,9 +13,11 @@ class Game { | ||||
| private: | ||||
|     PixelManager pm; | ||||
| 	Config conf; | ||||
| 	unsigned baseX; | ||||
| 	unsigned baseY; | ||||
| 
 | ||||
| 	position basePos; | ||||
| 	aliensGrid grid; | ||||
| 	bool direction = true; | ||||
| 
 | ||||
|     vector<missile> missiles; | ||||
|     vector<torpedo> torpedos; | ||||
| 	unsigned playerX; | ||||
| @ -31,6 +33,7 @@ private: | ||||
| 	void moveTorpedos(); | ||||
| 	bool checkMissilesAndPlayer(); | ||||
| 	bool checkTorpedosAndInvaders(); | ||||
| 	bool invadersTouchFloor(); | ||||
| public: | ||||
| 	// in case someone wants to mess with the code, here's a minimal API, costs nothing to us
 | ||||
|     Game(); | ||||
|  | ||||
| @ -33,6 +33,16 @@ void Game::deathMenuHandler(){ | ||||
| 			// potential options...
 | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| bool Game::invadersTouchFloor(){ | ||||
| 	for(aliensLine& line : grid){ | ||||
| 		if(basePos.getY()+line.size()*conf.alien_size>=pm.getScreenHeight()){ | ||||
| 			return true; | ||||
| 		} | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * Plays the game, and returns once the game is finished | ||||
|  * | ||||
| @ -46,7 +56,7 @@ unsigned Game::playGame(){ // returns when game is finished | ||||
| 	// GAMELOOP
 | ||||
| 	while(true){ | ||||
| 		managePlayer(); | ||||
| 		if(manageInvaders())return INVADERS_WINS; | ||||
| 		if(manageInvaders() && invadersTouchFloor())return INVADERS_WINS; | ||||
| 		unsigned res = manageAllCollisions(); // also advances missiles + torpedos
 | ||||
| 		if(res!=0)return res; | ||||
| 		display(); | ||||
| @ -60,8 +70,8 @@ void Game::display() { | ||||
| 	for (unsigned i = 0; i < this->grid.size(); ++i){ | ||||
| 		for (unsigned j = 0; j < this->grid[0].size(); ++j){ | ||||
| 			pm.dessinerInvader1(nsGraphics::Vec2D( | ||||
| 				baseX+j*conf.alien_size+j*conf.distance, | ||||
| 				baseY+i*conf.alien_size+i*conf.distance | ||||
| 				basePos.getX()+j*conf.alien_size+j*conf.distance, | ||||
| 				basePos.getY()+i*conf.alien_size+i*conf.distance | ||||
| 			)); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @ -11,9 +11,32 @@ void Game::managePlayer(){ | ||||
| 
 | ||||
| /** Makes the invaders play once, and check lower bounds
 | ||||
|  * | ||||
|  * @return true if the invaders crossed the first line of the grid, else false | ||||
|  * @return true if the invaders went down from one line (and we should check boundaries), else false | ||||
| */ | ||||
| bool Game::manageInvaders(){ | ||||
| 	if(direction){ // go to the right
 | ||||
| 		int end = basePos.getX(); // start position
 | ||||
| 		end+= grid.size()*conf.alien_size; // add the aliens
 | ||||
| 		end+= (grid.size()-1)*conf.distance; // add the distance between aliens
 | ||||
| 
 | ||||
| 		// you got the end !
 | ||||
| 
 | ||||
| 		if(end+conf.alien_speed<pm.getScreenWidth()){ | ||||
| 			basePos.setX(basePos.getX()+conf.alien_speed); | ||||
| 		}else{ | ||||
| 			basePos.setY(basePos.getY()-conf.alien_size); | ||||
| 			direction = !direction; | ||||
| 			return true; | ||||
| 		} | ||||
| 	}else{ | ||||
| 		if(basePos.getX()-conf.alien_size>=0){ | ||||
| 			basePos.setX(basePos.getX()-conf.alien_speed); | ||||
| 		}else{ | ||||
| 			basePos.setY(basePos.getY()-conf.alien_size); | ||||
| 			direction = !direction; | ||||
| 			return true; | ||||
| 		} | ||||
| 	} | ||||
| 	return false; | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -45,4 +45,8 @@ unsigned PixelManager::showDeathMenu() { | ||||
| 
 | ||||
| unsigned PixelManager::getScreenHeight() { | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| unsigned PixelManager::getScreenWidth() { | ||||
| 	return 0; | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user