save commit, just to be sure

This commit is contained in:
Thomas 2021-12-16 11:56:17 +01:00
parent 9d4f1f640a
commit d52a491cd0
No known key found for this signature in database
GPG Key ID: E538821A6CDFDAD7
7 changed files with 120 additions and 49 deletions

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

View File

@ -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
View File

@ -0,0 +1,8 @@
//
// Created by itrooz on 16/12/2021.
//
#ifndef SPACE_TYPEALIEN_H
#define SPACE_TYPEALIEN_H
#endif //SPACE_TYPEALIEN_H

View File

@ -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
View 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
View 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;
}

View File

@ -3,7 +3,7 @@
using namespace std;
int main(){
Game jeu();
jeu.display();
Game g();
g.managedGame();
return 0;
}