save commit, just to be sure
This commit is contained in:
parent
9d4f1f640a
commit
d52a491cd0
15
headers/config.h
Normal file
15
headers/config.h
Normal 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
|
@ -3,40 +3,41 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "mingl/mingl.h"
|
#include "mingl/mingl.h"
|
||||||
#include "sprites.h"
|
#include "sprites.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
enum TypeAlien {
|
typedef unsigned Alien;
|
||||||
typeUn,
|
typedef vector<Alien> aliensLine;
|
||||||
typeDeux,
|
typedef vector<aliensLine> aliensGrid;
|
||||||
typeTrois
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Alien{
|
|
||||||
TypeAlien type;
|
|
||||||
nsGraphics::Vec2D coord;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef vector<Alien> ligneEntite;
|
|
||||||
typedef vector<ligneEntite> matriceAlien;
|
|
||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
private:
|
private:
|
||||||
MinGL window;
|
MinGL window;
|
||||||
|
Config conf;
|
||||||
|
unsigned baseX;
|
||||||
|
unsigned baseY;
|
||||||
|
vector<vector<TypeAlien>> aliens;
|
||||||
matriceAlien grid;
|
matriceAlien grid;
|
||||||
vector<nsGraphics::Vec2D>missiles;
|
vector<nsGraphics::Vec2D> missiles;
|
||||||
vector<nsGraphics::Vec2D>torpilles;
|
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:
|
public:
|
||||||
Game();
|
Game();
|
||||||
void display();
|
void managedGame();
|
||||||
void importConfig();
|
void playGame();
|
||||||
void summon();
|
|
||||||
void deleteEntity();
|
|
||||||
void invaderMovement();
|
|
||||||
void torpilleMovement();
|
|
||||||
void collision();
|
|
||||||
void userInteraction();
|
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
8
headers/typeAlien.h
Normal file
8
headers/typeAlien.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//
|
||||||
|
// Created by itrooz on 16/12/2021.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SPACE_TYPEALIEN_H
|
||||||
|
#define SPACE_TYPEALIEN_H
|
||||||
|
|
||||||
|
#endif //SPACE_TYPEALIEN_H
|
23
src/game.cpp
23
src/game.cpp
@ -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
55
src/game_basics.cpp
Normal 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
15
src/game_managers.cpp
Normal 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;
|
||||||
|
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
Game jeu();
|
Game g();
|
||||||
jeu.display();
|
g.managedGame();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user