Browse Source

Update level select and play state transitions

master
C. J. Howard 7 years ago
parent
commit
994a61f79d
6 changed files with 48 additions and 16 deletions
  1. +6
    -6
      src/application.cpp
  2. +14
    -0
      src/game/colony.cpp
  3. +2
    -0
      src/game/colony.hpp
  4. +10
    -2
      src/states/level-select-state.cpp
  5. +5
    -0
      src/states/main-menu-state.cpp
  6. +11
    -8
      src/states/play-state.cpp

+ 6
- 6
src/application.cpp View File

@ -1635,12 +1635,12 @@ void Application::selectNextLevel()
selectLevel(currentLevelIndex + 1);
// Setup camera tween
Vector3 difference = Vector3(ANTKEEPER_LEVEL_SPACING * currentLevelIndex, camera.getTranslation().y, camera.getTranslation().z) - camera.getTranslation();
Vector3 difference = Vector3(ANTKEEPER_LEVEL_SPACING * currentLevelIndex, surfaceCam->getTargetFocalPoint().y, surfaceCam->getTargetFocalPoint().z) - surfaceCam->getTargetFocalPoint();
cameraTranslationTween->setTime(0.0f);
cameraTranslationTween->setDuration(1.0f);
cameraTranslationTween->setStartValue(camera.getTranslation());
cameraTranslationTween->setStartValue(surfaceCam->getTargetFocalPoint());
cameraTranslationTween->setDeltaValue(difference);
cameraTranslationTween->setUpdateCallback(std::bind(&SceneObject::setTranslation, &camera, std::placeholders::_1));
cameraTranslationTween->setUpdateCallback(std::bind(&SurfaceCameraController::setTargetFocalPoint, surfaceCam, std::placeholders::_1));
cameraTranslationTween->start();
}
}
@ -1652,12 +1652,12 @@ void Application::selectPreviousLevel()
selectLevel(currentLevelIndex - 1);
// Setup camera tween
Vector3 difference = Vector3(ANTKEEPER_LEVEL_SPACING * currentLevelIndex, camera.getTranslation().y, camera.getTranslation().z) - camera.getTranslation();
Vector3 difference = Vector3(ANTKEEPER_LEVEL_SPACING * currentLevelIndex, surfaceCam->getTargetFocalPoint().y, surfaceCam->getTargetFocalPoint().z) - surfaceCam->getTargetFocalPoint();
cameraTranslationTween->setTime(0.0f);
cameraTranslationTween->setDuration(1.0f);
cameraTranslationTween->setStartValue(camera.getTranslation());
cameraTranslationTween->setStartValue(surfaceCam->getTargetFocalPoint());
cameraTranslationTween->setDeltaValue(difference);
cameraTranslationTween->setUpdateCallback(std::bind(&SceneObject::setTranslation, &camera, std::placeholders::_1));
cameraTranslationTween->setUpdateCallback(std::bind(&SurfaceCameraController::setTargetFocalPoint, surfaceCam, std::placeholders::_1));
cameraTranslationTween->start();
}
}

+ 14
- 0
src/game/colony.cpp View File

@ -35,7 +35,9 @@ Colony::Colony():
Colony::~Colony()
{
killAll();
delete antOctree;
delete pheromoneOctree;
}
Ant* Colony::spawn(Navmesh* navmesh, Navmesh::Triangle* triangle, const Vector3& position)
@ -77,3 +79,15 @@ void Colony::queryAnts(const BoundingVolume& volume, std::list* results)
{
antOctree->query(volume, results);
}
void Colony::killAll()
{
antOctree->clear();
pheromoneOctree->clear();
for (Ant* ant: ants)
{
delete ant;
}
ants.clear();
}

+ 2
- 0
src/game/colony.hpp View File

@ -54,6 +54,8 @@ public:
const Ant* getAnt(std::size_t index) const;
Ant* getAnt(std::size_t index);
void killAll();
const Octree<Agent*>* getAntOctree() const;
const Octree<Pheromone*>* getPheromoneOctree() const;

+ 10
- 2
src/states/level-select-state.cpp View File

