Skip to content

Commit

Permalink
Replace currently used Ray with the new one
Browse files Browse the repository at this point in the history
The rifle used the old implementation of the ray all
the time. Now it is removed and the new implementation
of the drawable ray is used instead.
  • Loading branch information
Notiooo committed Dec 14, 2023
1 parent 2e215cb commit 23f8d26
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 83 deletions.
4 changes: 2 additions & 2 deletions AimGL/src/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include "Utils/Lerp.h"
#include "pch.h"

Player::Player(WindowToRender& window)
Player::Player(WindowToRender& window, ColliderRegister& colliderRegister)
: mCamera(window)
, mCrosshairTexture("resources/Textures/crosshair.png")
, mCrosshair(mCrosshairTexture)
, mRifle(mCamera)
, mRifle(mCamera, colliderRegister)
{
mCrosshair.setPosition({window.getSize().x / 2.f, window.getSize().y / 2.f},
Sprite2D::Origin::Center);
Expand Down
3 changes: 2 additions & 1 deletion AimGL/src/Player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class Player
/**
* \brief Player class constructor
* \param window The window into which the player's eye view is rendered
* \param colliderRegister Register in which all collisions on the scene should be located
*/
explicit Player(WindowToRender& window);
Player(WindowToRender& window, ColliderRegister& colliderRegister);

static constexpr auto PLAYER_HEGIHT = 0.8f;
static constexpr auto PLAYER_MAX_HORIZONTAL_SPEED = 5.f;
Expand Down
3 changes: 2 additions & 1 deletion AimGL/src/States/CustomStates/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
GameState::GameState(StateStack& stack, WindowToRender& window)
: State(stack)
, mWindow(window)
, mPlayer(window)
, mPlayer(window, mColliderRegister)
, mRenderer(mWindow)
, mLogoTexture("resources/Textures/logo_background.png")
, mLogo(mLogoTexture)
Expand Down Expand Up @@ -45,6 +45,7 @@ bool GameState::fixedUpdate(const float& deltaTime)
{
MTR_SCOPE("GameState", "GameState::fixedUpdate");
mPlayer.fixedUpdate(deltaTime);
mColliderRegister.updateAllCollisions();
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions AimGL/src/States/CustomStates/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <Player/Player.h>
#include <Renderer/Graphics/3D/Model.h>
#include <World/Physics/ColliderRegister.h>

class StateStack;

Expand Down Expand Up @@ -53,6 +54,7 @@ class GameState : public State

private:
WindowToRender& mWindow;
ColliderRegister mColliderRegister;
Player mPlayer;
Renderer mRenderer;
Texture mLogoTexture;
Expand Down
27 changes: 0 additions & 27 deletions AimGL/src/World/Physics/Ray.cpp

This file was deleted.

47 changes: 0 additions & 47 deletions AimGL/src/World/Physics/Ray.h

This file was deleted.

6 changes: 4 additions & 2 deletions AimGL/src/World/Scene/GameObjects/Rifle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include <Utils/Lerp.h>
#include <World/Camera.h>

Rifle::Rifle(Camera& camera)
Rifle::Rifle(Camera& camera, ColliderRegister& colliderRegister)
: mCamera(camera)
, mGun("resources/Models/ak47/ak47.obj",
{{"resources/Models/ak47/ak47-alternative.png", Texture::Type::Diffuse},
{"resources/Models/ak47/ak47-alternative-specular.png", Texture::Type::Specular}})
, mColliderRegister(colliderRegister)
{
mSoundBuffer.loadFromFile("resources/Sounds/gunshot.wav");
mGunShotSound.setBuffer(mSoundBuffer);
Expand Down Expand Up @@ -64,6 +65,7 @@ void Rifle::handleEvent(const sf::Event& event)
mCurrentRecoil = std::min(mCurrentRecoil, RECOIL_OFFSET_MAX);
mCamera.shake();
mGunShotSound.play();
mLatelyShotRay.emplace(mCamera.cameraPosition(), mCamera.direction());
mLatelyShotRay.emplace(mColliderRegister, mCamera.cameraPosition(), mCamera.direction());
mLatelyShotRay.value().colliderTag(ColliderTag::GunShot);
}
}
8 changes: 5 additions & 3 deletions AimGL/src/World/Scene/GameObjects/Rifle.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "World/Physics/Ray.h"
#include <Renderer/Graphics/3D/Model.h>
#include "Renderer/Graphics/3D/Model.h"
#include "World/Physics/Drawable/Ray.h"
#include <SFML/Audio/Sound.hpp>
#include <SFML/Audio/SoundBuffer.hpp>

Expand All @@ -16,8 +16,9 @@ class Rifle
/**
* \brief Constructor of Rifle class
* \param camera The camera to which the weapon should be attached
* \param colliderRegister Register in which all collisions on the scene should be located
*/
explicit Rifle(Camera& camera);
Rifle(Camera& camera, ColliderRegister& colliderRegister);

/**
* \brief Draws a Rifle to a given target
Expand Down Expand Up @@ -55,4 +56,5 @@ class Rifle
sf::Sound mGunShotSound;
std::optional<Ray> mLatelyShotRay;
std::vector<std::function<void(Ray)>> mRaySubscribers;
ColliderRegister& mColliderRegister;
};

0 comments on commit 23f8d26

Please sign in to comment.