Browse Source

Improve title screen

master
C. J. Howard 7 years ago
parent
commit
d258d9ebc6
8 changed files with 125 additions and 590 deletions
  1. +2
    -0
      CMakeLists.txt
  2. +1
    -1
      data
  3. +47
    -21
      src/application.cpp
  4. +8
    -1
      src/application.hpp
  5. +0
    -545
      src/states/experiment-state.cpp
  6. +50
    -0
      src/states/play-state.cpp
  7. +6
    -22
      src/states/play-state.hpp
  8. +11
    -0
      src/states/title-state.cpp

+ 2
- 0
CMakeLists.txt View File

@ -106,6 +106,8 @@ set(EXECUTABLE_SOURCES
${EXECUTABLE_SOURCE_DIR}/states/title-state.cpp ${EXECUTABLE_SOURCE_DIR}/states/title-state.cpp
${EXECUTABLE_SOURCE_DIR}/states/main-menu-state.hpp ${EXECUTABLE_SOURCE_DIR}/states/main-menu-state.hpp
${EXECUTABLE_SOURCE_DIR}/states/main-menu-state.cpp ${EXECUTABLE_SOURCE_DIR}/states/main-menu-state.cpp
${EXECUTABLE_SOURCE_DIR}/states/play-state.hpp
${EXECUTABLE_SOURCE_DIR}/states/play-state.cpp
${EXECUTABLE_SOURCE_DIR}/ui/ui.hpp ${EXECUTABLE_SOURCE_DIR}/ui/ui.hpp
${EXECUTABLE_SOURCE_DIR}/ui/ui.cpp ${EXECUTABLE_SOURCE_DIR}/ui/ui.cpp
${EXECUTABLE_SOURCE_DIR}/ui/tween.hpp ${EXECUTABLE_SOURCE_DIR}/ui/tween.hpp

+ 1
- 1
data

@ -1 +1 @@
Subproject commit 5c2d9e19f18fd4085ee0aa4096aa4d63e9e3edef
Subproject commit 1e82819229df7c2113938a1bc0ea35b6f3335493

+ 47
- 21
src/application.cpp View File

@ -25,6 +25,7 @@
#include "states/splash-state.hpp" #include "states/splash-state.hpp"
#include "states/title-state.hpp" #include "states/title-state.hpp"
#include "states/main-menu-state.hpp" #include "states/main-menu-state.hpp"
#include "states/play-state.hpp"
#include "debug.hpp" #include "debug.hpp"
#include "camera-controller.hpp" #include "camera-controller.hpp"
#include <cstdlib> #include <cstdlib>
@ -316,6 +317,7 @@ Application::Application(int argc, char* argv[]):
splashState = new SplashState(this); splashState = new SplashState(this);
titleState = new TitleState(this); titleState = new TitleState(this);
mainMenuState = new MainMenuState(this); mainMenuState = new MainMenuState(this);
playState = new PlayState(this);
// Setup loaders // Setup loaders
textureLoader = new TextureLoader(); textureLoader = new TextureLoader();
@ -561,13 +563,21 @@ bool Application::loadScene()
bool Application::loadUI() bool Application::loadUI()
{ {
// Load menu font
menuFont = new Font(512, 512);
// Load fonts
FontLoader* fontLoader = new FontLoader(); FontLoader* fontLoader = new FontLoader();
menuFont = new Font(512, 512);
if (!fontLoader->load("data/fonts/Varela-Regular.ttf", fontSizePX, menuFont)) if (!fontLoader->load("data/fonts/Varela-Regular.ttf", fontSizePX, menuFont))
{ {
std::cerr << "Failed to load font" << std::endl;
std::cerr << "Failed to load menu font" << std::endl;
} }
copyrightFont = new Font(256, 256);
if (!fontLoader->load("data/fonts/Varela-Regular.ttf", (int)(fontSizePX * 0.8f + 0.5f), copyrightFont))
{
std::cerr << "Failed to load copyright font" << std::endl;
}
delete fontLoader; delete fontLoader;
// Load UI textures // Load UI textures
@ -575,14 +585,16 @@ bool Application::loadUI()
textureLoader->setCubemap(false); textureLoader->setCubemap(false);
textureLoader->setMipmapChain(false); textureLoader->setMipmapChain(false);
textureLoader->setMaxAnisotropy(1.0f); textureLoader->setMaxAnisotropy(1.0f);
splashTexture = textureLoader->load("data/textures/splash.png");
titleTexture = textureLoader->load("data/textures/title.png");
splashTexture = textureLoader->load("data/textures/ui-splash.png");
titleTexture = textureLoader->load("data/textures/ui-title.png");
levelActiveTexture = textureLoader->load("data/textures/ui-level-active.png"); levelActiveTexture = textureLoader->load("data/textures/ui-level-active.png");
levelInactiveTexture = textureLoader->load("data/textures/ui-level-inactive.png"); levelInactiveTexture = textureLoader->load("data/textures/ui-level-inactive.png");
levelConnectorTexture = textureLoader->load("data/textures/ui-level-connector.png"); levelConnectorTexture = textureLoader->load("data/textures/ui-level-connector.png");
// Get strings // Get strings
std::string pressAnyKeyString; std::string pressAnyKeyString;
std::string copyrightString;
std::string versionString;
std::string backString; std::string backString;
std::string challengeString; std::string challengeString;
std::string experimentString; std::string experimentString;
@ -598,6 +610,8 @@ bool Application::loadUI()
std::string returnToMainMenuString; std::string returnToMainMenuString;
std::string quitToDesktopString; std::string quitToDesktopString;
strings.get("press-any-key", &pressAnyKeyString); strings.get("press-any-key", &pressAnyKeyString);
strings.get("copyright", &copyrightString);
strings.get("version", &versionString);
strings.get("back", &backString); strings.get("back", &backString);
strings.get("challenge", &challengeString); strings.get("challenge", &challengeString);
strings.get("experiment", &experimentString); strings.get("experiment", &experimentString);
@ -643,26 +657,38 @@ bool Application::loadUI()
titleImage = new UIImage(); titleImage = new UIImage();
titleImage->setAnchor(Vector2(0.5f, 0.0f)); titleImage->setAnchor(Vector2(0.5f, 0.0f));
titleImage->setDimensions(Vector2(titleTexture->getWidth(), titleTexture->getHeight())); titleImage->setDimensions(Vector2(titleTexture->getWidth(), titleTexture->getHeight()));
titleImage->setTranslation(Vector2(0.0f, (int)(height * (1.0f / 3.0f) - titleTexture->getHeight())));
titleImage->setTranslation(Vector2(0.0f, (int)(height * (1.0f / 4.0f) - titleTexture->getHeight() * 0.5f)));
titleImage->setTexture(titleTexture); titleImage->setTexture(titleTexture);
titleImage->setVisible(false); titleImage->setVisible(false);
uiRootElement->addChild(titleImage); uiRootElement->addChild(titleImage);
/*
copyrightImage = new UIImage();
copyrightImage->setAnchor(Vector2(0.5f, 1.0f));
copyrightImage->setDimensions(Vector2(copyrightTextureWidth, copyrightTextureHeight));
copyrightImage->setTranslation(Vector2(-.5f, (int)(-height * (1.0f / 10.0f) - copyrightTextureHeight * 0.5f)));
copyrightImage->setTexture(nullptr);
copyrightImage->setVisible(false);
uiRootElement->addChild(copyrightImage);
*/
// Create Title screen info element
titleScreenInfoContainer = new UIContainer();
titleScreenInfoContainer->setDimensions(Vector2(width, height));
titleScreenInfoContainer->setVisible(false);
uiRootElement->addChild(titleScreenInfoContainer);
// Create copyright element
copyrightLabel = new UILabel();
copyrightLabel->setAnchor(Vector2(0.0f, 1.0f));
copyrightLabel->setFont(copyrightFont);
copyrightLabel->setTranslation(Vector2((int)(width * 0.025f), (int)(-height * 0.025f)));
copyrightLabel->setText(copyrightString);
titleScreenInfoContainer->addChild(copyrightLabel);
// Create version element
versionLabel = new UILabel();
versionLabel->setAnchor(Vector2(1.0f, 1.0f));
versionLabel->setFont(copyrightFont);
versionLabel->setTranslation(Vector2((int)(-width * 0.025f), (int)(-height * 0.025f)));
versionLabel->setText(versionString);
titleScreenInfoContainer->addChild(versionLabel);
// Create "Press any key" element // Create "Press any key" element
anyKeyLabel = new UILabel(); anyKeyLabel = new UILabel();
anyKeyLabel->setAnchor(Vector2(0.5f, 1.0f)); anyKeyLabel->setAnchor(Vector2(0.5f, 1.0f));
anyKeyLabel->setFont(menuFont); anyKeyLabel->setFont(menuFont);
anyKeyLabel->setTranslation(Vector2(0.0f, (int)(-height * (1.0f / 3.0f)/* - menuFont->getMetrics().getHeight() * 0.5f*/)));
anyKeyLabel->setTranslation(Vector2(0.0f, (int)(-height * (1.0f / 4.0f) - menuFont->getMetrics().getHeight() * 0.5f)));
anyKeyLabel->setText(pressAnyKeyString); anyKeyLabel->setText(pressAnyKeyString);
anyKeyLabel->setVisible(false); anyKeyLabel->setVisible(false);
uiRootElement->addChild(anyKeyLabel); uiRootElement->addChild(anyKeyLabel);
@ -871,11 +897,11 @@ bool Application::loadUI()
tweener->addTween(titleFadeOutTween); tweener->addTween(titleFadeOutTween);
// Setup copyright tween // Setup copyright tween
copyrightFadeInTween = new Tween<Vector4>(EaseFunction::IN_CUBIC, 0.0f, 1.0f, Vector4(1.0f, 1.0f, 1.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f));
copyrightFadeInTween->setUpdateCallback(std::bind(UIElement::setTintColor, copyrightImage, std::placeholders::_1));
copyrightFadeInTween = new Tween<Vector4>(EaseFunction::IN_CUBIC, 0.0f, 1.0f, Vector4(0.0f, 0.0f, 0.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 0.5f));
copyrightFadeInTween->setUpdateCallback(std::bind(UIElement::setTintColor, titleScreenInfoContainer, std::placeholders::_1));
tweener->addTween(copyrightFadeInTween); tweener->addTween(copyrightFadeInTween);
copyrightFadeOutTween = new Tween<Vector4>(EaseFunction::OUT_CUBIC, 0.0f, 0.25f, Vector4(1.0f, 1.0f, 1.0f, 1.0f), Vector4(0.0f, 0.0f, 0.0f, -1.0f));
copyrightFadeOutTween->setUpdateCallback(std::bind(UIElement::setTintColor, copyrightImage, std::placeholders::_1));
copyrightFadeOutTween = new Tween<Vector4>(EaseFunction::OUT_CUBIC, 0.0f, 0.25f, Vector4(0.0f, 0.0f, 0.0f, 0.5f), Vector4(0.0f, 0.0f, 0.0f, -0.5f));
copyrightFadeOutTween->setUpdateCallback(std::bind(UIElement::setTintColor, titleScreenInfoContainer, std::placeholders::_1));
tweener->addTween(copyrightFadeOutTween); tweener->addTween(copyrightFadeOutTween);
// Setup "Press any key" tween // Setup "Press any key" tween
@ -896,7 +922,7 @@ bool Application::loadUI()
Vector4 menuFadeOutDeltaColor = Vector4(0.0f, 0.0f, 0.0f, -1.0f); Vector4 menuFadeOutDeltaColor = Vector4(0.0f, 0.0f, 0.0f, -1.0f);
float menuSlideInDuration = 0.35f; float menuSlideInDuration = 0.35f;
Vector2 menuSlideInStartTranslation = Vector2(-64.0f, 0.0f); Vector2 menuSlideInStartTranslation = Vector2(-64.0f, 0.0f);
Vector2 menuSlideInDeltaTranslation = Vector2(128.0f, 0.0f);
Vector2 menuSlideInDeltaTranslation = Vector2((int)(64.0f + width / 8.0f), 0.0f);
float levelSelectorSlideInDuration = 0.35f; float levelSelectorSlideInDuration = 0.35f;
Vector2 levelSelectorSlideInStartTranslation = Vector2(0.0f, levelActiveTexture->getHeight()); Vector2 levelSelectorSlideInStartTranslation = Vector2(0.0f, levelActiveTexture->getHeight());

+ 8
- 1
src/application.hpp View File

@ -42,6 +42,7 @@ class LoadingState;
class SplashState; class SplashState;
class TitleState; class TitleState;
class MainMenuState; class MainMenuState;
class PlayState;
class CameraController; class CameraController;
class SurfaceCameraController; class SurfaceCameraController;
class TunnelCameraController; class TunnelCameraController;
@ -129,6 +130,7 @@ public:
SplashState* splashState; SplashState* splashState;
TitleState* titleState; TitleState* titleState;
MainMenuState* mainMenuState; MainMenuState* mainMenuState;
PlayState* playState;
// Scene // Scene
Scene scene; Scene scene;
@ -213,6 +215,7 @@ public:
float fontSizePT; float fontSizePT;
float fontSizePX; float fontSizePX;
Font* menuFont; Font* menuFont;
Font* copyrightFont;
// UI textures // UI textures
Texture* splashTexture; Texture* splashTexture;
@ -228,7 +231,11 @@ public:
UIImage* blackoutImage; UIImage* blackoutImage;
UIImage* splashImage; UIImage* splashImage;
UIImage* titleImage; UIImage* titleImage;
UIImage* copyrightImage;
UIContainer* titleScreenInfoContainer;
UILabel* copyrightLabel;
UILabel* versionLabel;
UILabel* anyKeyLabel; UILabel* anyKeyLabel;
UILabel* menuSelectorLabel; UILabel* menuSelectorLabel;
UIContainer* mainMenuContainer; UIContainer* mainMenuContainer;

+ 0
- 545
src/states/experiment-state.cpp View File

@ -1,545 +0,0 @@
/*
* Copyright (C) 2017 Christopher J. Howard
*
* This file is part of Antkeeper Source Code.
*
* Antkeeper Source Code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper Source Code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "experiment-state.hpp"
#include "../application.hpp"
#include "../camera-controller.hpp"
#include "../ui/ui.hpp"
#include <iostream>
#include <SDL.h>
ExperimentState::ExperimentState(Application* application):
ApplicationState(application)
{}
ExperimentState::~ExperimentState()
{}
void drawShaft(LineBatcher* lineBatcher, const Shaft* shaft);
void drawChamber(LineBatcher* lineBatcher, const Chamber* chamber)
{
float helixAngle = chamber->parent->getHelixAngle(chamber->relativeDepth);
float minAngle = helixAngle - chamber->centralAngle * 0.5f;
float maxAngle = helixAngle + chamber->centralAngle * 0.5f;
// Find position on helix
Vector3 helixPosition = chamber->parent->getHelixPosition(chamber->relativeDepth);
helixPosition.y = -helixPosition.y;
// Move annulus toward helix by the inner radius
Vector3 helixDirection = glm::normalize(Vector3(std::cos(helixAngle), 0.0f, std::sin(helixAngle)));
Vector3 offset = helixPosition - helixDirection * (chamber->innerRadius - chamber->parent->shaftRadius);
int stepCount = 10;
float angleStep = chamber->centralAngle / (float)stepCount;
for (int i = 0; i < stepCount; ++i)
{
float angle0 = minAngle + angleStep * (float)i;
float angle1 = minAngle + angleStep * (float)(i + 1);
float x0 = std::cos(angle0);
float z0 = std::sin(angle0);
float x1 = std::cos(angle1);
float z1 = std::sin(angle1);
Vector3 innerStart;
innerStart.x = x0 * chamber->innerRadius;
innerStart.y = 0.0f;
innerStart.z = z0 * chamber->innerRadius;
Vector3 outerStart;
outerStart.x = x0 * chamber->outerRadius;
outerStart.y = 0.0f;
outerStart.z = z0 * chamber->outerRadius;
Vector3 innerEnd;
innerEnd.x = x1 * chamber->innerRadius;
innerEnd.y = 0.0f;
innerEnd.z = z1 * chamber->innerRadius;
Vector3 outerEnd;
outerEnd.x = x1 * chamber->outerRadius;
outerEnd.y = 0.0f;
outerEnd.z = z1 * chamber->outerRadius;
lineBatcher->draw(offset + innerStart, offset + innerEnd);
lineBatcher->draw(offset + outerStart, offset + outerEnd);
}
Vector3 leftWallStart;
leftWallStart.x = std::cos(minAngle) * chamber->innerRadius;
leftWallStart.y = 0.0f;
leftWallStart.z = std::sin(minAngle) * chamber->innerRadius;
Vector3 leftWallEnd;
leftWallEnd.x = std::cos(minAngle) * chamber->outerRadius;
leftWallEnd.y = 0.0f;
leftWallEnd.z = std::sin(minAngle) * chamber->outerRadius;
Vector3 rightWallStart;
rightWallStart.x = std::cos(maxAngle) * chamber->innerRadius;
rightWallStart.y = 0.0f;
rightWallStart.z = std::sin(maxAngle) * chamber->innerRadius;
Vector3 rightWallEnd;
rightWallEnd.x = std::cos(maxAngle) * chamber->outerRadius;
rightWallEnd.y = 0.0f;
rightWallEnd.z = std::sin(maxAngle) * chamber->outerRadius;
lineBatcher->draw(offset + leftWallStart, offset + leftWallEnd);
lineBatcher->draw(offset + rightWallStart, offset + rightWallEnd);
if (chamber->child != nullptr)
{
drawShaft(lineBatcher, chamber->child);
}
}
void drawShaft(LineBatcher* lineBatcher, const Shaft* shaft)
{
// Draw helix
int stepCount = 50;
float depthStep = shaft->shaftDepth / (float)stepCount;
for (int i = 0; i < stepCount; ++i)
{
Vector3 start = shaft->getHelixPosition((float)i * depthStep);
Vector3 end = shaft->getHelixPosition((float)(i + 1) * depthStep);
start.y = -start.y;
end.y = -end.y;
lineBatcher->draw(start, end);
}
// Draw children
for (const Chamber* chamber: shaft->children)
{
drawChamber(lineBatcher, chamber);
}
}
void ExperimentState::generateNest()
{
NestParameters params;
params.randomSeed = std::rand();
params.maxShaftGeneration = 2;
params.minShaftRadius = 0.0f;
params.maxShaftRadius = 0.0f;
params.minShaftDepth = 4.0f;
params.maxShaftDepth = 6.0f;
params.minShaftHelixRadius = 0.1f;
params.maxShaftHelixRadius = 1.0f;
params.minShaftHelixPitch = 0.25f;
params.maxShaftHelixPitch = 0.75f;
params.minShaftChamberCount = 1;
params.maxShaftChamberCount = 5;
params.minShaftChamberPitch = 0.5f;
params.maxShaftChamberPitch = 2.0f;
params.minChamberInnerRadius = 0.2f;
params.maxChamberInnerRadius = 0.2f;
params.minChamberOuterRadius = 0.5f;
params.maxChamberOuterRadius = 0.5f;
params.minChamberCentralAngle = glm::radians(240.0f);
params.maxChamberCentralAngle = glm::radians(240.0f);
nest.setParameters(params);
nest.generate();
// Draw nest
application->lineBatcher->setColor(Vector4(1.0f));
application->lineBatcher->setWidth(0.015f);
application->lineBatcher->begin();
drawShaft(application->lineBatcher, nest.getRootShaft());
application->lineBatcher->end();
}
void ExperimentState::enter()
{
std::cout << "Entering ExperimentState..." << std::endl;
std::srand(std::time(0));
// BG
application->bgBatch.resize(1);
BillboardBatch::Range* bgRange = application->bgBatch.addRange();
bgRange->start = 0;
bgRange->length = 1;
Billboard* bgBillboard = application->bgBatch.getBillboard(0);
bgBillboard->setDimensions(Vector2(1.0f, 1.0f));
bgBillboard->setTranslation(Vector3(0.5f, 0.5f, 0.0f));
bgBillboard->setTintColor(Vector4(1, 0, 0, 1));
application->bgBatch.update();
application->vignettePass.setRenderTarget(&application->defaultRenderTarget);
application->bgCompositor.addPass(&application->vignettePass);
application->bgCompositor.load(nullptr);
application->bgCamera.setOrthographic(0, 1.0f, 1.0f, 0, -1.0f, 1.0f);
application->bgCamera.lookAt(glm::vec3(0), glm::vec3(0, 0, -1), glm::vec3(0, 1, 0));
application->bgCamera.setCompositor(&application->bgCompositor);
application->bgCamera.setCompositeIndex(0);
application->bgScene.addLayer();
application->bgScene.getLayer(0)->addObject(&application->bgCamera);
application->bgScene.getLayer(0)->addObject(&application->bgBatch);
SceneLayer* terrainLayer = application->scene.addLayer();
SceneLayer* objectsLayer = application->scene.addLayer();
terrainLayer->addObject(&application->camera);
objectsLayer->addObject(&application->camera);
objectsLayer->addObject(application->antModelInstance);
objectsLayer->addObject(application->lineBatcher->getBatch());
// Create terrain
terrain.create(16, 16, Vector3(150.0f));
terrainLayer->addObject(terrain.getSurfaceModel()->createInstance());
terrainLayer->addObject(terrain.getSubsurfaceModel()->createInstance());
DirectionalLight* lightA = new DirectionalLight();
DirectionalLight* lightB = new DirectionalLight();
DirectionalLight* lightC = new DirectionalLight();
lightA->setColor(glm::vec3(1.0f));
lightB->setColor(glm::vec3(0.25f));
lightC->setColor(glm::vec3(1.0f, 1.0f, 1.0f));
lightA->setDirection(glm::normalize(glm::vec3(0.0, -0.8, -0.2)));
lightB->setDirection(glm::normalize(glm::vec3(1.0, -.2, 0.0f)));
lightC->setDirection(glm::normalize(glm::vec3(0.0, 1.0, 0.0)));
terrainLayer->addObject(lightA);
terrainLayer->addObject(lightB);
terrainLayer->addObject(lightC);
objectsLayer->addObject(lightA);
objectsLayer->addObject(lightB);
objectsLayer->addObject(lightC);
// Load compositor
application->defaultCompositor.unload();
RenderQueue renderQueue;
const std::list<SceneObject*>* objects = terrainLayer->getObjects();
for (const SceneObject* object: *objects)
renderQueue.queue(object);
objects = objectsLayer->getObjects();
for (const SceneObject* object: *objects)
renderQueue.queue(object);
RenderContext renderContext;
renderContext.camera = nullptr;
renderContext.layer = objectsLayer;
renderContext.queue = &renderQueue;
application->defaultCompositor.load(&renderContext);
application->camera.setPerspective(
glm::radians(25.0f),
(float)application->width / (float)application->height,
0.5f,
2000.0f);
// Setup camera controller
application->surfaceCam->setCamera(&application->camera);
application->surfaceCam->setFocalPoint(Vector3(0.0f));
application->surfaceCam->setFocalDistance(10.0f);
application->surfaceCam->setElevation(glm::radians(90.0f * (3.0f / 4.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->update(0.0f);
application->pauseMenuContainer->setVisible(false);
application->pauseMenuContainer->setActive(false);
// Generate nest
generateNest();
dragging = oldDragging = false;
application->inputManager->addWindowObserver(this);
application->mouse->addMouseButtonObserver(this);
windowResized(application->width, application->height);
// Start timer
timer.start();
}
void ExperimentState::execute()
{
// Calculate delta time (in seconds)
float dt = static_cast<float>(timer.microseconds().count()) / 1000000.0f;
timer.reset();
// Update controls
application->menuControlProfile->update();
application->gameControlProfile->update();
// Update input
oldDragging = dragging;
application->inputManager->update();
// Check if application was closed
if (application->inputManager->wasClosed() || application->escape.isTriggered())
{
application->close(EXIT_SUCCESS);
return;
}
// Check if fullscreen was toggled
if (application->toggleFullscreen.isTriggered() && !application->toggleFullscreen.wasTriggered())
{
application->changeFullscreen();
}
// Move camera
Vector2 movementVector(0.0f);
if (application->cameraMoveLeft.isTriggered())
movementVector.x -= application->cameraMoveLeft.getCurrentValue();
if (application->cameraMoveRight.isTriggered())
movementVector.x += application->cameraMoveRight.getCurrentValue();
if (application->cameraMoveForward.isTriggered())
movementVector.y -= application->cameraMoveForward.getCurrentValue();
if (application->cameraMoveBack.isTriggered())
movementVector.y += application->cameraMoveBack.getCurrentValue();
if (movementVector.x != 0.0f || movementVector.y != 0.0f)
{
movementVector *= 0.005f * application->surfaceCam->getFocalDistance() * dt / (1.0f / 60.0f);
application->surfaceCam->move(movementVector);
}
// Rotate camera
/*
if (application->cameraRotateCW.isTriggered() && !application->cameraRotateCW.wasTriggered())
application->surfaceCam->rotate(glm::radians(-90.0f));
if (application->cameraRotateCCW.isTriggered() && !application->cameraRotateCCW.wasTriggered())
application->surfaceCam->rotate(glm::radians(90.0f));
*/
float rotationSpeed = glm::radians(3.0f) * dt / (1.0f / 60.0f);
if (application->cameraRotateCW.isTriggered())
application->surfaceCam->rotate(-rotationSpeed);
if (application->cameraRotateCCW.isTriggered())
application->surfaceCam->rotate(rotationSpeed);
// Zoom camera
float zoomFactor = application->surfaceCam->getFocalDistance() / 20.0f * dt / (1.0f / 60.0f);
if (application->cameraZoomIn.isTriggered())
application->surfaceCam->zoom(zoomFactor * application->cameraZoomIn.getCurrentValue());
if (application->cameraZoomOut.isTriggered())
application->surfaceCam->zoom(-zoomFactor * application->cameraZoomOut.getCurrentValue());
// Enforce camera focal distance constraints
float minFocalDistance = 2.5f;
float maxFocalDistance = 1000.0f;
if (application->surfaceCam->getTargetFocalDistance() > maxFocalDistance)
{
application->surfaceCam->setTargetFocalDistance(maxFocalDistance);
}
else if (application->surfaceCam->getTargetFocalDistance() < minFocalDistance)
{
application->surfaceCam->setTargetFocalDistance(minFocalDistance);
}
// Enforce camera focal point constraints
float worldSize = 150.0f;
Vector3 boundsMin = Vector3(-worldSize * 0.5f, 0.0f, -worldSize * 0.5f);
Vector3 boundsMax = Vector3(worldSize * 0.5f, 0.0f, worldSize * 0.5f);
Vector3 targetFocalPoint = application->surfaceCam->getTargetFocalPoint();
targetFocalPoint.x = std::max(boundsMin.x, std::min(boundsMax.x, targetFocalPoint.x));
targetFocalPoint.z = std::max(boundsMin.z, std::min(boundsMax.z, targetFocalPoint.z));
application->surfaceCam->setTargetFocalPoint(targetFocalPoint);
// Fixed camera angles
float overheadViewElevation = glm::radians(90.0f * (3.0f / 4.0f));
float tiltedViewElevation = glm::radians(30.0f);
float nestViewElevation = glm::radians(0.0f);
// Toggle overhead view
if (!application->cameraNestView)
{
if (application->cameraToggleOverheadView.isTriggered() && !application->cameraToggleOverheadView.wasTriggered())
{
application->cameraOverheadView = !application->cameraOverheadView;
float elevation = (application->cameraOverheadView) ? overheadViewElevation : tiltedViewElevation;
application->surfaceCam->setTargetElevation(elevation);
}
}
// Toggle nest view
if (application->cameraToggleNestView.isTriggered() && !application->cameraToggleNestView.wasTriggered())
{
application->cameraNestView = !application->cameraNestView;
float elevation = (application->cameraNestView) ? nestViewElevation : (application->cameraOverheadView) ? overheadViewElevation : tiltedViewElevation;
application->surfaceCam->setTargetElevation(elevation);
}
if (application->menuSelect.isTriggered() && !application->menuSelect.wasTriggered())
{
generateNest();
}
application->surfaceCam->update(dt);
// Picking
// Pick!!!
glm::ivec2 mousePosition = application->mouse->getCurrentPosition();
mousePosition.y = application->height - mousePosition.y;
Vector4 viewport(0.0f, 0.0f, application->width, application->height);
Vector3 mouseNear = application->camera.unproject(Vector3(mousePosition.x, mousePosition.y, 0.0f), viewport);
Vector3 mouseFar = application->camera.unproject(Vector3(mousePosition.x, mousePosition.y, 1.0f), viewport);
Ray pickingRay;
pickingRay.origin = mouseNear;
pickingRay.direction = glm::normalize(mouseFar - mouseNear);
Vector3 pick;
/*
if (dragging)
{
auto result = pickingRay.intersects(*terrain.getSurfaceMesh());
if (std::get<0>(result))
{
pick = pickingRay.extrapolate(std::get<1>(result));
}
else
{
Plane plane;
plane.set(Vector3(0, 1, 0), Vector3(0.0f));
auto result = pickingRay.intersects(plane);
pick = pickingRay.extrapolate(std::get<1>(result));
}
Transform xf = Transform::getIdentity();
xf.translation = pick;
application->antModelInstance->setTransform(xf);
if (!oldDragging)
{
dragStart = pick;
}
dragEnd = pick;
Vector3 dragMin;
dragMin.x = std::min(dragStart.x, dragEnd.x);
dragMin.y = std::min(dragStart.y, dragEnd.y);
dragMin.z = std::min(dragStart.z, dragEnd.z);
Vector3 dragMax;
dragMax.x = std::max(dragStart.x, dragEnd.x);
dragMax.y = std::max(dragStart.y, dragEnd.y);
dragMax.z = std::max(dragStart.z, dragEnd.z);
float halfWorldSize = worldSize * 0.5f;
application->clippingPlaneOffsets[0] = Vector3(dragMax.x, -halfWorldSize, 0.0f);
application->clippingPlaneOffsets[1] = Vector3(0.0f, -halfWorldSize, dragMin.z);
application->clippingPlaneOffsets[2] = Vector3(dragMin.x, -halfWorldSize, 0.0f);
application->clippingPlaneOffsets[3] = Vector3(0.0f, -halfWorldSize, dragMax.z);
}
*/
// Calculate clipping planes
float halfWorldSize = worldSize * 0.5f;
application->lineBatcher->getBatch()->update();
// Perform tweening
application->tweener->update(dt);
// Update UI
application->uiRootElement->update();
// Clear to black
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Render background
application->renderer.render(application->bgScene);
// Render scene
application->renderer.render(application->scene);
// Form billboard batch for UI then render UI scene
application->uiBatcher->batch(application->uiBatch, application->uiRootElement);
application->renderer.render(application->uiScene);
// Swap buffers
SDL_GL_SwapWindow(application->window);
}
void ExperimentState::exit()
{
std::cout << "Exiting ExperimentState..." << std::endl;
application->inputManager->removeWindowObserver(this);
}
void ExperimentState::windowClosed()
{
application->close(EXIT_SUCCESS);
}
void ExperimentState::windowResized(int width, int height)
{
// Update application dimensions
application->width = width;
application->height = height;
if (application->fullscreen)
{
application->fullscreenWidth = width;
application->fullscreenHeight = height;
}
else
{
application->windowedWidth = width;
application->windowedHeight = height;
}
// Setup default render target
application->defaultRenderTarget.width = application->width;
application->defaultRenderTarget.height = application->height;
// UI camera
application->uiCamera.setOrthographic(0, application->width, application->height, 0, -1.0f, 1.0f);
// 3D camera
application->camera.setPerspective(
glm::radians(25.0f),
(float)application->width / (float)application->height,
0.5f,
2000.0f);
}
void ExperimentState::mouseButtonPressed(int button, int x, int y)
{
dragging = true;
}
void ExperimentState::mouseButtonReleased(int button, int x, int y)
{
dragging = false;
}

+ 50
- 0
src/states/play-state.cpp View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2017 Christopher J. Howard
*
* This file is part of Antkeeper Source Code.
*
* Antkeeper Source Code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper Source Code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "play-state.hpp"
#include "../application.hpp"
PlayState::PlayState(Application* application):
ApplicationState(application)
{}
PlayState::~PlayState()
{}
void PlayState::enter()
{
// Start fade-in
application->fadeInTween->start();
}
void PlayState::execute()
{
}
void PlayState::exit()
{
}
void PlayState::mouseButtonPressed(int button, int x, int y)
{
}
void PlayState::mouseButtonReleased(int button, int x, int y)
{
}

src/states/experiment-state.hpp → src/states/play-state.hpp View File

@ -17,43 +17,27 @@
* along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef EXPERIMENT_STATE_HPP
#define EXPERIMENT_STATE_HPP
#ifndef PLAY_STATE_HPP
#define PLAY_STATE_HPP
#include "../application-state.hpp" #include "../application-state.hpp"
#include "../input.hpp" #include "../input.hpp"
#include "../debug.hpp"
#include "../game/nest.hpp"
#include "../game/terrain.hpp"
#include <emergent/emergent.hpp> #include <emergent/emergent.hpp>
using namespace Emergent; using namespace Emergent;
class ExperimentState: public ApplicationState, public WindowObserver, public MouseButtonObserver
class PlayState: public ApplicationState, public MouseButtonObserver
{ {
public: public:
ExperimentState(Application* application);
virtual ~ExperimentState();
PlayState(Application* application);
virtual ~PlayState();
virtual void enter(); virtual void enter();
virtual void execute(); virtual void execute();
virtual void exit(); virtual void exit();
virtual void windowClosed();
virtual void windowResized(int width, int height);
virtual void mouseButtonPressed(int button, int x, int y); virtual void mouseButtonPressed(int button, int x, int y);
virtual void mouseButtonReleased(int button, int x, int y); virtual void mouseButtonReleased(int button, int x, int y);
void generateNest();
private:
Timer timer;
Nest nest;
Terrain terrain;
bool dragging;
bool oldDragging;
Vector3 dragStart;
Vector3 dragEnd;
}; };
#endif // EXPERIMENT_STATE_HPP
#endif // PLAY_STATE_HPP

+ 11
- 0
src/states/title-state.cpp View File

@ -156,6 +156,8 @@ void TitleState::execute()
{ {
application->titleImage->setVisible(true); application->titleImage->setVisible(true);
application->titleFadeInTween->start(); application->titleFadeInTween->start();
application->titleScreenInfoContainer->setVisible(true);
application->copyrightFadeInTween->start();
} }
if (stateTime >= pressAnyKeyDelay && !application->anyKeyLabel->isVisible()) if (stateTime >= pressAnyKeyDelay && !application->anyKeyLabel->isVisible())
@ -206,6 +208,9 @@ void TitleState::execute()
application->titleImage->setTintColor(Vector4(1.0f)); application->titleImage->setTintColor(Vector4(1.0f));
application->anyKeyFadeInTween->start(); application->anyKeyFadeInTween->start();
application->anyKeyLabel->setVisible(true); application->anyKeyLabel->setVisible(true);
application->copyrightFadeInTween->stop();
application->titleScreenInfoContainer->setVisible(true);
application->titleScreenInfoContainer->setTintColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
} }
else if (substate == 1) else if (substate == 1)
{ {
@ -216,6 +221,8 @@ void TitleState::execute()
application->anyKeyFadeInTween->stop(); application->anyKeyFadeInTween->stop();
application->anyKeyFadeOutTween->stop(); application->anyKeyFadeOutTween->stop();
application->anyKeyLabel->setVisible(false); application->anyKeyLabel->setVisible(false);
application->copyrightFadeInTween->stop();
application->copyrightFadeOutTween->start();
application->antHillZoomInTween->start(); application->antHillZoomInTween->start();
@ -231,6 +238,10 @@ void TitleState::execute()
void TitleState::exit() void TitleState::exit()
{ {
application->titleImage->setVisible(false);
application->anyKeyLabel->setVisible(false);
application->titleScreenInfoContainer->setVisible(false);
// Remove objects from scene // Remove objects from scene
application->defaultLayer->removeObject(&application->antHillModelInstance); application->defaultLayer->removeObject(&application->antHillModelInstance);

Loading…
Cancel
Save