/*! * * @file gameBasics.cpp * @author RUBINI Thomas * @author SIMAILA Djalim * @date January 2022 * @version 1.0 * @brief game basic mechanisms * */ #include #include #include "game.h" #include "playMode.h" #define WININIT window("SUPER Space Invader : Turbo Apocalypse DX - VS GOD", Position(1280, 720), Position(128, 128), nsGraphics::KBlack) Game::Game() : WININIT, pm(window) { if(!reloadConfig()){ throw runtime_error("Initial config loading failed. Please check the error above and fix the configuration"); } sm.readFile(); } bool Game::areThereInvadersLeft(){ return grid.validColsNumber() > 0; } void Game::handleScoreSaving(){ for(unsigned i=0;i 100 /*lambda value*/ && god.state==GodState::NONE) { awakeGod(); } } if(manageGod())return WinValue::PLAYERS; if(arePlayersDead())return WinValue::GOD; moveMissiles(); remCollidingProjectiles(); moveTorpedos(); remCollidingProjectiles(); checkMissilesAndPlayers(); if(checkTorpedosAndInvaders())return WinValue::PLAYERS; if(arePlayersDead())return WinValue::INVADERS; displayAll(); pm.endFrame(); MyTimePoint endTime = chrono::high_resolution_clock::now(); // This code is counted as part of frames, but that's not really something we can control if(fpsStartTime+chrono::seconds(1) < endTime){ fps = tmpFps; tmpFps = 0; fpsStartTime = {}; }else ++tmpFps; this_thread::sleep_until(startTime+maxFrameTime); } return WinValue::NOBODY; } Position Game::invIndexToPos(unsigned x, unsigned y) const { return basePos+Position(INV_GET_POS(x), INV_GET_POS(y)); } bool Game::arePlayersDead() { return all_of(players.begin(), players.end(), [](Player& p) -> bool {return p.isEliminated();}); }