CA COMPIIIIILE

This commit is contained in:
Thomas 2021-12-16 13:49:49 +01:00
parent a39266b044
commit fac5bc245a
No known key found for this signature in database
GPG Key ID: E538821A6CDFDAD7
10 changed files with 70 additions and 33 deletions

View File

@ -9,7 +9,7 @@ file(GLOB_RECURSE HEADERS headers/*)
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 lib_headers)

View File

@ -2,14 +2,18 @@
#define GUARD_CONFIG
#include<vector>
#include "utils.h"
using namespace std;
struct Config{
class Config{
public:
aliensGrid grid;
unsigned alien_size;
unsigned distance;
bool loadConfig();
};
#endif

View File

@ -10,9 +10,13 @@
class DrawEngine{
public:
MinGL window;
DrawEngine();
void dessinerInvader1(const nsGraphics::Vec2D& baseVector);
void dessinerInvader2(const nsGraphics::Vec2D& baseVector);
void dessinerInvader3(const nsGraphics::Vec2D& baseVector);
unsigned showInitialMenu();
unsigned showDeathMenu();
};

View File

@ -4,13 +4,10 @@
#include "mingl/mingl.h"
#include "drawEngine.h"
#include "config.h"
#include "utils.h"
using namespace std;
typedef unsigned Alien;
typedef vector<Alien> aliensLine;
typedef vector<aliensLine> aliensGrid;
class Game {
private:
DrawEngine drawer;
@ -21,22 +18,17 @@ private:
vector<nsGraphics::Vec2D> missiles;
vector<nsGraphics::Vec2D> torpilles;
void loadConfig();
unsigned manageCollisions();
void managePlayer();
bool manageInvaders();
void display();
void summon();
void deleteEntity();
void invaderMovement();
void torpilleMovement();
void collision();
void userInteraction();
public:
// in case someone wants to mess with the code, here's a minimal API, costs nothing to us
Game();
void managedGame();
void playGame();
void managedGames();
unsigned playGame();
void initialMenuHandler();
void deathMenuHandler();
};

15
headers/utils.h Normal file
View 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
View File

@ -0,0 +1,5 @@
#include "config.h"
bool Config::loadConfig() {
return true;
}

View File

@ -1,6 +1,8 @@
#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.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);
}
unsigned DrawEngine::showInitialMenu(){
return 0;
}
unsigned DrawEngine::showDeathMenu() {
return 0;
}

View File

@ -1,26 +1,33 @@
#include "game.h"
Game::Game() :
window("space invader du turfu ma gueule", nsGraphics::Vec2D(1280, 720), nsGraphics::Vec2D(128, 128), nsGraphics::KBlack) {
loadConfig();
Game::Game() {
conf.loadConfig();
}
void Game::managedGame() {
void Game::managedGames() {
initialMenuHandler(); // returns when user clicked plays
while(true){
playGame();
deathScrenHandler(); // returns when user clicked replay
deathMenuHandler(); // returns when user clicked replay
}
}
void Game::showInitialMenu(){
switch(pixelManager.showInitialMenu()){
void Game::initialMenuHandler(){
switch(drawer.showInitialMenu()){
case 0:{ // play
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
// INIT
aliens = conf.grid; // will copy the vector
grid = conf.grid; // will copy the vector
// GAMELOOP
while(true){
display();
unsigned res = manageCollisions(game); // also advances missiles + torpedos
unsigned res = manageCollisions(); // also advances missiles + torpedos
if(res!=0)return res;
managePlayer(game);
if(manageInvalider(game))return INVADER_WINS;
managePlayer();
if(manageInvaders())return INVADERS_WINS;
}
}

View File

@ -16,8 +16,8 @@ bool Game::manageInvaders(){
/** 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(){
return 0;
}

View File

@ -4,6 +4,6 @@ using namespace std;
int main(){
Game g;
g.managedGame();
g.managedGames();
return 0;
}