From d52a491cd04a68f01a261181c0cf917d04786708 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 16 Dec 2021 11:56:17 +0100 Subject: [PATCH] save commit, just to be sure --- headers/config.h | 15 +++++++++++ headers/game.h | 49 +++++++++++++++++------------------ headers/typeAlien.h | 8 ++++++ src/game.cpp | 23 ----------------- src/game_basics.cpp | 55 ++++++++++++++++++++++++++++++++++++++++ src/game_managers.cpp | 15 +++++++++++ main.cpp => src/main.cpp | 4 +-- 7 files changed, 120 insertions(+), 49 deletions(-) create mode 100644 headers/config.h create mode 100644 headers/typeAlien.h delete mode 100644 src/game.cpp create mode 100644 src/game_basics.cpp create mode 100644 src/game_managers.cpp rename main.cpp => src/main.cpp (71%) diff --git a/headers/config.h b/headers/config.h new file mode 100644 index 0000000..eea2b14 --- /dev/null +++ b/headers/config.h @@ -0,0 +1,15 @@ +#ifndef SPACE_CONFIG +#define SPACE_CONFIG + +#include + +using namespace std; + +struct Config{ + vector> grid; + + unsigned alien_size; + unsigned distance; +}; + +#endif \ No newline at end of file diff --git a/headers/game.h b/headers/game.h index c23062a..2bdad07 100644 --- a/headers/game.h +++ b/headers/game.h @@ -3,40 +3,41 @@ #include #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 ligneEntite; -typedef vector matriceAlien; +typedef unsigned Alien; +typedef vector aliensLine; +typedef vector aliensGrid; class Game { private: MinGL window; + Config conf; + unsigned baseX; + unsigned baseY; + vector> aliens; matriceAlien grid; - vectormissiles; - vectortorpilles; + vector missiles; + vector 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 \ No newline at end of file diff --git a/headers/typeAlien.h b/headers/typeAlien.h new file mode 100644 index 0000000..461e1cc --- /dev/null +++ b/headers/typeAlien.h @@ -0,0 +1,8 @@ +// +// Created by itrooz on 16/12/2021. +// + +#ifndef SPACE_TYPEALIEN_H +#define SPACE_TYPEALIEN_H + +#endif //SPACE_TYPEALIEN_H diff --git a/src/game.cpp b/src/game.cpp deleted file mode 100644 index c616196..0000000 --- a/src/game.cpp +++ /dev/null @@ -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); - } - } -} \ No newline at end of file diff --git a/src/game_basics.cpp b/src/game_basics.cpp new file mode 100644 index 0000000..bfb52c3 --- /dev/null +++ b/src/game_basics.cpp @@ -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); + } + } +} \ No newline at end of file diff --git a/src/game_managers.cpp b/src/game_managers.cpp new file mode 100644 index 0000000..7c5bf76 --- /dev/null +++ b/src/game_managers.cpp @@ -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; + +} \ No newline at end of file diff --git a/main.cpp b/src/main.cpp similarity index 71% rename from main.cpp rename to src/main.cpp index 13b33fe..4dc06f5 100644 --- a/main.cpp +++ b/src/main.cpp @@ -3,7 +3,7 @@ using namespace std; int main(){ - Game jeu(); - jeu.display(); + Game g(); + g.managedGame(); return 0; } \ No newline at end of file