diff --git a/AimGL/resources/Textures/welcome-screen.png b/AimGL/resources/Textures/welcome-screen.png new file mode 100644 index 0000000..5f3d82f Binary files /dev/null and b/AimGL/resources/Textures/welcome-screen.png differ diff --git a/AimGL/src/Renderer/Graphics/3D/Sprite3D.h b/AimGL/src/Renderer/Graphics/3D/Sprite3D.h index 4b92a4c..edfe426 100644 --- a/AimGL/src/Renderer/Graphics/3D/Sprite3D.h +++ b/AimGL/src/Renderer/Graphics/3D/Sprite3D.h @@ -114,5 +114,5 @@ class Sprite3D glm::vec2 mScale; glm::vec2 mDimensionsNormalized; Rotation3D mRotation; - float mOpacity; + float mOpacity{1}; }; diff --git a/AimGL/src/Renderer/Graphics/3D/Utils/Rotation3D.cpp b/AimGL/src/Renderer/Graphics/3D/Utils/Rotation3D.cpp index 3a5061d..b826031 100644 --- a/AimGL/src/Renderer/Graphics/3D/Utils/Rotation3D.cpp +++ b/AimGL/src/Renderer/Graphics/3D/Utils/Rotation3D.cpp @@ -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; } diff --git a/AimGL/src/Renderer/Graphics/3D/Utils/Rotation3D.h b/AimGL/src/Renderer/Graphics/3D/Utils/Rotation3D.h index d30a77f..75948c3 100644 --- a/AimGL/src/Renderer/Graphics/3D/Utils/Rotation3D.h +++ b/AimGL/src/Renderer/Graphics/3D/Utils/Rotation3D.h @@ -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. diff --git a/AimGL/src/States/CustomStates/GameState.cpp b/AimGL/src/States/CustomStates/GameState.cpp index 8a5d1b1..82a5e0f 100644 --- a/AimGL/src/States/CustomStates/GameState.cpp +++ b/AimGL/src/States/CustomStates/GameState.cpp @@ -12,32 +12,19 @@ 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 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(mColliderRegister, position); - mPreviewTargets.push_back(std::move(test)); - } } void GameState::draw(sf::Window& target) const @@ -45,14 +32,10 @@ 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); } @@ -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) { @@ -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) { diff --git a/AimGL/src/States/CustomStates/GameState.h b/AimGL/src/States/CustomStates/GameState.h index fd09907..0888efc 100644 --- a/AimGL/src/States/CustomStates/GameState.h +++ b/AimGL/src/States/CustomStates/GameState.h @@ -8,9 +8,9 @@ #include "World/InfiniteGridFloor.h" #include -#include #include -#include +#include +#include class StateStack; @@ -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> mPreviewTargets; + ShootingRange mShootingRange; + SidewayMovingTargetsRange mSidewayMovingTargetsRange; + Texture mWelcomeScreenTexture; + Sprite3D mWelcomeScreen; bool mDrawImgui{true}; }; diff --git a/AimGL/src/States/CustomStates/LogoState.cpp b/AimGL/src/States/CustomStates/LogoState.cpp index 8c58fc5..2711afe 100644 --- a/AimGL/src/States/CustomStates/LogoState.cpp +++ b/AimGL/src/States/CustomStates/LogoState.cpp @@ -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; } diff --git a/AimGL/src/World/Scene/GameObjects/Rifle.cpp b/AimGL/src/World/Scene/GameObjects/Rifle.cpp index ba0d474..e69022a 100644 --- a/AimGL/src/World/Scene/GameObjects/Rifle.cpp +++ b/AimGL/src/World/Scene/GameObjects/Rifle.cpp @@ -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) @@ -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(); } } \ No newline at end of file diff --git a/AimGL/src/World/Scene/GameObjects/Rifle.h b/AimGL/src/World/Scene/GameObjects/Rifle.h index 849cedb..2bb4b78 100644 --- a/AimGL/src/World/Scene/GameObjects/Rifle.h +++ b/AimGL/src/World/Scene/GameObjects/Rifle.h @@ -57,4 +57,6 @@ class Rifle std::optional mLatelyShotRay; std::vector> mRaySubscribers; ColliderRegister& mColliderRegister; + sf::Clock mShotRayClock; + sf::Time mShotRayDeleteTime = sf::seconds(0.5); }; \ No newline at end of file