19#define WININIT window("SUPER Space Invader : Turbo Apocalypse DX - VS GOD", Position(1280, 720), Position(128, 128), nsGraphics::KBlack)
24 throw runtime_error(
"Initial config loading failed. Please check the error above and fix the configuration");
28 if(confData.theme==
"good"){
29 pm = std::make_unique<GoodPixelManager>(window);
30 }
else if(confData.theme==
"bad"){
31 pm = std::make_unique<PixelManager>(window);
32 }
else throw runtime_error(
"Invalid theme value : "+confData.theme+
33 "\nValid values are : good,bad");
35 cout <<
"Loading sprites..." << endl;
37 chrono::high_resolution_clock::time_point start = chrono::high_resolution_clock::now();
39 pm->loadSprites(tasks);
40 for(future<void>& f : tasks)f.wait();
43 pm->leftHand.mirror(pm->rightHand);
45 chrono::high_resolution_clock::duration elapsed = chrono::high_resolution_clock::now()-start;
46 cout <<
"Done ! Time : " << chrono::duration_cast<chrono::milliseconds>(elapsed).count() <<
"ms" << endl;
51bool Game::areThereInvadersLeft(){
55void Game::handleScoreSaving(){
56 for(
unsigned i=0;i<players.size();++i){
58 pm->askPlayerNameMenu(i, players[i].score, pName);
71 playMode = pm->showInitialMenu();
103 for(
unsigned i=0;i<players.size();++i){
113#define START_TIMER() DEBUG_INSTR(debugTime = chrono::high_resolution_clock::now())
114#define PRINT_TIMER(X) DEBUG_MSG((X) << ": " << chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now()-debugTime).count())
118 chrono::milliseconds maxFrameTime = chrono::milliseconds(1000/confData.
maxFPS);
122 typedef chrono::high_resolution_clock::time_point MyTimePoint;
123 MyTimePoint fpsStartTime = {};
125 while(window.isOpen()){
127 MyTimePoint startTime = chrono::high_resolution_clock::now();
128 if(fpsStartTime.time_since_epoch()==chrono::seconds(0)){
129 fpsStartTime = startTime;
135 if(manageInvaders()) {
144 remCollidingProjectiles();
146 remCollidingProjectiles();
148 checkMissilesAndPlayers();
157 MyTimePoint endTime = chrono::high_resolution_clock::now();
160 if(fpsStartTime+chrono::seconds(1) < endTime){
166 this_thread::sleep_until(startTime+maxFrameTime);
172Position Game::invIndexToPos(
unsigned x,
unsigned y)
const {
177 return all_of(players.begin(), players.end(), [](
Player& p) ->
bool {return p.isEliminated();});
void managedGames()
manages and changes the states of the game
WinValue enterGameLoop()
enter the main gameplay game loop
Game()
constructor for the game class
bool arePlayersDead()
tells if all players are dead
GodState state
god's current state
unsigned validColsNumber() const
vector< ScoreLink > scores
list of pairs of player names and their score
void writeFile() const
write the score list into the score file
void inputScore(string name, unsigned score)
add player name and their score in the list of scores
full game logic and display management
unsigned startXPosition
players horizontal start position
unsigned playersLives
player life points
InvadersGrid grid
Invader type matrix.
unsigned playersWidth
player horizontal size in pixel
unsigned maxFPS
maximum framerate at which the game will run
nsGraphics::Vec2D Position
WinValue
list of win values