Skip to content

Commit

Permalink
Prepare new gamestate scene
Browse files Browse the repository at this point in the history
Prepares game scenes using newly created facilities.
This is the scene for the final presentation.
  • Loading branch information
Notiooo committed Jan 13, 2024
1 parent a5a3a59 commit 0cac5b0
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 40 deletions.
Binary file added AimGL/resources/Textures/welcome-screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion AimGL/src/Renderer/Graphics/3D/Sprite3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ class Sprite3D
glm::vec2 mScale;
glm::vec2 mDimensionsNormalized;
Rotation3D mRotation;
float mOpacity;
float mOpacity{1};
};
2 changes: 1 addition & 1 deletion AimGL/src/Renderer/Graphics/3D/Utils/Rotation3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Rotation3D& Rotation3D::operator*=(const Rotation3D& rhs)
return *this;
}

Rotation3D::operator glm::vec<3, float>()
Rotation3D::operator glm::vec<3, float>() const
{
return mRotation;
}
Expand Down
2 changes: 1 addition & 1 deletion AimGL/src/Renderer/Graphics/3D/Utils/Rotation3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Rotation3D
Rotation3D& operator-=(const Rotation3D&);
Rotation3D& operator*=(const Rotation3D&);
friend Rotation3D operator*(const Rotation3D& lhs, float rhs);
explicit operator glm::vec3();
explicit operator glm::vec3() const;

