Browse Source

Add basic ability to transition between all states

master
C. J. Howard 7 years ago
parent
commit
12deb67fc4
6 changed files with 63 additions and 15 deletions
  1. +1
    -1
      data
  2. +20
    -0
      src/game/colony.hpp
  3. +2
    -0
      src/states/level-select-state.cpp
  4. +6
    -2
      src/states/main-menu-state.cpp
  5. +29
    -9
      src/states/play-state.cpp
  6. +5
    -3
      src/states/title-state.cpp

+ 1
- 1
data

@ -1 +1 @@
Subproject commit b26170ae9513ded1bb38dcb6fa537a1a6c02a9df
Subproject commit c08b221aed4d3dbe82e8ffe5bc67d7b786993b28

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

@ -50,6 +50,10 @@ public:
void queryAnts(const BoundingVolume& volume, std::list<Agent*>* results) const; void queryAnts(const BoundingVolume& volume, std::list<Agent*>* results) const;
std::size_t getAntCount() const;
const Ant* getAnt(std::size_t index) const;
Ant* getAnt(std::size_t index);
const Octree<Agent*>* getAntOctree() const; const Octree<Agent*>* getAntOctree() const;
const Octree<Pheromone*>* getPheromoneOctree() const; const Octree<Pheromone*>* getPheromoneOctree() const;
@ -83,6 +87,22 @@ inline Model* Colony::getAntModel()
return antModel; return antModel;
} }
inline std::size_t Colony::getAntCount() const
{
return ants.size();
}
inline const Ant* Colony::getAnt(std::size_t index) const
{
return ants[index];
}
inline Ant* Colony::getAnt(std::size_t index)
{
return ants[index];
}
inline const Octree<Agent*>* Colony::getAntOctree() const inline const Octree<Agent*>* Colony::getAntOctree() const
{ {
return antOctree; return antOctree;

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

@ -109,6 +109,8 @@ void LevelSelectState::exit()
application->defaultLayer->removeObject(surfaceInstance); application->defaultLayer->removeObject(surfaceInstance);
application->defaultLayer->removeObject(subsurfaceInstance); application->defaultLayer->removeObject(subsurfaceInstance);
} }
application->defaultLayer->removeObject(&application->biomeFloorModelInstance);
application->levelIDLabel->setVisible(false); application->levelIDLabel->setVisible(false);
application->levelNameLabel->setVisible(false); application->levelNameLabel->setVisible(false);
} }

+ 6
- 2
src/states/main-menu-state.cpp View File

@ -18,6 +18,7 @@
*/ */
#include "main-menu-state.hpp" #include "main-menu-state.hpp"
#include "title-state.hpp"
#include "../application.hpp" #include "../application.hpp"
#include "../debug.hpp" #include "../debug.hpp"
#include "../camera-controller.hpp" #include "../camera-controller.hpp"
@ -235,7 +236,7 @@ void MainMenuState::execute()
} }
else if (application->menuCancel.isTriggered() && !application->menuCancel.wasTriggered()) else if (application->menuCancel.isTriggered() && !application->menuCancel.wasTriggered())
{ {
application->changeState(application->titleState);
} }
float lineHeight = application->menuFont->getMetrics().getHeight(); float lineHeight = application->menuFont->getMetrics().getHeight();
@ -277,7 +278,10 @@ void MainMenuState::execute()
void MainMenuState::exit() void MainMenuState::exit()
{ {
// Remove nest
// Hide UI
application->menuSelectorLabel->setVisible(false);
// Clear scene
application->defaultLayer->removeObject(&application->nestModelInstance); application->defaultLayer->removeObject(&application->nestModelInstance);
} }

+ 29
- 9
src/states/play-state.cpp View File

