18#define WININIT window("SUPER Space Invader : Turbo Apocalypse DX - VS GOD", Position(1280, 720), Position(128, 128), nsGraphics::KBlack)
23 throw runtime_error(
"Initial config loading failed. Please check the error above and fix the configuration");
27 if(confData.theme==
"good"){
28 pm = std::make_unique<GoodPixelManager>(window);
29 }
else if(confData.theme==
"bad"){
30 pm = std::make_unique<PixelManager>(window);
31 }
else throw runtime_error(
"Invalid theme value : "+confData.theme+
32 "\nValid values are : good,bad");
34 cout <<
"Loading sprites..." << endl;
36 chrono::high_resolution_clock::time_point start = chrono::high_resolution_clock::now();
38 pm->loadSprites(tasks);
39 for(
Task& f : tasks)f.wait();
42 pm->leftHand.mirror(pm->rightHand);
44 chrono::high_resolution_clock::duration elapsed = chrono::high_resolution_clock::now()-start;
45 cout <<
"Done ! Time : " << chrono::duration_cast<chrono::milliseconds>(elapsed).count() <<
"ms" << endl;
50bool Game::areThereInvadersLeft(){
54void Game::handleScoreSaving(){
55 for(
unsigned i=0;i<players.size();++i){
57 pm->askPlayerNameMenu(i, players[i].score, pName);
70 playMode = pm->showInitialMenu();
102 for(
unsigned i=0;i<players.size();++i){
112#define START_TIMER() DEBUG_INSTR(debugTime = chrono::high_resolution_clock::now())
113#define PRINT_TIMER(X) DEBUG_MSG((X) << ": " << chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now()-debugTime).count())
117 chrono::milliseconds maxFrameTime = chrono::milliseconds(1000/confData.
maxFPS);
121 typedef chrono::high_resolution_clock::time_point MyTimePoint;
122 MyTimePoint fpsStartTime = {};
124 while(window.isOpen()){
126 MyTimePoint startTime = chrono::high_resolution_clock::now();
127 if(fpsStartTime.time_since_epoch()==chrono::seconds(0)){
128 fpsStartTime = startTime;
134 if(manageInvaders()) {
143 remCollidingProjectiles();
145 remCollidingProjectiles();
147 checkMissilesAndPlayers();
156 MyTimePoint endTime = chrono::high_resolution_clock::now();
159 if(fpsStartTime+chrono::seconds(1) < endTime){
165 this_thread::sleep_until(startTime+maxFrameTime);
171Position Game::invIndexToPos(
unsigned x,
unsigned y)
const {
176 return all_of(players.begin(), players.end(), [](
Player& p) ->
bool {return p.isEliminated();});
void managedGames()
start games managed by our class
WinValue enterGameLoop()
enter the main gameplay game loop. Will block until the game ends
void initGame()
Set or reset all the setting for a new game.
Game()
constructor for the game class
bool arePlayersDead()
tells if all players are dead
GodState state
god's current state
unsigned validColsNumber() const
Helper function for randomValidCol() that returns the number of valid column (at least one invader in...
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
Manages screen display with async sprite loading.
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
#define INV_GET_SINGLE_POS(i)
nsGraphics::Vec2D Position
WinValue
list of win values