//----------------------------------------------------------------------------------- void TheGame::Update(float deltaSeconds) { if (InputSystem::instance->WasKeyJustPressed('D')) { g_renderDebug = !g_renderDebug; } if(InputSystem::instance->WasKeyJustPressed('1')) { SetGameState(GameState::MAIN_MENU); } else if (InputSystem::instance->WasKeyJustPressed('2')) { SetGameState(GameState::MAP_SELECTION); } else if (InputSystem::instance->WasKeyJustPressed('3')) { SetGameState(GameState::GENERATION); } else if (InputSystem::instance->WasKeyJustPressed('4')) { SetGameState(GameState::PLAYING); } else if (InputSystem::instance->WasKeyJustPressed('5')) { SetGameState(GameState::PAUSED); } switch(GetGameState()) { case GameState::MAIN_MENU: UpdateMainMenu(deltaSeconds); break; case GameState::MAP_SELECTION: EnvironmentBlueprint::LoadEnvironmentBlueprints(); UpdateMapSelection(deltaSeconds); break; case GameState::GENERATION: UpdateGeneration(deltaSeconds); break; case GameState::PLAYING: if (m_player == nullptr) { m_player = new Player(); SpawnInGame(m_player); m_currentMap->UpdateFOVFrom(m_player->m_position, m_player->m_viewDistance); for (int i = 0; i < NPCFactory::s_NPCFactories.size(); ++i) { NPC* enemyPointer = NPCFactory::GetNPCAt(i); SpawnInGame(enemyPointer); } } UpdatePlaying(deltaSeconds); break; case GameState::PAUSED: UpdatePaused(deltaSeconds); break; } MessageLog::instance->Update(deltaSeconds); }
State* MainMenuState::Update(float deltaSeconds) { State* state = SwitchStates(); if (nullptr == state) { UpdateMainMenu(deltaSeconds); } return state; }
void GameApp::Update(float timestep){ button_movement_counter += timestep; audio->update(timestep); switch (state){ case MAIN_MENU: UpdateMainMenu(timestep); break; case GAMEPLAY: UpdateGamePlay(timestep); break; case GAME_OVER: UpdateGameOver(timestep); break; case PAUSE: UpdatePause(timestep); break; } }
int main( int argc, char* argv[] ) { Initialise( iScreenWidth, iScreenHeight, false, "Just Another Retro Pew Pew" ); SetBackgroundColour( SColour( 000, 000, 000, 000 ) ); // player.SetSpriteID(CreateSprite( "./images/player.png", player.GetWidth(), player.GetHeight(), true)); GameStates eCurrentState = eMAIN_MENU; do { ClearScreen(); float fDeltaT = GetDeltaTime(); switch (eCurrentState) { case eMAIN_MENU: UpdateMainMenu(); if( IsKeyDown( KEY_ENTER) ) { eCurrentState = eGAMEPLAY; } break; case eGAMEPLAY: UpdateGameState(); if( IsKeyDown( KEY_ESCAPE) ) { eCurrentState = eMAIN_MENU; } break; default: break; } } while ( FrameworkUpdate() == false ); Shutdown(); return 0; }
void Game::Update() { // escape exits the program if(GetAsyncKeyState(VK_ESCAPE) < 0) { delete this; exit(0); } // if we havent started a game if(m_inMainMenu) { UpdateMainMenu(); } // if we are in a game else { // get the friction value of the track at the player cars position float friction = m_track->GetTileFriction(m_pMyCar->X(),m_pMyCar->Y()); // if there is resistance then lower the top speed of the car by half if(friction > 0) { m_pMyCar->SetTopSpeed(carTopSpeed / 3); // now apply the friction of the tile m_pMyCar->SetFriction(friction); } // else there is no resistance so set to full top speed else { m_pMyCar->SetTopSpeed(carTopSpeed); // set to the default friction m_pMyCar->SetFriction(defaultFriction); } // update movement m_pMyCar->Update(); // update the other car m_pOtherCar->Update(); // if we are using dead reckoning then // update what the remote side thinks if(m_packetTransferState == DEADRECKONING) { m_pMyCarRemote->Update(); // accelerate our remote view car if our car is faster if(m_pMyCarRemote->Speed() > m_otherCarLastSpeed) { m_pMyCarRemote->Accelerate(); m_carHasJustStopped = false; } else if(m_pMyCar->Speed() <= 0 && m_carHasJustStopped == false) { m_carHasJustStopped = true; } } // do our networking stuff DoNetworking(); // if the speed is greater than it was then we should accelerate if(m_pOtherCar->Speed() > m_otherCarLastSpeed) { m_pOtherCar->Accelerate(); } // process keyboard input ProcessInput(); //check if we pass the right checkpoint if(m_start->PointCollides(m_pMyCar->X(), m_pMyCar->Y()) && m_finishPassed == true) { m_startPassed = true; m_midCheckpointPassed = false; m_finishPassed = false; m_lapCount++; m_numPacketsSentPerLap = m_numPacketsSent; m_numPacketsSent = 0; } else if(m_midCheckpoint->PointCollides(m_pMyCar->X(), m_pMyCar->Y()) && m_startPassed == true) { m_startPassed = false; m_midCheckpointPassed = true; m_finishPassed = false; } else if(m_finish->PointCollides(m_pMyCar->X(), m_pMyCar->Y()) && m_midCheckpointPassed == true) { m_startPassed = false; m_midCheckpointPassed = false; m_finishPassed = true; } // 3 laps and the race is finished if(m_lapCount >= 3 && !m_raceFinished) { SendFinishRace(); } } }
int main( int argc, char* argv[] ) { Initialise(iScreenWidth, iScreenHeight, false, "Space Invaders"); SetBackgroundColour(SColour(0x00, 0x00, 0x00, 0xFF)); //player settings player.SetSize(64.0f, 32.0f); player.iSpriteID = CreateSprite("./images/cannon.png", player.fWidth, player.fHeight, true); player.SetMovementExtremes(0.0f, iScreenWidth); player.SetMovementKeys(65, 68); player.x = iScreenWidth * 0.5f; player.y = 88.0f; //create Marquee sprite iArcadeMarquee = CreateSprite("./images/Space-Invaders-Marquee.png", iScreenWidth, iScreenHeight, true); //enemy creation CreateEnemies(); enemyDirection = eRIGHT; nextDirection = eRIGHT; //font setting AddFont(pInvadersFont); //game state declaration GAMESTATES eCurrentState = eMAIN_MENU; //Game Loop do { float fDeltaT = GetDeltaTime(); switch (eCurrentState) { case eMAIN_MENU: UpdateMainMenu(); //input if (IsKeyDown(257) && !IsKeyDown(256)) { eCurrentState = eGAMEPLAY; ResetEnemies(); } break; case eGAMEPLAY: UpdateGameState(fDeltaT); //ChangeState if (IsKeyDown(256)) { eCurrentState = eMAIN_MENU; } break; default: break; } //clear screen ClearScreen(); } while(!FrameworkUpdate()); Shutdown(); return 0; }