-
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 a shooting range that allows the player to shoot at moving targets. It has appropriate graphic instructions and its own logo and button to activate the shooting ranges. Has boxes that cover the targets.
- Loading branch information
Showing
4 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
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
91 changes: 91 additions & 0 deletions
91
AimGL/src/World/Scene/GameObjects/SidewayMovingTargetsRange.cpp
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,91 @@ | ||
#include "SidewayMovingTargetsRange.h" | ||
#include "pch.h" | ||
|
||
SidewayMovingTargetsRange::SidewayMovingTargetsRange(ColliderRegister& colliderRegister, | ||
const glm::vec3& position) | ||
: mButtonStand(colliderRegister, position) | ||
, mPosition(position) | ||
, mSmallerCrate(colliderRegister, position) | ||
, mMediumCrate(colliderRegister, position) | ||
, mLargeCrate(colliderRegister, position) | ||
, mDirectionArrowTexture("resources/Textures/arrow-up.png") | ||
, mDirectionArrowPointingButton(mDirectionArrowTexture) | ||
, mTrainingLogoTexture("resources/Textures/moving-targets.png") | ||
, mTrainingLogo(mTrainingLogoTexture) | ||
, mTargetManager(colliderRegister, {0, 0, 0}, sf::seconds(1.5), sf::seconds(5)) | ||
{ | ||
mLargeCrate.setScale(1.5); | ||
mMediumCrate.setScale(1); | ||
mSmallerCrate.setScale(0.5); | ||
setPosition(mPosition); | ||
mSmallerCrate.setRotation({0, 90, 0}); | ||
mMediumCrate.setRotation({0, 90, 0}); | ||
mLargeCrate.setRotation({0, 90, 0}); | ||
mDirectionArrowPointingButton.setRotation({0, 0, 180}); | ||
mDirectionArrowPointingButton.setScale(0.2); | ||
mTrainingLogo.setRotation({180, 0, 0}); | ||
mTrainingLogo.setScale(3.f); | ||
mTargetManager.setTargetMovement({1, 0, 0}, 4); | ||
mTargetManager.setSpawnRange({0, 0, 0}, {0, 4, 4}); | ||
mButtonStand.onClick( | ||
[this]() | ||
{ | ||
toggleShootingRange(); | ||
}); | ||
} | ||
|
||
void SidewayMovingTargetsRange::draw(const Renderer& target, const Camera& camera) const | ||
{ | ||
mButtonStand.draw(target, camera); | ||
mLargeCrate.draw(target, camera); | ||
mMediumCrate.draw(target, camera); | ||
mSmallerCrate.draw(target, camera); | ||
mDirectionArrowPointingButton.draw(target, camera); | ||
mTargetManager.draw(target, camera); | ||
mTrainingLogo.draw(target, camera); | ||
} | ||
|
||
void SidewayMovingTargetsRange::update(const float& deltaTime) | ||
{ | ||
mButtonStand.update(deltaTime); | ||
mTargetManager.update(deltaTime); | ||
} | ||
|
||
void SidewayMovingTargetsRange::handleEvent(const sf::Event& event) | ||
{ | ||
mButtonStand.handleEvent(event); | ||
} | ||
|
||
void SidewayMovingTargetsRange::showDebugImGui(std::string name) | ||
{ | ||
name = "[Model] " + name; | ||
ImGui::Begin(name.c_str()); | ||
ImGui::SliderFloat3("Position", &mPosition[0], -50, 50.f); | ||
ImGui::End(); | ||
setPosition(mPosition); | ||
} | ||
|
||
void SidewayMovingTargetsRange::setPosition(const glm::vec3& newPosition) | ||
{ | ||
mTargetManager.setPosition(newPosition + glm::vec3{0, 0, BOXES_DISTANCE + 2.f}); | ||
mButtonStand.setPosition(newPosition + glm::vec3{2.5, 0, 0}); | ||
mLargeCrate.setPosition(newPosition + glm::vec3{0, 0.75, BOXES_DISTANCE}); | ||
mMediumCrate.setPosition(newPosition + glm::vec3{2.5, 0.5, BOXES_DISTANCE}); | ||
mSmallerCrate.setPosition(newPosition + glm::vec3{4.5, 0.25, BOXES_DISTANCE}); | ||
mDirectionArrowPointingButton.setPosition(newPosition + glm::vec3{2.3, 0.3, 0}); | ||
mTrainingLogo.setPosition(newPosition + glm::vec3{2, 5, BOXES_DISTANCE}); | ||
} | ||
|
||
void SidewayMovingTargetsRange::toggleShootingRange() | ||
{ | ||
if (mIsShootingRangeActive) | ||
{ | ||
mTargetManager.stop(); | ||
mIsShootingRangeActive = false; | ||
} | ||
else | ||
{ | ||
mTargetManager.start(); | ||
mIsShootingRangeActive = true; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
AimGL/src/World/Scene/GameObjects/SidewayMovingTargetsRange.h
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,79 @@ | ||
#pragma once | ||
#include "ButtonStand.h" | ||
#include "LongCrate.h" | ||
#include "TargetManager.h" | ||
|
||
#include <Renderer/Graphics/3D/Sprite3D.h> | ||
|
||
/** | ||
* \brief Represents a SidewayMovingTargetsRange, | ||
* a shooting range featuring targets that move sideways. | ||
*/ | ||
class SidewayMovingTargetsRange | ||
{ | ||
public: | ||
/** | ||
* \brief Initializes a SidewayMovingTargetsRange object with collision | ||
* management and a specific position. | ||
* \param colliderRegister A register for managing collisions in the scene. | ||
* \param position The initial position of the SidewayMovingTargetsRange. | ||
*/ | ||
SidewayMovingTargetsRange(ColliderRegister& colliderRegister, const glm::vec3& position); | ||
|
||
/** | ||
* \brief Draws a shooting range to a given target | ||
* \param target The target to which the model is drawn | ||
* \param camera A camera in 3D space that looks at this object | ||
*/ | ||
void draw(const Renderer& target, const Camera& camera) const; | ||
|
||
/** | ||
* Updates the Shooting Range logic dependent, or independent of time, every rendered frame. | ||
* \param deltaTime the time that has passed since the game was last updated. | ||
*/ | ||
void update(const float& deltaTime); | ||
|
||
/** | ||
* \brief It takes input (event) from the user and interprets it | ||
* \param event user input | ||
*/ | ||
void handleEvent(const sf::Event& event); | ||
|
||
/** | ||
* \brief Displays a debug ImGui window that allows to change the internal | ||
* variables of the 3d model. | ||
* \param name Optional name of the model (it can be seen in the window name). | ||
*/ | ||
void showDebugImGui(std::string name = ""); | ||
|
||
/** | ||
* \brief Sets the position of the object. | ||
* \param newPosition The new position for the object. | ||
*/ | ||
void setPosition(const glm::vec3& newPosition); | ||
|
||
private: | ||
/** | ||
* \brief Toggles the operational state of the sideway moving targets, | ||
* such as activating or deactivating them. | ||
*/ | ||
void toggleShootingRange(); | ||
|
||
private: | ||
constexpr static auto BOXES_DISTANCE = 6.f; | ||
ButtonStand mButtonStand; | ||
glm::vec3 mPosition; | ||
|
||
LongCrate mSmallerCrate; | ||
LongCrate mMediumCrate; | ||
LongCrate mLargeCrate; | ||
|
||
Texture mDirectionArrowTexture; | ||
Sprite3D mDirectionArrowPointingButton; | ||
|
||
Texture mTrainingLogoTexture; | ||
Sprite3D mTrainingLogo; | ||
|
||
TargetManager mTargetManager; | ||
bool mIsShootingRangeActive{false}; | ||
}; |