/**
* \brief Angles of Euler rotation.
Expand Down
43 changes: 13 additions & 30 deletions AimGL/src/States/CustomStates/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,30 @@ GameState::GameState(StateStack& stack, WindowToRender& window)
, mWindow(window)
, mPlayer(window, mColliderRegister)
, mRenderer(mWindow)
, mLogoTexture("resources/Textures/logo_background.png")
, mLogo(mLogoTexture)
, 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})
, mTree("resources/Models/tree/tree.obj",
{{"resources/Models/tree/tree_combined.png", Texture::Type::Diffuse}})
, mShootingRange(mColliderRegister, {-2, 0, 5.5})
, mSidewayMovingTargetsRange(mColliderRegister, {3, 0, 5.5})
, mWelcomeScreenTexture("resources/Textures/welcome-screen.png")
, mWelcomeScreen(mWelcomeScreenTexture)
{
Mouse::lockMouseAtCenter(mWindow);
mTree.setScale(0.2f);
mTree.setPosition({4, 0, 4}, Model::Origin::CenterBottom);
mLogo.setHeight(2.f);
mLogo.setPosition(glm::vec3(4, 0, 4), Sprite3D::Origin::LeftBottom);
mLogo.setRotation({225.f, 0.f, 0});
mLogo.setOpacity(1);
mWelcomeScreen.setScale(2);
mWelcomeScreen.setPosition({0, 1, -2}, Sprite3D::Origin::Center);
mGameBackground.setPosition({0, 0});
mPhaseInLogoColor.setPosition({0, 0});
mPhaseInClock.restart();

std::vector<glm::vec3> samplePreviewTargetsPositons = {
{2, 2, 2}, {2, 1, 2}, {2, 3, 2}, {2.5, 2, 2.6}, {3, 3, 3},
{3, 2, 1}, {1, 2, 3}, {0, 3, 2}, {0, 1, 1}, {0, 2, 4}};
for (auto& position: samplePreviewTargetsPositons)
{
auto test = std::make_unique<Target>(mColliderRegister, position);
mPreviewTargets.push_back(std::move(test));
}
}

void GameState::draw(sf::Window& target) const
{
MTR_SCOPE("GameState", "GameState::draw");
mGameBackground.draw(mRenderer);
mInfiniteGridFloor.draw(target, mPlayer.camera());
mTree.draw(mRenderer, mPlayer.camera());
mLogo.draw(mRenderer, mPlayer.camera());
mWelcomeScreen.draw(mRenderer, mPlayer.camera());
mPhaseInLogoColor.draw(mRenderer);

for (auto& previewTarget: mPreviewTargets)
{
previewTarget->draw(mRenderer, mPlayer.camera());
}
mShootingRange.draw(mRenderer, mPlayer.camera());
mSidewayMovingTargetsRange.draw(mRenderer, mPlayer.camera());
mPlayer.draw(mRenderer);
}

Expand All @@ -67,11 +50,9 @@ bool GameState::fixedUpdate(const float& deltaTime)
bool GameState::update(const float& deltaTime)
{
MTR_SCOPE("GameState", "GameState::update");
for (auto& previewTarget: mPreviewTargets)
{
previewTarget->update(deltaTime);
}
mPlayer.update(deltaTime);
mShootingRange.update(deltaTime);
mSidewayMovingTargetsRange.update(deltaTime);

if (mPhaseInLogoColor.opacity() > 0)
{
Expand All @@ -84,6 +65,8 @@ bool GameState::handleEvent(const sf::Event& event)
{
MTR_SCOPE("GameState", "GameState::handleEvent");
mPlayer.handleEvent(event);
mShootingRange.handleEvent(event);
mSidewayMovingTargetsRange.handleEvent(event);

if (event.type == sf::Event::KeyPressed)
{
Expand Down
12 changes: 6 additions & 6 deletions AimGL/src/States/CustomStates/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "World/InfiniteGridFloor.h"

#include <Player/Player.h>
#include <Renderer/Graphics/3D/Model.h>
#include <World/Physics/ColliderRegister.h>
#include <World/Scene/GameObjects/Target.h>
#include <World/Scene/GameObjects/ShootingRange.h>
#include <World/Scene/GameObjects/SidewayMovingTargetsRange.h>

class StateStack;

Expand Down Expand Up @@ -83,13 +83,13 @@ class GameState : public State
ColliderRegister mColliderRegister;
Player mPlayer;
Renderer mRenderer;
Texture mLogoTexture;
Sprite3D mLogo;
Rectangle2D mGameBackground;
sf::Clock mPhaseInClock;
Rectangle2D mPhaseInLogoColor;
InfiniteGridFloor mInfiniteGridFloor;
Model mTree;
std::vector<std::unique_ptr<Target>> mPreviewTargets;
ShootingRange mShootingRange;
SidewayMovingTargetsRange mSidewayMovingTargetsRange;
Texture mWelcomeScreenTexture;
Sprite3D mWelcomeScreen;
bool mDrawImgui{true};
};
1 change: 0 additions & 1 deletion AimGL/src/States/CustomStates/LogoState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,5 @@ bool LogoState::handleEvent(const sf::Event& event)
bool LogoState::updateImGui(const float& deltaTime)
{
MTR_SCOPE("LogoState", "LogoState::updateImGui");
ImGui::ShowDemoWindow();
return true;
}
5 changes: 5 additions & 0 deletions AimGL/src/World/Scene/GameObjects/Rifle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ void Rifle::draw(const Renderer& target) const
void Rifle::update(const float& deltaTime)
{
updateAttachToCamera(deltaTime);
if (mLatelyShotRay.has_value() and mShotRayClock.getElapsedTime() > mShotRayDeleteTime)
{
mLatelyShotRay.reset();
}
}

void Rifle::updateAttachToCamera(const float& deltaTime)
Expand Down Expand Up @@ -67,5 +71,6 @@ void Rifle::handleEvent(const sf::Event& event)
mGunShotSound.play();
mLatelyShotRay.emplace(mColliderRegister, mCamera.cameraPosition(), mCamera.direction());
mLatelyShotRay.value().colliderTag(ColliderTag::GunShot);
mShotRayClock.restart();
}
}
2 changes: 2 additions & 0 deletions AimGL/src/World/Scene/GameObjects/Rifle.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ class Rifle
std::optional<Ray> mLatelyShotRay;
std::vector<std::function<void(Ray)>> mRaySubscribers;
ColliderRegister& mColliderRegister;
sf::Clock mShotRayClock;
sf::Time mShotRayDeleteTime = sf::seconds(0.5);
};

0 comments on commit 0cac5b0

Please sign in to comment.