save commit, just to be sure
This commit is contained in:
		
							parent
							
								
									9d4f1f640a
								
							
						
					
					
						commit
						d52a491cd0
					
				
							
								
								
									
										15
									
								
								headers/config.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								headers/config.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| #ifndef SPACE_CONFIG | ||||
| #define SPACE_CONFIG | ||||
| 
 | ||||
| #include<vector> | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| struct Config{ | ||||
| 	vector<vector<unsigned>> grid; | ||||
| 
 | ||||
| 	unsigned alien_size; | ||||
| 	unsigned distance; | ||||
| }; | ||||
| 
 | ||||
| #endif | ||||
| @ -3,40 +3,41 @@ | ||||
| #include <vector> | ||||
| #include "mingl/mingl.h" | ||||
| #include "sprites.h" | ||||
| #include "config.h" | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| enum TypeAlien { | ||||
|     typeUn, | ||||
|     typeDeux, | ||||
|     typeTrois | ||||
| }; | ||||
| 
 | ||||
| struct Alien{ | ||||
|     TypeAlien type; | ||||
|     nsGraphics::Vec2D coord; | ||||
| }; | ||||
| 
 | ||||
| typedef vector<Alien> ligneEntite; | ||||
| typedef vector<ligneEntite> matriceAlien; | ||||
| typedef unsigned Alien; | ||||
| typedef vector<Alien> aliensLine; | ||||
| typedef vector<aliensLine> aliensGrid; | ||||
| 
 | ||||
| class Game { | ||||
| private: | ||||
|     MinGL window; | ||||
| 	Config conf; | ||||
| 	unsigned baseX; | ||||
| 	unsigned baseY; | ||||
| 	vector<vector<TypeAlien>> aliens; | ||||
|     matriceAlien grid; | ||||
|     vector<nsGraphics::Vec2D>missiles; | ||||
|     vector<nsGraphics::Vec2D>torpilles; | ||||
|     vector<nsGraphics::Vec2D> missiles; | ||||
|     vector<nsGraphics::Vec2D> torpilles; | ||||
| 
 | ||||
| 	unsigned manageCollisions(); | ||||
| 	void managePlayer(); | ||||
| 	bool manageInvaders(); | ||||
| 	void display(); | ||||
| 	void importConfig(); | ||||
| 	void summon(); | ||||
| 	void deleteEntity(); | ||||
| 	void invaderMovement(); | ||||
| 	void torpilleMovement(); | ||||
| 	void collision(); | ||||
| 	void userInteraction(); | ||||
| public: | ||||
|     Game(); | ||||
|     void display(); | ||||
|     void importConfig(); | ||||
|     void summon(); | ||||
|     void deleteEntity(); | ||||
|     void invaderMovement(); | ||||
|     void torpilleMovement(); | ||||
|     void collision(); | ||||
|     void userInteraction(); | ||||
| 	void managedGame(); | ||||
| 	void playGame(); | ||||
| 
 | ||||
| } | ||||
| }; | ||||
| 
 | ||||
| #endif | ||||
							
								
								
									
										8
									
								
								headers/typeAlien.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								headers/typeAlien.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | ||||
| //
 | ||||
| // Created by itrooz on 16/12/2021.
 | ||||
| //
 | ||||
| 
 | ||||
| #ifndef SPACE_TYPEALIEN_H | ||||
| #define SPACE_TYPEALIEN_H | ||||
| 
 | ||||
| #endif //SPACE_TYPEALIEN_H
 | ||||
							
								
								
									
										23
									
								
								src/game.cpp
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								src/game.cpp
									
									
									
									
									
								
							| @ -1,23 +0,0 @@ | ||||
| #include "game.h" | ||||
| 
 | ||||
| Game::Game() : | ||||
|     window("space invader du turfu ma gueule", nsGraphics::Vec2D(1280, 720), nsGraphics::Vec2D(128, 128), nsGraphics::KBlack) | ||||
|     { | ||||
|  // init la fentre
 | ||||
|   | ||||
|     this->window.initGlut(); | ||||
|     this->window.initGraphic(); | ||||
| // init les amlien
 | ||||
|     Alien tamer {typeUn,{0,0}}; | ||||
|     ligneEntite tmp(0); | ||||
|     tmp.push_back(tamer); | ||||
|     this->grid.push_back(tmp); | ||||
| } | ||||
| 
 | ||||
| void Game::display(){ | ||||
|     for(ligneEntite & ligne : this->grid){ | ||||
|         for( Alien & alien : ligne){ | ||||
|             dessinerInvader1(this->window, alien.coord); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										55
									
								
								src/game_basics.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/game_basics.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,55 @@ | ||||
| #include "game.h" | ||||
| 
 | ||||
| Game::Game() : | ||||
|     window("space invader du turfu ma gueule", nsGraphics::Vec2D(1280, 720), nsGraphics::Vec2D(128, 128), nsGraphics::KBlack) { | ||||
| 
 | ||||
| 	this->window.initGlut(); | ||||
| 	this->window.initGraphic(); | ||||
| } | ||||
| 
 | ||||
| void Game::managedGame() { | ||||
| 	initialMenuHandler(); // returns when user clicked plays
 | ||||
| 
 | ||||
| 	while(true){ | ||||
| 		playGame(); | ||||
| 		deathScrenHandler(); // returns when user clicked replay
 | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void Game::showInitialMenu(){ | ||||
| 	switch(pixelManager.showInitialMenu()){ | ||||
| 		case 0:{ // play
 | ||||
| 			return; | ||||
| 		} | ||||
| 		// potential options...
 | ||||
| 	} | ||||
| } | ||||
| /**
 | ||||
|  * Plays the game, and returns once the game is finished | ||||
|  * | ||||
|  * @return 1 if the player won, 2 is the invaders won, any other value can be returned in case of a problem | ||||
|  */ | ||||
| unsigned Game::playGame(){ // returns when game is finished
 | ||||
| 	// INIT
 | ||||
| 	aliens = conf.grid; // will copy the vector
 | ||||
| 
 | ||||
| 	// GAMELOOP
 | ||||
| 	while(true){ | ||||
| 		display(); | ||||
| 		unsigned res = manageCollisions(game); // also advances missiles + torpedos
 | ||||
| 		if(res!=0)return res; | ||||
| 		managePlayer(game); | ||||
| 		if(manageInvalider(game))return INVADER_WINS; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| /** Displays the screen once, and returns
 | ||||
|  * | ||||
|  */ | ||||
| void Game::display(){ | ||||
|     for(aliensLine& line : this->grid){ | ||||
|         for(Alien& al : line){ | ||||
|             pixelManager.dessinerInvader1(this->window, alien.coord); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										15
									
								
								src/game_managers.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/game_managers.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| #include "game.h" | ||||
| /** Makes the player play once
 | ||||
| */ | ||||
| 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 | ||||
| */ | ||||
| bool Game::manageInvaders(){ | ||||
| 	return false; | ||||
| 
 | ||||
| } | ||||
| @ -3,7 +3,7 @@ | ||||
| using namespace std; | ||||
| 
 | ||||
| int main(){ | ||||
|     Game jeu(); | ||||
|     jeu.display(); | ||||
|     Game g(); | ||||
| 	g.managedGame(); | ||||
|     return 0; | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user