CA COMPIIIIILE
This commit is contained in:
		
							parent
							
								
									a39266b044
								
							
						
					
					
						commit
						fac5bc245a
					
				@ -9,7 +9,7 @@ file(GLOB_RECURSE HEADERS headers/*)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
add_executable(Space ${LIB_HEADERS} ${HEADERS} ${SRC})
 | 
					add_executable(Space ${LIB_HEADERS} ${HEADERS} ${SRC})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# target_link_directories(Space PUBLIC libs)
 | 
					 target_link_directories(Space PUBLIC .)
 | 
				
			||||||
target_include_directories(Space PUBLIC headers)
 | 
					target_include_directories(Space PUBLIC headers)
 | 
				
			||||||
target_include_directories(Space PUBLIC lib_headers)
 | 
					target_include_directories(Space PUBLIC lib_headers)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -2,14 +2,18 @@
 | 
				
			|||||||
#define GUARD_CONFIG
 | 
					#define GUARD_CONFIG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include<vector>
 | 
					#include<vector>
 | 
				
			||||||
 | 
					#include "utils.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace std;
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Config{
 | 
					class Config{
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
	aliensGrid grid;
 | 
						aliensGrid grid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	unsigned alien_size;
 | 
						unsigned alien_size;
 | 
				
			||||||
	unsigned distance;
 | 
						unsigned distance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bool loadConfig();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@ -10,9 +10,13 @@
 | 
				
			|||||||
class DrawEngine{
 | 
					class DrawEngine{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	MinGL window;
 | 
						MinGL window;
 | 
				
			||||||
 | 
						DrawEngine();
 | 
				
			||||||
	void dessinerInvader1(const nsGraphics::Vec2D& baseVector);
 | 
						void dessinerInvader1(const nsGraphics::Vec2D& baseVector);
 | 
				
			||||||
	void dessinerInvader2(const nsGraphics::Vec2D& baseVector);
 | 
						void dessinerInvader2(const nsGraphics::Vec2D& baseVector);
 | 
				
			||||||
	void dessinerInvader3(const nsGraphics::Vec2D& baseVector);
 | 
						void dessinerInvader3(const nsGraphics::Vec2D& baseVector);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						unsigned showInitialMenu();
 | 
				
			||||||
 | 
						unsigned showDeathMenu();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -4,13 +4,10 @@
 | 
				
			|||||||
#include "mingl/mingl.h"
 | 
					#include "mingl/mingl.h"
 | 
				
			||||||
#include "drawEngine.h"
 | 
					#include "drawEngine.h"
 | 
				
			||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#include "utils.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace std;
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef unsigned Alien;
 | 
					 | 
				
			||||||
typedef vector<Alien> aliensLine;
 | 
					 | 
				
			||||||
typedef vector<aliensLine> aliensGrid;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Game {
 | 
					class Game {
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    DrawEngine drawer;
 | 
					    DrawEngine drawer;
 | 
				
			||||||
@ -21,22 +18,17 @@ private:
 | 
				
			|||||||
    vector<nsGraphics::Vec2D> missiles;
 | 
					    vector<nsGraphics::Vec2D> missiles;
 | 
				
			||||||
    vector<nsGraphics::Vec2D> torpilles;
 | 
					    vector<nsGraphics::Vec2D> torpilles;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void loadConfig();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	unsigned manageCollisions();
 | 
						unsigned manageCollisions();
 | 
				
			||||||
	void managePlayer();
 | 
						void managePlayer();
 | 
				
			||||||
	bool manageInvaders();
 | 
						bool manageInvaders();
 | 
				
			||||||
	void display();
 | 
						void display();
 | 
				
			||||||
	void summon();
 | 
					 | 
				
			||||||
	void deleteEntity();
 | 
					 | 
				
			||||||
	void invaderMovement();
 | 
					 | 
				
			||||||
	void torpilleMovement();
 | 
					 | 
				
			||||||
	void collision();
 | 
					 | 
				
			||||||
	void userInteraction();
 | 
					 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
						// in case someone wants to mess with the code, here's a minimal API, costs nothing to us
 | 
				
			||||||
    Game();
 | 
					    Game();
 | 
				
			||||||
	void managedGame();
 | 
						void managedGames();
 | 
				
			||||||
	void playGame();
 | 
						unsigned playGame();
 | 
				
			||||||
 | 
						void initialMenuHandler();
 | 
				
			||||||
 | 
						void deathMenuHandler();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										15
									
								
								headers/utils.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								headers/utils.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					#ifndef SPACE_STRUCTS
 | 
				
			||||||
 | 
					#define SPACE_STRUCTS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include<vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define PLAYER_WINS 1
 | 
				
			||||||
 | 
					#define INVADERS_WINS 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef unsigned Alien;
 | 
				
			||||||
 | 
					typedef vector<Alien> aliensLine;
 | 
				
			||||||
 | 
					typedef vector<aliensLine> aliensGrid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										5
									
								
								src/config.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/config.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool Config::loadConfig() {
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,6 +1,8 @@
 | 
				
			|||||||
#include "drawEngine.h"
 | 
					#include "drawEngine.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DrawEngine::DrawEngine(){
 | 
					#define WININIT window("space invader du turfu ma gueule", nsGraphics::Vec2D(1280, 720), nsGraphics::Vec2D(128, 128), nsGraphics::KBlack)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DrawEngine::DrawEngine() : WININIT {
 | 
				
			||||||
	window.initGlut();
 | 
						window.initGlut();
 | 
				
			||||||
	window.initGraphic();
 | 
						window.initGraphic();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -32,3 +34,11 @@ void DrawEngine::dessinerInvader3(const nsGraphics::Vec2D& baseVector){
 | 
				
			|||||||
    window << nsShape::Rectangle(nsGraphics::Vec2D(35, 65)+baseVector, nsGraphics::Vec2D(75, 72)+baseVector, nsGraphics::KBlack);
 | 
					    window << nsShape::Rectangle(nsGraphics::Vec2D(35, 65)+baseVector, nsGraphics::Vec2D(75, 72)+baseVector, nsGraphics::KBlack);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned DrawEngine::showInitialMenu(){
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned DrawEngine::showDeathMenu() {
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,26 +1,33 @@
 | 
				
			|||||||
#include "game.h"
 | 
					#include "game.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Game::Game() :
 | 
					Game::Game() {
 | 
				
			||||||
    window("space invader du turfu ma gueule", nsGraphics::Vec2D(1280, 720), nsGraphics::Vec2D(128, 128), nsGraphics::KBlack) {
 | 
						conf.loadConfig();
 | 
				
			||||||
 | 
					 | 
				
			||||||
	loadConfig();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Game::managedGame() {
 | 
					void Game::managedGames() {
 | 
				
			||||||
	initialMenuHandler(); // returns when user clicked plays
 | 
						initialMenuHandler(); // returns when user clicked plays
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while(true){
 | 
						while(true){
 | 
				
			||||||
		playGame();
 | 
							playGame();
 | 
				
			||||||
		deathScrenHandler(); // returns when user clicked replay
 | 
							deathMenuHandler(); // returns when user clicked replay
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Game::showInitialMenu(){
 | 
					void Game::initialMenuHandler(){
 | 
				
			||||||
	switch(pixelManager.showInitialMenu()){
 | 
						switch(drawer.showInitialMenu()){
 | 
				
			||||||
		case 0:{ // play
 | 
							case 0:{ // play
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// potential options...
 | 
								// potential options...
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Game::deathMenuHandler(){
 | 
				
			||||||
 | 
						switch(drawer.showDeathMenu()){
 | 
				
			||||||
 | 
							case 0:{ // play
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
								// potential options...
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -30,15 +37,15 @@ void Game::showInitialMenu(){
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
unsigned Game::playGame(){ // returns when game is finished
 | 
					unsigned Game::playGame(){ // returns when game is finished
 | 
				
			||||||
	// INIT
 | 
						// INIT
 | 
				
			||||||
	aliens = conf.grid; // will copy the vector
 | 
						grid = conf.grid; // will copy the vector
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// GAMELOOP
 | 
						// GAMELOOP
 | 
				
			||||||
	while(true){
 | 
						while(true){
 | 
				
			||||||
		display();
 | 
							display();
 | 
				
			||||||
		unsigned res = manageCollisions(game); // also advances missiles + torpedos
 | 
							unsigned res = manageCollisions(); // also advances missiles + torpedos
 | 
				
			||||||
		if(res!=0)return res;
 | 
							if(res!=0)return res;
 | 
				
			||||||
		managePlayer(game);
 | 
							managePlayer();
 | 
				
			||||||
		if(manageInvalider(game))return INVADER_WINS;
 | 
							if(manageInvaders())return INVADERS_WINS;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -16,8 +16,8 @@ bool Game::manageInvaders(){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/** makes projectile smove, and manage collisions between everything
 | 
					/** makes projectile smove, and manage collisions between everything
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @return true if the invaders crossed the first line of the grid, else false
 | 
					 * @return 1 if the invaders are all dead, 2 if the player is dead, else 0
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
unsigned Game::manageCollisions(){
 | 
					unsigned Game::manageCollisions(){
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -4,6 +4,6 @@ using namespace std;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
int main(){
 | 
					int main(){
 | 
				
			||||||
    Game g;
 | 
					    Game g;
 | 
				
			||||||
	g.managedGame();
 | 
						g.managedGames();
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user