//============================================================================================================= void Game::Reset(const std::string& stagefile) { Clear(); UnapplyPowerup(); savedvars.health = avatar.Health; savedvars.maxhealth = avatar.MaxHealth; savedvars.integrity = avatar.Integrity; savedvars.maxintegrity = avatar.MaxIntegrity; savedvars.score = hud.Score; avatar.InitialPosition = D3DXVECTOR2(0, (GameVariables::ScreenHeight - avatar.Image->Size.y) * 0.5f); avatar.Bounds = D3DXVECTOR4(0, hud.Panel->Size.y, GameVariables::ScreenWidth, GameVariables::ScreenHeight - hud.Panel->Size.y); if( !distort && rendertarget && rendersurface && GameVariables::EnableShaders ) { if( game->DeviceCaps.VertexShaderVersion >= D3DVS_VERSION(2, 0) && game->DeviceCaps.PixelShaderVersion >= D3DPS_VERSION(2, 0) ) { distort = game->Content.LoadMaterial("distort.fx"); GameVariables::EnableShaders = (distort != NULL); } } if( !script.Compile(stagefile, *this) ) game->Application.Close(); RestartLevel(); }
void Game::NewGame() { PreviousScore = 0; CurrentLevel = 1; PreviousLevel = CurrentLevel; Lives = 3; SetBlackFlag(false); SetHelpFlag(false); SetIncreaseLivesFlag(false); RestartLevel(true); }
DGLE_RESULT DGLE_API Game::Update(uint uiDeltaTime) { bool key_escape, pause; pInput->GetKey(KEY_ESCAPE, key_escape); if (key_escape) pEngineCore->QuitEngine(); pInput->GetKey(KEY_P, pause); if (pause) { if (PauseChange) { Pause = !Pause; PauseChange = false; } } else PauseChange = true; if (!Pause) { bool key_right, key_left, key_down, key_up; pInput->GetKey(KEY_RIGHT, key_right); pInput->GetKey(KEY_LEFT, key_left); pInput->GetKey(KEY_DOWN, key_down); pInput->GetKey(KEY_UP, key_up); // update game objects GhostList().begin()->UpdateAngle(); if (key_right) { GhostList().begin()->SetDirection(true, true); GhostList().begin()->Update(); } else if (key_left) { GhostList().begin()->SetDirection(true, false); GhostList().begin()->Update(); } else if (key_down) { GhostList().begin()->SetDirection(false, true); GhostList().begin()->Update(); } else if (key_up) { GhostList().begin()->SetDirection(false, false); GhostList().begin()->Update(); } for (auto it = ++GhostList().begin(); it != GhostList().end(); ++it) it->Update(); // swallow score and special items for (auto it = cItemList().cbegin(); it != cItemList().cend();) { bool flag = false; if (IsBlackFlagSet()) for (auto this_ghost = ++cGhostList().cbegin(); this_ghost != cGhostList().cend(); ++this_ghost) if (this_ghost->Swallow(*it)) flag = true; if (cGhostList().cbegin()->Swallow(*it) || flag) it = ItemList().erase(it); else ++it; } if (CurrentLevel > PreviousLevel) { RestartLevel(false); PreviousLevel = CurrentLevel; } // swallow player and ghosts for (auto this_ghost = ++cGhostList().cbegin(); this_ghost != cGhostList().cend(); ++this_ghost) { if (this_ghost->Swallow(*cGhostList().cbegin())) { if (Lives > 1) { RestartLevel(true); Lives--; } else NewGame(); break; } else if (IsHelpFlagSet()) for (auto it = ++cGhostList().cbegin(); it != cGhostList().cend();) if (this_ghost->Swallow(*it)) it = GhostList().erase(it); else ++it; } // additional updating AI if (!(Counter % 15)) for (auto it = ++GhostList().begin(); it != GhostList().end(); ++it) it->UpdateAI(0.1, false); //0.25 ++Counter; } return S_OK; }