Example #1
0
void GSMain::Update()
{
  static Lurker* lurker = TheLurker::Instance();
  static Game* game = TheGame::Instance();
  SceneGraph* scenegraph = GetGameSceneGraph();

  lurker->Update();

  // Disable pause button if Lurk msg showing

  // Freeze if displaying tutorial text
  if (lurker->IsDisplayingMsg())
  {
    m_pauseButton->SetVisible(false);
    scenegraph->Update(); // DO still update the scene graph?
    // TODO Also still update Bird?
    GameObjects* objs = game->GetGameObjects();
    for (auto it = objs->begin(); it != objs->end(); ++it)
    {
      GameObject* obj = it->second;
      if (dynamic_cast<Bird*>(obj))
      {
        obj->Update();
      }
    }
  }
  else if (m_exitState == IS_EXITING)
  {
    m_pauseButton->SetVisible(false);
    scenegraph->Update(); // DO still update the scene graph?
    // TODO Also still update Bird?
    GameObjects* objs = game->GetGameObjects();
    for (auto it = objs->begin(); it != objs->end(); ++it)
    {
      GameObject* obj = it->second;
      if (dynamic_cast<Player*>(obj))
      {
        obj->Update();
      }
      Pet* pet = dynamic_cast<Pet*>(obj);
      if (pet && pet->IsTeleporting())
      {
        pet->Update();
      }
      if (dynamic_cast<Exit*>(obj))
      {
        obj->Update();
      }
    }
  }
  else
  {
    if (m_exitState == FINISHED_EXITING)
    {
      m_exitTimer += TheTimer::Instance()->GetDt();

      static const float EXIT_DELAY_2 = ROConfig()->GetFloat("exit-delay-2");

      if (m_exitTimer > EXIT_DELAY_2) 
      {
        game->SetCurrentState(TheGSLevelComplete::Instance());
      }
    }
    else
    {
      m_pauseButton->SetVisible(true);

      Player* player = Player::GetPlayer(AMJU_P1);
      float y = -(player->GetPos().y);
      DepthUpdate(y);
      TheProcGen::Instance()->AddLayerWhenReady(player->GetPos().x);

      ThePowerUpManager::Instance()->Update();  

      game->UpdateGameObjects();

      DeleteDeadObjects();

      TheCollisionManager::Instance()->Update();
      scenegraph->Update();
      TheShadowManager::Instance()->Update();
    }
  }
}