void OgreApp::setPause(bool value) { if (value) { pause = value; player->pause(); OgreFramework::getSingletonPtr()->m_pSoundMgr->pauseAllSounds(); if (predictSessionOver()) { if (player->getName() == "subject999") globals.setMessage("Training is complete!\nPlease check in.\n\nDouble tap to exit.", MESSAGE_FINAL); else globals.setMessage("That's it for Today!\nPlease check in before you leave.\n\nYou completed: " + Util::toStringInt(player->getNumStagesWon()) + " stages!\n\nDouble tap to exit.", MESSAGE_FINAL); endGame(); } else { globals.appendMessage("\n\nSwipe to Continue", MESSAGE_NORMAL); #ifdef DEBUG_MODE globals.appendMessage("\n\n" + player->getSkillLevel().getCurrentStats(), MESSAGE_NORMAL); globals.appendMessage("\n\n" + Util::toStringInt(globals.sessionTime - getTotalElapsed()), MESSAGE_NORMAL); #endif } Ogre::ControllerManager::getSingleton().setTimeFactor(0); } else if (!sessionOver) { pause = value; player->unpause(); OgreFramework::getSingletonPtr()->m_pSoundMgr->resumeAllPausedSounds(); globals.clearMessage(); Ogre::ControllerManager::getSingleton().setTimeFactor(1); } }
void OgreApp::setLevel(Evaluation forced, bool forward) { globals.clearMessage(); std::vector<NavigationLevel> navLevels; if (tunnel) { levelMgr->updatePlayerSkill(tunnel, forced); if (forward) levelMgr->incrementSchedIndex(); else levelMgr->decrementSchedIndex(); navLevels = tunnel->getNavLevels(); player->unlink(); tunnel->unlink(); hud->unlink(); } // Don't gen a new tunnel if our schedule is over if (!predictSessionOver()) { tunnel = levelMgr->getNextLevel(tunnel); if (navLevels.size() <= 0) // First stage { globals.appendMessage("\n\nSession No: " + Util::toStringInt(player->getSkillLevel().sessionID), MESSAGE_NORMAL); } } // Link/Relink Pointers tunnel->link(player, hud); player->link(tunnel, hud); hud->init(tunnel, player); if (!predictSessionOver()) { // If repeated, repeat the same navigation level if (levelMgr->isRepeatingPhase()) tunnel->setNavigationLevels(navLevels); else tunnel->setNavigationLevels(); tunnel->constructTunnel(globals.tunnelSections); // If nback is same then panels are changing, keep speed same player->setCamPos(tunnel->getStart() + tunnel->getCurrent()->getForward() * globals.tunnelSegmentDepth); player->setCamRot(tunnel->getCurrent()->getQuaternion()); player->setDesireRot(player->getCamRot()); player->newTunnel(musicMode == MUSIC_ENABLED); Plane plane; switch (globals.setSkyBox) { case 0: plane.d = 3000; plane.normal = Ogre::Vector3(0, 0, 1); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->setSkyPlane(true, plane, "General/SpaceSkyPlane", 80, 4, true); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue::ZERO, 0.0, 300.0, 600.0); OgreFramework::getSingletonPtr()->m_pViewportMain->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.0f, 1.0f)); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->getSkyPlaneNode()->resetToInitialState(); break; case 1: plane.d = 160; plane.normal = Ogre::Vector3(0, 0, 1); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->setSkyPlane(true, plane, "General/TestSkyPlane0", 1.9, 1, true); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue(1.0, 0.95, 0.3, 0.0), 0.0, 500.0, 800.0); OgreFramework::getSingletonPtr()->m_pViewportMain->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.0f, 1.0f)); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->getSkyPlaneNode()->resetToInitialState(); break; default: plane.d = 3000; plane.normal = Ogre::Vector3(0, 0, 1); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->setSkyPlane(true, plane, "General/SpaceSkyPlane", 80, 4, true); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue::ZERO, 0.0, 300.0, 600.0); OgreFramework::getSingletonPtr()->m_pViewportMain->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.0f, 1.0f)); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->getSkyPlaneNode()->resetToInitialState(); break; } } // Stop the game setPause(true); }
void EngineStage::update(float elapsed) { switch (stageState) { case STAGE_STATE_INIT: { setup(); setPause(true); if (tunnel->getMode() != STAGE_MODE_RECESS || tunnel->getMode() != STAGE_MODE_TEACHING) globals.appendMessage("\n\nSet Your Speed", MESSAGE_NORMAL); stageState = STAGE_STATE_PAUSE; hud->update(elapsed); hud->setOverlay(0, true); hud->setOverlay(1, false); hud->setOverlay(2, false); hud->setOverlay(3, false); hud->notifyGoButton(false); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); break; } case STAGE_STATE_RUNNING: { OgreFramework::getSingletonPtr()->m_pSoundMgr->update(elapsed); #if defined(OGRE_IS_IOS) // Update the game state updateSpin(elapsed); #endif tunnel->update(elapsed); if (tunnel->needsCleaning()) { completeStage(EVEN); stageState = STAGE_STATE_PROMPT; setPause(true); std::string finalScoreMessage = Util::toStringInt(player->getScore()); globals.appendMessage("\nScore " + finalScoreMessage + "\n\nPlay Again?", MESSAGE_NORMAL); } hud->update(elapsed); hud->setOverlay(0, true); hud->setOverlay(1, false); hud->notifyGoButton(false); // Graphical view changes from camera, light, and skybox Quaternion camRot = player->getCombinedRotAndRoll(); OgreFramework::getSingletonPtr()->m_pCameraMain->setPosition(player->getCamPos()); OgreFramework::getSingletonPtr()->m_pCameraMain->setOrientation(camRot); if (OgreFramework::getSingletonPtr()->m_pSceneMgrMain->getSkyPlaneNode()) OgreFramework::getSingletonPtr()->m_pSceneMgrMain->getSkyPlaneNode()->setOrientation(player->getCombinedRotAndRoll()); if (lightNode) lightNode->setPosition(OgreFramework::getSingletonPtr()->m_pCameraMain->getPosition()); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); // See by the end of this frame if we have a tutorial popup, if so pause the game, keep the music running if (player->getTutorialMgr()->isVisible()) { setPause(true, false); globals.appendMessage("\n\nPaused", MESSAGE_NORMAL); stageState = STAGE_STATE_PAUSE; } break; } case STAGE_STATE_PAUSE: { // Navigation Debug Keys if (player->getKeyUp()) player->move(Vector3(player->getCamForward() * globals.initCamSpeed * elapsed)); if (player->getKeyDown()) player->move(Vector3(player->getCamForward() * -globals.initCamSpeed * elapsed)); if (player->getKeyLeft()) player->move(Vector3(player->getCamRight() * -globals.initCamSpeed * elapsed)); if (player->getKeyRight()) player->move(Vector3(player->getCamRight() * globals.initCamSpeed * elapsed)); OgreFramework::getSingletonPtr()->m_pCameraMain->setPosition(player->getCamPos()); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); if (!player->hasTriggeredStartup()) { int sliderSpeed = hud->getSpeedSlider()->getIndex(); globals.initCamSpeed = Util::clamp(sliderSpeed, globals.minCamSpeed, globals.maxCamSpeed); player->setSpeedParameters(globals.initCamSpeed, globals.minCamSpeed, globals.maxCamSpeed); } hud->update(elapsed); hud->setOverlay(0, true); hud->setOverlay(1, false); hud->notifyGoButton(true); break; } case STAGE_STATE_PROMPT: { hud->update(elapsed); hud->setOverlay(0, true); hud->setOverlay(1, true); hud->notifyGoButton(false); OgreFramework::getSingletonPtr()->m_pSceneMgrMain->setAmbientLight(Ogre::ColourValue(0.1, 0.1, 0.1)); break; } case STAGE_STATE_DONE: { // Unpause Settings but without the sound deactivating engineStateMgr->requestPopEngine(); break; } } }
void EngineStage::keyPressed(const OIS::KeyEvent &keyEventRef) { switch (keyEventRef.key) { case OIS::KC_W: { player->setKeyUp(true); break; } case OIS::KC_A: { player->setKeyLeft(true); break; } case OIS::KC_S: { player->setKeyDown(true); break; } case OIS::KC_D: { player->setKeyRight(true); break; } case OIS::KC_SPACE: { player->setKeySpace(true); break; } case OIS::KC_LEFT: { activatePerformLeftMove(); break; } case OIS::KC_RIGHT: { activatePerformRightMove(); break; } case OIS::KC_UP: { activatePerformSwipeUp(); break; } case OIS::KC_DOWN: { activatePerformSwipeDown(); break; } case OIS::KC_1: { if (tunnel && tunnel->isMultiCollectionTask()) { player->setToggleBack(3); tunnel->respondToToggleCheat(); } break; } case OIS::KC_2: { if (tunnel && tunnel->isMultiCollectionTask()) { player->setToggleBack(2); tunnel->respondToToggleCheat(); } break; } case OIS::KC_3: { if (tunnel && tunnel->isMultiCollectionTask()) { player->setToggleBack(1); tunnel->respondToToggleCheat(); } break; } case OIS::KC_4: { if (tunnel && tunnel->isMultiCollectionTask()) { // Bad hack but // Don't show 3-Back for multi-collection tasks of 1 or less. if (player->getLevelRequestRow() > 0) player->setToggleBack(0); tunnel->respondToToggleCheat(); } break; } case OIS::KC_P: { if (stageState == STAGE_STATE_RUNNING) { setPause(true); globals.appendMessage("\n\nPaused", MESSAGE_NORMAL); stageState = STAGE_STATE_PAUSE; } else { setPause(false); stageState = STAGE_STATE_RUNNING; } break; } case OIS::KC_Z: { activatePerformBeginLongPress(); break; } case OIS::KC_X: { if (stageState == STAGE_STATE_RUNNING) player->performPowerUp("TractorBeam"); break; } case OIS::KC_C: { player->setPowerUp("TimeWarp", true); if (stageState == STAGE_STATE_RUNNING) player->performPowerUp("TimeWarp"); break; } case OIS::KC_V: { if (stageState == STAGE_STATE_RUNNING) player->performPowerUp("Shields"); break; } #ifdef DEBUG_MODE case OIS::KC_K: { if (stageState == STAGE_STATE_RUNNING) tunnel->setDone(FAIL); break; } case OIS::KC_L: { if (stageState == STAGE_STATE_RUNNING) tunnel->setDone(PASS); break; } case OIS::KC_G: { player->setGodMode(!player->getGodMode()); std::cout << "God Mode: " << player->getGodMode() << std::endl; break; } #endif default: break; } }
void EngineStage::setup() { globals.clearMessage(); // Dealloc data dealloc(); // Retrieve player skill and gen new tunnel PlayerLevel skillLevel = player->getSkillLevel(); // Setup player and tunnel params Vector3 origin = Vector3::ZERO; Vector3 forward = globals.tunnelReferenceForward; Quaternion rot = Quaternion(1, 0, 0, 0); //if (!configStageType(globals.configPath, globals.configBackup, "globalConfig")) // globals.setMessage("WARNING: Failed to read configuration", MESSAGE_ERROR); globals.maxCamSpeed = skillLevel.maxSpeed; globals.stageTotalTargets1 = globals.stageTotalSignals * (globals.podNBackChance / 100.0); globals.stageTotalTargets2 = globals.stageTotalSignals * (globals.podNBackChance / 100.0); globals.stageTotalTargets3 = globals.stageTotalSignals * (globals.podNBackChance / 100.0); StageMode nmode = STAGE_MODE_PROFICIENCY; StageRequest level = player->getLevels()->retrieveLevel(player->getLevelRequestRow(), player->getLevelRequestCol()); int nlevel = level.nback; switch (level.phase) { case 'A': { nmode = STAGE_MODE_COLLECTION; globals.signalTypes = std::vector<std::vector<PodInfo> >(4); globals.signalTypes[POD_SIGNAL_1].push_back(PodInfo(POD_SIGNAL_1, POD_FUEL, POD_COLOR_BLUE, POD_SHAPE_UNKNOWN, POD_SOUND_1)); globals.signalTypes[POD_SIGNAL_2].push_back(PodInfo(POD_SIGNAL_2, POD_FUEL, POD_COLOR_GREEN, POD_SHAPE_UNKNOWN, POD_SOUND_2)); globals.signalTypes[POD_SIGNAL_3].push_back(PodInfo(POD_SIGNAL_3, POD_FUEL, POD_COLOR_PINK, POD_SHAPE_UNKNOWN, POD_SOUND_3)); globals.signalTypes[POD_SIGNAL_4].push_back(PodInfo(POD_SIGNAL_4, POD_FUEL, POD_COLOR_YELLOW, POD_SHAPE_UNKNOWN, POD_SOUND_4)); //globals.setBigMessage(Util::toStringInt(nlevel) + "-Back"); globals.appendMessage("\nObtain matches by Color!", MESSAGE_NORMAL); break; } case 'B': { nmode = STAGE_MODE_COLLECTION; globals.signalTypes = std::vector<std::vector<PodInfo> >(4); globals.signalTypes[POD_SIGNAL_1].push_back(PodInfo(POD_SIGNAL_1, POD_FUEL, POD_COLOR_UNKNOWN, POD_SHAPE_DIAMOND, POD_SOUND_1)); globals.signalTypes[POD_SIGNAL_2].push_back(PodInfo(POD_SIGNAL_2, POD_FUEL, POD_COLOR_UNKNOWN, POD_SHAPE_SPHERE, POD_SOUND_2)); globals.signalTypes[POD_SIGNAL_3].push_back(PodInfo(POD_SIGNAL_3, POD_FUEL, POD_COLOR_UNKNOWN, POD_SHAPE_CONE, POD_SOUND_3)); globals.signalTypes[POD_SIGNAL_4].push_back(PodInfo(POD_SIGNAL_4, POD_FUEL, POD_COLOR_UNKNOWN, POD_SHAPE_TRIANGLE, POD_SOUND_4)); //globals.setBigMessage(Util::toStringInt(nlevel) + "-Back"); globals.appendMessage("Obtain matches by Shape!", MESSAGE_NORMAL); break; } case 'C': { nmode = STAGE_MODE_COLLECTION; globals.signalTypes = std::vector<std::vector<PodInfo> >(4); globals.signalTypes[POD_SIGNAL_1].push_back(PodInfo(POD_SIGNAL_1, POD_FUEL, POD_COLOR_HOLDOUT, POD_SHAPE_UNKNOWN, POD_SOUND_1)); globals.signalTypes[POD_SIGNAL_2].push_back(PodInfo(POD_SIGNAL_2, POD_FUEL, POD_COLOR_HOLDOUT, POD_SHAPE_UNKNOWN, POD_SOUND_2)); globals.signalTypes[POD_SIGNAL_3].push_back(PodInfo(POD_SIGNAL_3, POD_FUEL, POD_COLOR_HOLDOUT, POD_SHAPE_UNKNOWN, POD_SOUND_3)); globals.signalTypes[POD_SIGNAL_4].push_back(PodInfo(POD_SIGNAL_4, POD_FUEL, POD_COLOR_HOLDOUT, POD_SHAPE_UNKNOWN, POD_SOUND_4)); //globals.setBigMessage(Util::toStringInt(nlevel) + "-Back"); globals.setMessage("Obtain matches by only sound!", MESSAGE_NORMAL); break; } case 'D': nmode = STAGE_MODE_COLLECTION; globals.signalTypes = std::vector<std::vector<PodInfo> >(4); globals.signalTypes[POD_SIGNAL_1].push_back(PodInfo(POD_SIGNAL_1, POD_FUEL, POD_COLOR_BLUE, POD_SHAPE_DIAMOND, POD_SOUND_1)); globals.signalTypes[POD_SIGNAL_2].push_back(PodInfo(POD_SIGNAL_2, POD_FUEL, POD_COLOR_GREEN, POD_SHAPE_SPHERE, POD_SOUND_2)); globals.signalTypes[POD_SIGNAL_3].push_back(PodInfo(POD_SIGNAL_3, POD_FUEL, POD_COLOR_PINK, POD_SHAPE_CONE, POD_SOUND_3)); globals.signalTypes[POD_SIGNAL_4].push_back(PodInfo(POD_SIGNAL_4, POD_FUEL, POD_COLOR_YELLOW, POD_SHAPE_TRIANGLE, POD_SOUND_4)); //globals.setBigMessage(Util::toStringInt(nlevel) + "-Back"); globals.setMessage("Obtain matching signals!", MESSAGE_NORMAL); break; case 'E': nmode = STAGE_MODE_RECESS; globals.signalTypes.clear(); if (level.initCamSpeed <= 15) // For starting slower stages, be nicer globals.stageTotalCollections = (level.minCamSpeed + level.maxCamSpeed) / 3.0 * level.stageTime / Util::getModdedLengthByNumSegments(globals, globals.tunnelSegmentsPerPod); else globals.stageTotalCollections = (level.minCamSpeed + level.maxCamSpeed) / 2.5 * level.stageTime / Util::getModdedLengthByNumSegments(globals, globals.tunnelSegmentsPerPod); //globals.setBigMessage("Recess!"); globals.setMessage("Reach the end! Grab Fuel Cells!", MESSAGE_NORMAL); break; case 'F': nmode = STAGE_MODE_TEACHING; globals.signalTypes.clear(); //globals.setBigMessage("Training!"); globals.setMessage("Grab Fuel Cells!", MESSAGE_NORMAL); break; } globals.initCamSpeed = level.initCamSpeed; globals.minCamSpeed = level.minCamSpeed; globals.maxCamSpeed = level.maxCamSpeed; tunnel = new Tunnel( OgreFramework::getSingletonPtr()->m_pSceneMgrMain->getRootSceneNode(), origin + forward * (globals.tunnelSegmentWidth / 2), rot, globals.tunnelSegmentWidth, globals.tunnelSegmentDepth, globals.tunnelMinAngleTurn, globals.tunnelMaxAngleTurn, 1, // replace or remove... nmode, level.phase, // replace or remove... nlevel, level.stageTime, SOUTH, globals.tunnelSegmentsPerSection, globals.tunnelSegmentsPerPod, globals.tunnelSegmentsPerDistractors, globals.tunnelSegmentsPerPowerup, globals.signalTypes, level.powerups); tunnel->link(player); player->link(tunnel); tunnel->setHoldout(level.hasHoldout,level.holdoutFrequency); if (tunnel->getMode() == STAGE_MODE_RECESS) { // Assign nav levels in an incremental order specified by Liam's formula if the mode is recess // Therefore, the level parameter provided looks at the nav level provided as the starting index tunnel->setNavigationLevels(level.navLevels[0].level, globals.navMap.size() - 1, level.tunnelSectionsPerNavLevel); } else { // Otherwise, nav levels provided by the parameters tunnel->setNavigationLevels(level.navLevels, level.tunnelSectionsPerNavLevel); } tunnel->setCollectionCriteria(level.collectionCriteria); tunnel->constructTunnel(level.nameTunnelTile, globals.tunnelSections); player->newTunnel(level.nameMusic); player->setSpeedParameters(globals.initCamSpeed, globals.minCamSpeed, globals.maxCamSpeed); Util::setSkyboxAndFog(level.nameSkybox); /* if (skillLevel.set1Notify) globals.setBigMessage("Congratulations! You earned " + Util::toStringInt(nlevel) + "-Back!"); else { if (skillLevel.set1Rep >= 2) globals.setBigMessage(Util::toStringInt(nlevel) + "-Back. Challenge Round!"); else globals.setBigMessage(Util::toStringInt(nlevel) + "-Back"); } globals.setMessage("Match by Color!", MESSAGE_NORMAL); */ hud = new HudStage(player, tunnel); Quaternion camRot = player->getCombinedRotAndRoll(); // Set lighting lightMain = OgreFramework::getSingletonPtr()->m_pSceneMgrMain->createLight("StageLight"); lightMain->setDiffuseColour(1.0, 1.0, 1.0); lightMain->setSpecularColour(1.0, 1.0, 1.0); //lightMain->setAttenuation(10, 1.0, 0.0001, 0.0); lightNode = OgreFramework::getSingletonPtr()->m_pSceneMgrMain->getRootSceneNode()->createChildSceneNode("lightNode"); lightNode->attachObject(lightMain); // Set initial transformations for camera, light, skynode OgreFramework::getSingletonPtr()->m_pCameraMain->setPosition(player->getCamPos()); OgreFramework::getSingletonPtr()->m_pCameraMain->setOrientation(camRot); if (OgreFramework::getSingletonPtr()->m_pSceneMgrMain->getSkyPlaneNode()) OgreFramework::getSingletonPtr()->m_pSceneMgrMain->getSkyPlaneNode()->setOrientation(player->getCombinedRotAndRoll()); if (lightNode) lightNode->setPosition(OgreFramework::getSingletonPtr()->m_pCameraMain->getPosition()); // Set tutorial slides for certain thingies if (tunnel->getMode() == STAGE_MODE_RECESS || tunnel->getMode() == STAGE_MODE_TEACHING || tunnel->getHighestCriteria() <= 0) player->getTutorialMgr()->setSlides(TutorialManager::TUTORIAL_SLIDES_ZERO_BACK); if (tunnel->getHighestCriteria() == 1) player->getTutorialMgr()->setSlides(TutorialManager::TUTORIAL_SLIDES_ONE_BACK); if (tunnel->getHighestCriteria() == 2) player->getTutorialMgr()->setSlides(TutorialManager::TUTORIAL_SLIDES_TWO_BACK); if (tunnel->getPhase() == 'A') player->getTutorialMgr()->setSlides(TutorialManager::TUTORIAL_SLIDES_COLOR_SOUND); if (tunnel->getPhase() == 'B') player->getTutorialMgr()->setSlides(TutorialManager::TUTORIAL_SLIDES_SHAPE_SOUND); if (tunnel->getPhase() == 'C') player->getTutorialMgr()->setSlides(TutorialManager::TUTORIAL_SLIDES_SOUND_ONLY); if (tunnel->getPhase() == 'D') player->getTutorialMgr()->setSlides(TutorialManager::TUTORIAL_SLIDES_HOLDOUT); spinVelocity = 0.0f; spinVelocityTarget = 0.0f; damping = 0.0f; freeMotion = false; }