cleaned up project following CLion recommendations
This commit is contained in:
parent
32cdec6b7e
commit
fe16c843cc
15 changed files with 40 additions and 53 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
void Actor::SetPosition(Vector2D position)
|
||||
{
|
||||
//differenct = velocity vector to new position
|
||||
//difference = velocity vector to new position
|
||||
Vector2D difference = position - m_Position;
|
||||
m_MoveHitbox.ApplyVelocity(difference);
|
||||
m_CombatHitbox.ApplyVelocity(difference);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define ACTOR_H
|
||||
|
||||
#include <memory>
|
||||
#include <SDL3/SDL_rect.h>
|
||||
#include "../DataStructures/Vector2D.h"
|
||||
#include "../DataStructures/Hitbox.h"
|
||||
|
||||
|
@ -14,9 +13,9 @@ public:
|
|||
void SetPosition(Vector2D position);
|
||||
void MoveBy(Vector2D velocity);
|
||||
|
||||
Vector2D GetPosition() {return m_Position;}
|
||||
Hitbox GetMovementHitbox() {return m_MoveHitbox;}
|
||||
Hitbox GetCombatHitbox() {return m_CombatHitbox;}
|
||||
Vector2D GetPosition() const {return m_Position;}
|
||||
Hitbox GetMovementHitbox() const {return m_MoveHitbox;}
|
||||
Hitbox GetCombatHitbox() const {return m_CombatHitbox;}
|
||||
|
||||
friend class ActorFactory;
|
||||
protected:
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define ACTOR_FACTORY_H
|
||||
|
||||
#include <memory>
|
||||
#include <SDL3/SDL_rect.h>
|
||||
#include "Actor.h"
|
||||
#include "MovingActor.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#include "MoveComponent.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
void MoveComponent::Update(float deltaTime)
|
||||
{
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#define MOVE_COMPONENT_H
|
||||
|
||||
#include <memory>
|
||||
#include<math.h>
|
||||
#include <SDL3/SDL_rect.h>
|
||||
#include "../Actors/Actor.h"
|
||||
#include "../DataStructures/NormalizedDirection.h"
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "NormalizedDirection.h"
|
||||
|
||||
|
||||
bool DirectionButtonStatus::GetDirection(NormalizedDirection & ref_direction)
|
||||
bool DirectionButtonStatus::GetDirection(NormalizedDirection & ref_direction) const
|
||||
{
|
||||
SDL_Point direction = {0,0};
|
||||
if(UpPressed) direction.y -= 1;
|
||||
|
@ -11,8 +11,8 @@ bool DirectionButtonStatus::GetDirection(NormalizedDirection & ref_direction)
|
|||
if(LeftPressed) direction.x -= 1;
|
||||
if(RightPressed) direction.x += 1;
|
||||
|
||||
float x = (float)direction.x;
|
||||
float y = (float)direction.y;
|
||||
float x = static_cast<float>(direction.x);
|
||||
float y = static_cast<float>(direction.y);
|
||||
if((direction.y == 1 || direction.y == -1)
|
||||
&& (direction.x == 1 || direction.x == -1))
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define DIRECTION_BUTTON_STATUS_H
|
||||
|
||||
#include <math.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include "NormalizedDirection.h"
|
||||
|
||||
class DirectionButtonStatus
|
||||
|
@ -12,9 +11,9 @@ public:
|
|||
bool DownPressed = false;
|
||||
bool LeftPressed = false;
|
||||
bool RightPressed = false;
|
||||
const float c_NormalizedDiagonal = (float)(1.0 / sqrt(2));
|
||||
const float c_NormalizedDiagonal = static_cast<float>(1.0 / sqrt(2));
|
||||
|
||||
bool GetDirection(NormalizedDirection & ref_direction);
|
||||
bool GetDirection(NormalizedDirection & ref_direction) const;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,10 +1,10 @@
|
|||
#include "Hitbox.h"
|
||||
#include "Vector2D.h"
|
||||
|
||||
void Hitbox::ApplyVelocity(Vector2D vector)
|
||||
void Hitbox::ApplyVelocity(Vector2D velocity)
|
||||
{
|
||||
x += vector.x;
|
||||
y += vector.y;
|
||||
x += velocity.x;
|
||||
y += velocity.y;
|
||||
}
|
||||
|
||||
void Hitbox::SetPosition(Vector2D vector)
|
||||
|
@ -13,7 +13,7 @@ void Hitbox::SetPosition(Vector2D vector)
|
|||
y = vector.y;
|
||||
}
|
||||
|
||||
Vector2D Hitbox::GetDirectionTo(const Hitbox & other)
|
||||
Vector2D Hitbox::GetDirectionTo(const Hitbox & other) const
|
||||
{
|
||||
Vector2D vec;
|
||||
vec.x = other.x - x;
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
|
||||
void ApplyVelocity(Vector2D velocity);
|
||||
void SetPosition(Vector2D vector);
|
||||
Vector2D GetDirectionTo(const Hitbox & other);
|
||||
Vector2D GetDirectionTo(const Hitbox & other) const;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
#include "NormalizedDirection.h"
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
|
||||
NormalizedDirection::NormalizedDirection(float x, float y, bool isNormalized)
|
||||
{
|
||||
|
@ -10,18 +10,14 @@ NormalizedDirection::NormalizedDirection(float x, float y, bool isNormalized)
|
|||
}
|
||||
else
|
||||
{
|
||||
float normalizeValue = (float)(1.0 / sqrt(pow(x,2) + pow(y,2)));
|
||||
float normalizeValue = static_cast<float>(1.0 / sqrt(pow(x, 2) + pow(y, 2)));
|
||||
m_Direction.x = x * normalizeValue;
|
||||
m_Direction.y = y * normalizeValue;
|
||||
}
|
||||
}
|
||||
|
||||
NormalizedDirection::NormalizedDirection(SDL_FPoint direction, bool isNormalized)
|
||||
{
|
||||
NormalizedDirection(direction.x, direction.y, isNormalized);
|
||||
}
|
||||
NormalizedDirection::NormalizedDirection(SDL_FPoint direction, bool isNormalized):
|
||||
NormalizedDirection(direction.x, direction.y, isNormalized) {}
|
||||
|
||||
NormalizedDirection::NormalizedDirection(Vector2D direction, bool isNormalized)
|
||||
{
|
||||
NormalizedDirection(direction.x, direction.y, isNormalized);
|
||||
}
|
||||
NormalizedDirection::NormalizedDirection(Vector2D direction, bool isNormalized) :
|
||||
NormalizedDirection(direction.x, direction.y, isNormalized) {}
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "Vector2D.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include "Vector2D.h"
|
||||
|
||||
class NormalizedDirection
|
||||
{
|
||||
|
@ -13,9 +12,9 @@ public:
|
|||
NormalizedDirection(SDL_FPoint direction, bool isNormalized);
|
||||
NormalizedDirection(Vector2D direction, bool isNormalized);
|
||||
|
||||
float GetX() {return m_Direction.x;}
|
||||
float GetY() {return m_Direction.y;}
|
||||
Vector2D GetDirection() {return m_Direction;};
|
||||
float GetX() const {return m_Direction.x;}
|
||||
float GetY() const {return m_Direction.y;}
|
||||
Vector2D GetDirection() const {return m_Direction;};
|
||||
private:
|
||||
Vector2D m_Direction;
|
||||
};
|
||||
|
|
14
src/Game.cpp
14
src/Game.cpp
|
@ -32,7 +32,7 @@ Game::Game(SDL_Window *window, SDL_Renderer *renderer) :
|
|||
//TODO: read game settings from config file
|
||||
SetFps(60);
|
||||
|
||||
//TODO: read keybinds from config if it exists. otherwise initialze standard and write file
|
||||
//TODO: read keybinds from config if it exists. otherwise initialize standard and write file
|
||||
m_KeyboardCommandMap.emplace(SDL_SCANCODE_ESCAPE, new EndGameCommand(this));
|
||||
m_KeyboardCommandMap.emplace(SDL_SCANCODE_W, new MoveUpCommand(m_Player1DirectionButtonStatus));
|
||||
m_KeyboardCommandMap.emplace(SDL_SCANCODE_A, new MoveLeftCommand(m_Player1DirectionButtonStatus));
|
||||
|
@ -79,7 +79,7 @@ float Game::GetDeltaTime()
|
|||
frameTicks = currentTicksNS - m_TickCount;
|
||||
}
|
||||
m_TickCount = currentTicksNS;
|
||||
return frameTicks / c_NSPerSecond;
|
||||
return static_cast<float>(frameTicks) / static_cast<float>(c_NSPerSecond);
|
||||
}
|
||||
|
||||
void Game::HandleMovement()
|
||||
|
@ -136,10 +136,10 @@ void Game::HandleGamepadButton(const SDL_Event &event)
|
|||
|
||||
void Game::HandleGamepadAxis(const SDL_Event &event)
|
||||
{
|
||||
auto commandIterator = m_Gamepad1AxisCommandMap.find((SDL_GamepadAxis)event.gaxis.axis);
|
||||
auto commandIterator = m_Gamepad1AxisCommandMap.find(static_cast<SDL_GamepadAxis>(event.gaxis.axis));
|
||||
if(commandIterator != m_Gamepad1AxisCommandMap.end())
|
||||
{
|
||||
float value = (float)event.gaxis.value / std::numeric_limits<int16_t>::max();
|
||||
float value = static_cast<float>(event.gaxis.value) / std::numeric_limits<int16_t>::max();
|
||||
commandIterator->second->Execute(value);
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ void Game::SetFps(uint16_t fps)
|
|||
|
||||
void Game::EndGame()
|
||||
{
|
||||
SDL_Event * event = new SDL_Event();
|
||||
event->type = SDL_EVENT_QUIT;
|
||||
SDL_PushEvent(event);
|
||||
SDL_Event event;
|
||||
event.type = SDL_EVENT_QUIT;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
|
@ -26,7 +26,7 @@ public:
|
|||
void EndGame();
|
||||
private:
|
||||
const float c_GamepadAxisDeadzone = 0.2f; //TODO: make this a setting?
|
||||
const float c_NSPerSecond = 1000000000.0f;
|
||||
const uint32_t c_NSPerSecond = 1000000000;
|
||||
|
||||
bool m_running = true;
|
||||
uint64_t m_TickCount = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue