void GSMain::OnActive() { GameState::OnActive(); TheEventPoller::Instance()->AddListener(m_gui); TheLurker::Instance()->SetAsListener(true); TheSoundManager::Instance()->PlaySong("sound/apz2.it"); SceneNode::SetGlobalShowAABB(s_showAABBs); TheCollisionManager::Instance()->GetCollisionDetector()->Clear(); // Clear Text scene graph GetTextSceneGraph()->Clear(); // Set clear colour for game, TODO depends on skybox //AmjuGL::SetClearColour(Colour(0.0f, 0.0f, 1.0f, 1.0f)); m_exitState = NOT_EXITED; m_exitTimer = 0; GuiElement* splitLine = m_gui->GetElementByName("split-screen-line"); Assert(splitLine); splitLine->SetVisible(TheScores::Instance()->GetNumPlayers() == 2); m_pauseButton = (GuiButton*)m_gui->GetElementByName("pause-button"); Assert(m_pauseButton); m_pauseButton->SetCommand(OnPause); m_pauseButton->SetIsCancelButton(true); m_pauseButton->SetShowIfFocus(true); AmjuGL::SetClearColour(m_clearColour); // When we are in the play state, we DO want to go to the paused state // if we are interrupted (e.g. answer phone) TheGame::Instance()->RegisterPauseState(TheGSPaused::Instance()); NetSendMarkSessionStart(); }
void Hud::Draw() { float dt = TheTimer::Instance()->GetDt(); static const char* SCORE_NAME[3] = { "p1-score-text", "p2-score-text", "hi-score-text" }; static const float origSize[3] = { dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[0]))->GetFontSize(), dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[1]))->GetFontSize(), dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[2]))->GetFontSize() }; for (int i = 0; i < 3; i++) { if (s_scoreExpandTimer[i] > 0) { s_scoreExpandTimer[i] -= dt; if (s_scoreExpandTimer[i] < 0) { s_scoreExpandTimer[i] = 0; } GuiText* text = dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[i])); Assert(text); static const float EXPAND_SCALE = ROConfig()->GetFloat("hud-expand-scale"); text->SetFontSize(origSize[i] * (s_scoreExpandTimer[i] * EXPAND_SCALE + 1.0f)); std::string s = text->GetText(); text->SetText(""); text->SetText(s); // force tri list rebuild } } if (s_lifeTimer > 0) { s_lifeTimer -= dt; if (s_lifeTimer < 0) { s_lifeTimer = 0; } static const char* GUI_NAME[4] = { "heart-img1", "p1-lives-text", "heart-img2", "p2-lives-text" }; float t = s_lifeTimer * 10; bool vis = (((int)t % 2) == 0); for (int i = 0; i < 4; i++) { GuiElement* elem = m_gui->GetElementByName(GUI_NAME[i]); Assert(elem); elem->SetVisible(vis); } } m_gui->Draw(); }
void Hud::SetNumPlayers(int num) { GuiElement* elem = m_gui->GetElementByName("p2-comp"); Assert(elem); elem->SetVisible(num == 2); }