@ -18,6 +18,7 @@
*/ */
#include "play-state.hpp" #include "play-state.hpp"
#include "level-select-state.hpp"
#include "../application.hpp" #include "../application.hpp"
#include "../camera-controller.hpp" #include "../camera-controller.hpp"
#include "../game/colony.hpp" #include "../game/colony.hpp"
@ -47,13 +48,10 @@ void PlayState::enter()
// Setup tools // Setup tools
application->forcepsClosed = false; application->forcepsClosed = false;
// Add background
//application->backgroundLayer->addObject(&application->bgCamera);
//application->backgroundLayer->addObject(&application->bgBatch);
// Add terrain to scene // Add terrain to scene
application->defaultLayer->addObject(&application->currentLevel->terrainSurface); application->defaultLayer->addObject(&application->currentLevel->terrainSurface);
application->defaultLayer->addObject(&application->currentLevel->terrainSubsurface); application->defaultLayer->addObject(&application->currentLevel->terrainSubsurface);
application->defaultLayer->addObject(&application->biomeFloorModelInstance);
// Add forceps to scene // Add forceps to scene
application->defaultLayer->addObject(&application->forcepsModelInstance); application->defaultLayer->addObject(&application->forcepsModelInstance);
@ -116,7 +114,11 @@ void PlayState::execute()
//application->blaImage->setRotation(iconRotation); //application->blaImage->setRotation(iconRotation);
// Return to level select
if (application->menuCancel.isTriggered() && !application->menuCancel.wasTriggered())
{
application->changeState(application->levelSelectState);
}
// Move camera // Move camera
Vector2 movementVector(0.0f); Vector2 movementVector(0.0f);
@ -217,11 +219,29 @@ void PlayState::execute()
void PlayState::exit() void PlayState::exit()
{ {
// Remove background
//application->backgroundLayer->removeObject(&application->bgCamera);
//application->backgroundLayer->removeObject(&application->bgBatch);
// Remove input observers
application->mouse->removeMouseButtonObserver(this); application->mouse->removeMouseButtonObserver(this);
// Clear scene
application->defaultLayer->removeObject(&application->currentLevel->terrainSurface);
application->defaultLayer->removeObject(&application->currentLevel->terrainSubsurface);
application->defaultLayer->removeObject(&application->biomeFloorModelInstance);
application->defaultLayer->removeObject(&application->forcepsModelInstance);
for (std::size_t i = 0; i < application->colony->getAntCount(); ++i)
{
Ant* ant = application->colony->getAnt(i);
application->defaultLayer->removeObject(ant->getModelInstance());
}
// Hide HUD
application->pauseButtonImage->setVisible(false);
application->pauseButtonImage->setActive(false);
application->playButtonImage->setVisible(false);
application->playButtonImage->setActive(false);
application->rectangularPaletteImage->setVisible(false);
application->rectangularPaletteImage->setActive(false);
application->toolbar->getContainer()->setVisible(false);
application->toolbar->getContainer()->setActive(false);
} }
void PlayState::mouseButtonPressed(int button, int x, int y) void PlayState::mouseButtonPressed(int button, int x, int y)

+ 5
- 3
src/states/title-state.cpp View File

@ -169,16 +169,18 @@ void TitleState::execute()
void TitleState::exit() void TitleState::exit()
{ {
// Remove input observers
application->inputManager->removeWindowObserver(this);
// Hide UI
application->titleImage->setVisible(false); application->titleImage->setVisible(false);
application->anyKeyLabel->setVisible(false); application->anyKeyLabel->setVisible(false);
application->titleScreenInfoContainer->setVisible(false); application->titleScreenInfoContainer->setVisible(false);
// Remove objects from scene
// Remove clear scene
application->defaultLayer->removeObject(&application->antHillModelInstance); application->defaultLayer->removeObject(&application->antHillModelInstance);
application->backgroundLayer->removeObject(&application->bgCamera); application->backgroundLayer->removeObject(&application->bgCamera);
application->backgroundLayer->removeObject(&application->bgBatch); application->backgroundLayer->removeObject(&application->bgBatch);
application->inputManager->removeWindowObserver(this);
} }
void TitleState::windowClosed() void TitleState::windowClosed()

Loading…
Cancel
Save