From 9d4f1f640a5ecd7a80fb2d0e781983e07b0aa773 Mon Sep 17 00:00:00 2001 From: Thomas <74205383+Thomas776@users.noreply.github.com> Date: Mon, 13 Dec 2021 12:07:17 +0100 Subject: [PATCH] progress de la classe game --- README | 8 +++++++- config.yaml | 7 ------- headers/entites.h | 16 ---------------- headers/game.h | 42 ++++++++++++++++++++++++++++++++++++++++++ headers/sprites.h | 21 +++++++++++++++++++-- main.cpp | 3 +++ src/entites.cpp | 16 ---------------- src/game.cpp | 23 +++++++++++++++++++++++ src/sprites.cpp | 34 ++++++++++++++++++++++++++++++++++ 9 files changed, 128 insertions(+), 42 deletions(-) delete mode 100644 headers/entites.h create mode 100644 headers/game.h delete mode 100644 src/entites.cpp create mode 100644 src/game.cpp create mode 100644 src/sprites.cpp diff --git a/README b/README index 48aaeda..e383112 100644 --- a/README +++ b/README @@ -1 +1,7 @@ -Hey there +Conventions à suivre : +camelCase pour les noms de variables/fonctions/fichiers +PascalCase pour les noms de classes/structures +Nommage en anglais +Pas de fonctions de +100 lignes + +écran : constante 1280x720 diff --git a/config.yaml b/config.yaml index 74f2c53..8f686bb 100644 --- a/config.yaml +++ b/config.yaml @@ -3,13 +3,6 @@ screen: # specifies the screen resolution, must in 16:9, # default : "1280x720" #! hardcoder une res de base si c'est pas un 16:9 - resolution: - screen: - - "1920" - - "1080" - terminal: - - 10 - - 10 terminal: charEmptySpace: ' ' charPlayer: '' diff --git a/headers/entites.h b/headers/entites.h deleted file mode 100644 index f7cb0fe..0000000 --- a/headers/entites.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef entites -#define entites - -void summonEntity(entites & pos_entites, pos & coordonees); - -void deleteEntity(entites & pos_entites, pos & coordonees); - -void invaderMovement(entites & pos_entites); - -void torpilleMovement(entites & pos_entites); - -void Collision(entites & pos_entites); - -void userInteraction(entites & pos_entites); - -#endif \ No newline at end of file diff --git a/headers/game.h b/headers/game.h new file mode 100644 index 0000000..c23062a --- /dev/null +++ b/headers/game.h @@ -0,0 +1,42 @@ +#ifndef game +#define game +#include +#include "mingl/mingl.h" +#include "sprites.h" + +using namespace std; + +enum TypeAlien { + typeUn, + typeDeux, + typeTrois +}; + +struct Alien{ + TypeAlien type; + nsGraphics::Vec2D coord; +}; + +typedef vector ligneEntite; +typedef vector matriceAlien; + +class Game { +private: + MinGL window; + matriceAlien grid; + vectormissiles; + vectortorpilles; +public: + Game(); + void display(); + void importConfig(); + void summon(); + void deleteEntity(); + void invaderMovement(); + void torpilleMovement(); + void collision(); + void userInteraction(); + +} + +#endif \ No newline at end of file diff --git a/headers/sprites.h b/headers/sprites.h index bdcc06b..fe6062b 100644 --- a/headers/sprites.h +++ b/headers/sprites.h @@ -1,12 +1,29 @@ #ifndef sprites #define sprites -#include "mingl/mingl.h" +#include "mingl/mingl.h" #include "mingl/shape/line.h" #include "mingl/shape/triangle.h" -#include "mingl/shape/rectangle.g" +#include "mingl/shape/rectangle.h" #include "mingl/shape/circle.h" +enum typeA{ + vert, + rouge, + bleu, +}; +/* +sprites envahisseurUn(); +sprites envahisseurDeux(); +sprites envahisseurTrois(); +sprites joueur(); +sprites missile(); +sprites torpille(); +*/ + +void dessinerInvader1(MinGL& window, const nsGraphics::Vec2D& baseVector); +void dessinerInvader2(MinGL& window, const nsGraphics::Vec2D& baseVector); +void dessinerInvader3(MinGL& window, const nsGraphics::Vec2D& baseVector); #endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index 7960da3..13b33fe 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,9 @@ #include +#include "game.h" using namespace std; int main(){ + Game jeu(); + jeu.display(); return 0; } \ No newline at end of file diff --git a/src/entites.cpp b/src/entites.cpp deleted file mode 100644 index 4441990..0000000 --- a/src/entites.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include "entites.h" -#include - -struct pos { - int x; - int y; -}; - -struct entites { - vector torpille = vector(0); - vector missile = vector(0); - pos joueur; - vector envahisseur= vector(0); - string direction; -}; \ No newline at end of file diff --git a/src/game.cpp b/src/game.cpp new file mode 100644 index 0000000..c616196 --- /dev/null +++ b/src/game.cpp @@ -0,0 +1,23 @@ +#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/sprites.cpp b/src/sprites.cpp new file mode 100644 index 0000000..855451a --- /dev/null +++ b/src/sprites.cpp @@ -0,0 +1,34 @@ +#include "sprite.h" + +void dessinerInvader1(MinGL& window, const nsGraphics::Vec2D& baseVector){ + + window << nsShape::Circle(nsGraphics::Vec2D(50, 50)+baseVector, 50, nsGraphics::KGray); + window << nsShape::Circle(nsGraphics::Vec2D(60, 50)+baseVector, 50, nsGraphics::KGray); + window << nsShape::Triangle(nsGraphics::Vec2D(35, 50)+baseVector, nsGraphics::Vec2D(15, 25)+baseVector, nsGraphics::Vec2D(15, 75)+baseVector, nsGraphics::KBlack); + window << nsShape::Triangle(nsGraphics::Vec2D(25, 50)+baseVector, nsGraphics::Vec2D(10, 25)+baseVector, nsGraphics::Vec2D(10, 75)+baseVector, nsGraphics::KGray); + window << nsShape::Triangle(nsGraphics::Vec2D(75, 50)+baseVector, nsGraphics::Vec2D(95, 25)+baseVector, nsGraphics::Vec2D(95, 75)+baseVector, nsGraphics::KBlack); + window << nsShape::Triangle(nsGraphics::Vec2D(85, 50)+baseVector, nsGraphics::Vec2D(100, 25)+baseVector, nsGraphics::Vec2D(100, 75)+baseVector, nsGraphics::KGray); + window << nsShape::Rectangle(nsGraphics::Vec2D(35, 65)+baseVector, nsGraphics::Vec2D(75, 72)+baseVector, nsGraphics::KBlack); + +} + +void dessinerInvader2(MinGL& window, const nsGraphics::Vec2D& baseVector){ + window << nsShape::Circle(nsGraphics::Vec2D(50, 50)+baseVector, 50, nsGraphics::KRed); + window << nsShape::Circle(nsGraphics::Vec2D(60, 50)+baseVector, 50, nsGraphics::KRed); + window << nsShape::Rectangle(nsGraphics::Vec2D(25, 30)+baseVector, nsGraphics::Vec2D(45, 40)+baseVector, nsGraphics::KBlack); + window << nsShape::Rectangle(nsGraphics::Vec2D(65, 30)+baseVector, nsGraphics::Vec2D(85, 40)+baseVector, nsGraphics::KBlack); + window << nsShape::Rectangle(nsGraphics::Vec2D(35, 65)+baseVector, nsGraphics::Vec2D(75, 72)+baseVector, nsGraphics::KBlack); +} + +void dessinerInvader3(MinGL& window, const nsGraphics::Vec2D& baseVector){ + window << nsShape::Circle(nsGraphics::Vec2D(60, 50)+baseVector, 50, nsGraphics::KGreen); + window << nsShape::Circle(nsGraphics::Vec2D(50, 50)+baseVector, 50, nsGraphics::KGreen); + window << nsShape::Circle(nsGraphics::Vec2D(35, 35)+baseVector, 10, nsGraphics::KBlack); + window << nsShape::Circle(nsGraphics::Vec2D(75, 35)+baseVector, 10, nsGraphics::KBlack); + window << nsShape::Rectangle(nsGraphics::Vec2D(35, 65)+baseVector, nsGraphics::Vec2D(75, 72)+baseVector, nsGraphics::KBlack); +} + +sprites joueur(); +sprites missile(); +sprites torpille(); +