@ -21,6 +21,7 @@
#include "main-menu-state.hpp"
#include "../application.hpp"
#include "../configuration.hpp"
#include "../camera-controller.hpp"
LevelSelectState::LevelSelectState(Application* application):
ApplicationState(application)
@ -45,7 +46,6 @@ void LevelSelectState::enter()
application->defaultLayer->addObject(subsurfaceInstance);
}
application->defaultLayer->addObject(&application->biomeFloorModelInstance);
//application->biomeFloorModelInstance.setTranslation(Vector3(0.0f, -ANTKEEPER_TERRAIN_BASE_HEIGHT, 0.0f));
application->levelIDLabel->setVisible(true);
application->levelNameLabel->setVisible(true);
@ -53,7 +53,12 @@ void LevelSelectState::enter()
application->selectWorld(0);
application->selectLevel(0);
application->camera.lookAt(Vector3(0, 150, 200), Vector3(0, 0, 0), Vector3(0, 1, 0));
// Setup camera controller
application->surfaceCam->setTargetFocalPoint(Vector3(0.0f));
application->surfaceCam->setTargetFocalDistance(350.0f);
application->surfaceCam->setTargetElevation(glm::radians(85.0f));
application->surfaceCam->setTargetAzimuth(0.0f);
application->surfaceCam->update(0.0f);
}
void LevelSelectState::execute()
@ -97,6 +102,9 @@ void LevelSelectState::execute()
//surfaceInstance->setRotation(rotation);
//subsurfaceInstance->setRotation(rotation);
}
// Update camera
application->surfaceCam->update(application->dt);
}
void LevelSelectState::exit()

+ 5
- 0
src/states/main-menu-state.cpp View File

@ -182,6 +182,9 @@ void MainMenuState::enter()
application->blackoutImage->setVisible(true);
application->fadeInTween->start();
application->backgroundLayer->addObject(&application->bgCamera);
application->backgroundLayer->addObject(&application->bgBatch);
// Add nest
application->defaultLayer->addObject(&application->nestModelInstance);
@ -283,6 +286,8 @@ void MainMenuState::exit()
// Clear scene
application->defaultLayer->removeObject(&application->nestModelInstance);
application->backgroundLayer->removeObject(&application->bgCamera);
application->backgroundLayer->removeObject(&application->bgBatch);
}
void MainMenuState::mouseButtonPressed(int button, int x, int y)

+ 11
- 8
src/states/play-state.cpp View File

@ -74,14 +74,14 @@ void PlayState::enter()
// Setup camera controller
application->surfaceCam->setCamera(&application->camera);
application->surfaceCam->setFocalPoint(Vector3(0.0f));
application->surfaceCam->setFocalDistance(250.0f);
application->surfaceCam->setElevation(glm::radians(35.0f));
application->surfaceCam->setAzimuth(glm::radians(-45.0f));
application->surfaceCam->setTargetFocalPoint(application->surfaceCam->getFocalPoint());
application->surfaceCam->setTargetFocalDistance(application->surfaceCam->getFocalDistance());
application->surfaceCam->setTargetElevation(application->surfaceCam->getElevation());
application->surfaceCam->setTargetAzimuth(application->surfaceCam->getAzimuth());
//application->surfaceCam->setFocalPoint(Vector3(0.0f));
//application->surfaceCam->setFocalDistance(250.0f);
//application->surfaceCam->setElevation(glm::radians(35.0f));
//application->surfaceCam->setAzimuth(glm::radians(-45.0f));
application->surfaceCam->setTargetFocalPoint(Vector3(0.0f));
application->surfaceCam->setTargetFocalDistance(250.0f);
application->surfaceCam->setTargetElevation(glm::radians(35.0f));
//application->surfaceCam->setTargetAzimuth(glm::radians(-45.0f));
application->surfaceCam->update(0.0f);
application->simulationPaused = false;
@ -233,6 +233,9 @@ void PlayState::exit()
application->defaultLayer->removeObject(ant->getModelInstance());
}
// Kill all ants
application->colony->killAll();
// Hide HUD
application->pauseButtonImage->setVisible(false);
application->pauseButtonImage->setActive(false);

Loading…
Cancel
Save