-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the state in which the main part of game will run (player training). In addition, the renderer improves the drawing of 2D objects to ignore the depth buffer, which would be problematic if 3D objects were also drawn.
- Loading branch information
Showing
11 changed files
with
221 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "GameState.h" | ||
#include "Renderer3D/Sprite3D.h" | ||
#include "States/StateStack.h" | ||
#include "Utils/Mouse.h" | ||
#include "pch.h" | ||
|
||
GameState::GameState(StateStack& stack, WindowToRender& window) | ||
: State(stack) | ||
, mWindow(window) | ||
, mRenderer3D(mWindow) | ||
, mLogoTexture("resources/Textures/logo_background.png") | ||
, mLogo(mLogoTexture) | ||
, mCamera(window) | ||
, mGameBackground(glm::vec2(1280, 720.f), glm::vec4(0.85f, 0.85f, 0.85f, 1.f)) | ||
, mPhaseInLogoColor({window.getSize().x, window.getSize().y}, {0.067f, 0.11f, 0.18f, 1.1f}) | ||
{ | ||
Mouse::lockMouseAtCenter(mWindow); | ||
mLogo.setHeight(2.f); | ||
mLogo.setPosition(glm::vec3(0, 0, 0), Sprite3D::Origin::LeftBottom); | ||
mLogo.setOpacity(1); | ||
mGameBackground.setPosition({0, 0}); | ||
mPhaseInLogoColor.setPosition({0, 0}); | ||
mPhaseInClock.restart(); | ||
mCamera.cameraPosition({1, 1.5, 2}); | ||
} | ||
|
||
void GameState::draw(sf::Window& target) const | ||
{ | ||
MTR_SCOPE("GameState", "GameState::draw"); | ||
mGameBackground.draw(mRenderer3D); | ||
mInfiniteGridFloor.draw(target, mCamera); | ||
mLogo.draw(mRenderer3D, mCamera); | ||
mPhaseInLogoColor.draw(mRenderer3D); | ||
} | ||
|
||
bool GameState::fixedUpdate(const float& deltaTime) | ||
{ | ||
MTR_SCOPE("GameState", "GameState::fixedUpdate"); | ||
mCamera.fixedUpdate(deltaTime); | ||
return true; | ||
} | ||
|
||
bool GameState::update(const float& deltaTime) | ||
{ | ||
MTR_SCOPE("GameState", "GameState::update"); | ||
mCamera.update(deltaTime); | ||
|
||
if (mPhaseInLogoColor.opacity() > 0) | ||
{ | ||
mPhaseInLogoColor.setOpacity(mPhaseInLogoColor.opacity() - deltaTime / 4.f); | ||
} | ||
return true; | ||
} | ||
|
||
bool GameState::handleEvent(const sf::Event& event) | ||
{ | ||
MTR_SCOPE("GameState", "GameState::handleEvent"); | ||
mCamera.handleEvent(event); | ||
|
||
if (event.type == sf::Event::KeyPressed) | ||
{ | ||
switch (event.key.code) | ||
{ | ||
case sf::Keyboard::Escape: Mouse::unlockMouse(mWindow); break; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
bool GameState::updateImGui(const float& deltaTime) | ||
{ | ||
MTR_SCOPE("GameState", "GameState::updateImGui"); | ||
mCamera.updateImGui(); | ||
ImGui::ShowDemoWindow(); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#pragma once | ||
|
||
#include "Renderer3D/Rectangle2D.h" | ||
#include "Renderer3D/Renderer3D.h" | ||
#include "Renderer3D/Sprite3D.h" | ||
#include "States/State.h" | ||
#include "World/Camera.h" | ||
#include "World/InfiniteGridFloor.h" | ||
|
||
class StateStack; | ||
|
||
/** | ||
* \brief The game state in which all the action of the game (player training) takes place. | ||
*/ | ||
class GameState : public State | ||
{ | ||
public: | ||
GameState(StateStack& stack, WindowToRender& window); | ||
|
||
/** | ||
* \brief Draws only this state to the passed target | ||
* \param target where it should be drawn to | ||
*/ | ||
void draw(sf::Window& target) const override; | ||
|
||
|
||
/** | ||
* \brief Updates the state logic at equal intervals independent of the frame rate. | ||
* \param deltaTime Time interval | ||
*/ | ||
bool fixedUpdate(const float& deltaTime) override; | ||
|
||
/** | ||
* \brief Updates the game logic dependent, or independent of time, every rendered frame. | ||
* \param deltaTime the time that has passed since the game was last updated. | ||
*/ | ||
bool update(const float& deltaTime) override; | ||
|
||
/** | ||
* \brief It takes input (event) from the user and interprets it | ||
* \param event user input | ||
*/ | ||
bool handleEvent(const sf::Event& event) override; | ||
|
||
/** | ||
* \brief Updates the imgui logic dependent, or independent of time, every rendered frame. | ||
* \param deltaTime the time that has passed since the game was last updated. | ||
*/ | ||
bool updateImGui(const float& deltaTime) override; | ||
|
||
private: | ||
WindowToRender& mWindow; | ||
Renderer3D mRenderer3D; | ||
Texture mLogoTexture; | ||
Sprite3D mLogo; | ||
Camera mCamera; | ||
Rectangle2D mGameBackground; | ||
sf::Clock mPhaseInClock; | ||
Rectangle2D mPhaseInLogoColor; | ||
InfiniteGridFloor mInfiniteGridFloor; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters