cleaned up project following CLion recommendations
This commit is contained in:
parent
32cdec6b7e
commit
fe16c843cc
15 changed files with 40 additions and 53 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -467,3 +467,4 @@ FodyWeavers.xsd
|
||||||
|
|
||||||
.kateproject.build
|
.kateproject.build
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
|
.idea
|
||||||
|
|
18
main.cpp
18
main.cpp
|
@ -7,8 +7,8 @@
|
||||||
/* This function runs once at startup. */
|
/* This function runs once at startup. */
|
||||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SDL_Window *window = NULL;
|
SDL_Window *window = nullptr;
|
||||||
SDL_Renderer *renderer = NULL;
|
SDL_Renderer *renderer = nullptr;
|
||||||
SDL_SetAppMetadata("Example Input Joystick Polling", "1.0", "com.example.input-joystick-polling");
|
SDL_SetAppMetadata("Example Input Joystick Polling", "1.0", "com.example.input-joystick-polling");
|
||||||
|
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
|
||||||
|
@ -27,17 +27,15 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||||
return SDL_APP_CONTINUE; /* carry on with the program! */
|
return SDL_APP_CONTINUE; /* carry on with the program! */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
|
/* This function runs when a new event (mouse input, keypresses, etc.) occurs. */
|
||||||
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
|
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
|
||||||
{
|
{
|
||||||
Game* game = (Game*) appstate;
|
Game* game = static_cast<Game *>(appstate);
|
||||||
switch(event->type)
|
switch(event->type)
|
||||||
{
|
{
|
||||||
case SDL_EVENT_QUIT:
|
case SDL_EVENT_QUIT:
|
||||||
return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
|
return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
|
||||||
case SDL_EVENT_KEY_DOWN:
|
case SDL_EVENT_KEY_DOWN:
|
||||||
game->HandleKeyboardInput(*event);
|
|
||||||
break;
|
|
||||||
case SDL_EVENT_KEY_UP:
|
case SDL_EVENT_KEY_UP:
|
||||||
game->HandleKeyboardInput(*event);
|
game->HandleKeyboardInput(*event);
|
||||||
break;
|
break;
|
||||||
|
@ -48,14 +46,14 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
|
||||||
game->RemoveGamepad(event->gdevice.which);
|
game->RemoveGamepad(event->gdevice.which);
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||||
game->HandleGamepadButton(*event);
|
|
||||||
break;
|
|
||||||
case SDL_EVENT_GAMEPAD_BUTTON_UP:
|
case SDL_EVENT_GAMEPAD_BUTTON_UP:
|
||||||
game->HandleGamepadButton(*event);
|
game->HandleGamepadButton(*event);
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
|
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
|
||||||
game->HandleGamepadAxis(*event);
|
game->HandleGamepadAxis(*event);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return SDL_APP_CONTINUE; /* carry on with the program! */
|
return SDL_APP_CONTINUE; /* carry on with the program! */
|
||||||
}
|
}
|
||||||
|
@ -63,7 +61,7 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
|
||||||
/* This function runs once per frame, and is the heart of the program. */
|
/* This function runs once per frame, and is the heart of the program. */
|
||||||
SDL_AppResult SDL_AppIterate(void *appstate)
|
SDL_AppResult SDL_AppIterate(void *appstate)
|
||||||
{
|
{
|
||||||
Game* game = (Game*) appstate;
|
Game* game = static_cast<Game *>(appstate);
|
||||||
game ->Run();
|
game ->Run();
|
||||||
|
|
||||||
return SDL_APP_CONTINUE; /* carry on with the program! */
|
return SDL_APP_CONTINUE; /* carry on with the program! */
|
||||||
|
@ -72,6 +70,6 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||||
/* This function runs once at shutdown. */
|
/* This function runs once at shutdown. */
|
||||||
void SDL_AppQuit(void *appstate, SDL_AppResult result)
|
void SDL_AppQuit(void *appstate, SDL_AppResult result)
|
||||||
{
|
{
|
||||||
delete (Game*)appstate;
|
delete static_cast<Game *>(appstate);
|
||||||
/* SDL will clean up the window/renderer for us. */
|
/* SDL will clean up the window/renderer for us. */
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
void Actor::SetPosition(Vector2D position)
|
void Actor::SetPosition(Vector2D position)
|
||||||
{
|
{
|
||||||
//differenct = velocity vector to new position
|
//difference = velocity vector to new position
|
||||||
Vector2D difference = position - m_Position;
|
Vector2D difference = position - m_Position;
|
||||||
m_MoveHitbox.ApplyVelocity(difference);
|
m_MoveHitbox.ApplyVelocity(difference);
|
||||||
m_CombatHitbox.ApplyVelocity(difference);
|
m_CombatHitbox.ApplyVelocity(difference);
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define ACTOR_H
|
#define ACTOR_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <SDL3/SDL_rect.h>
|
|
||||||
#include "../DataStructures/Vector2D.h"
|
#include "../DataStructures/Vector2D.h"
|
||||||
#include "../DataStructures/Hitbox.h"
|
#include "../DataStructures/Hitbox.h"
|
||||||
|
|
||||||
|
@ -14,9 +13,9 @@ public:
|
||||||
void SetPosition(Vector2D position);
|
void SetPosition(Vector2D position);
|
||||||
void MoveBy(Vector2D velocity);
|
void MoveBy(Vector2D velocity);
|
||||||
|
|
||||||
Vector2D GetPosition() {return m_Position;}
|
Vector2D GetPosition() const {return m_Position;}
|
||||||
Hitbox GetMovementHitbox() {return m_MoveHitbox;}
|
Hitbox GetMovementHitbox() const {return m_MoveHitbox;}
|
||||||
Hitbox GetCombatHitbox() {return m_CombatHitbox;}
|
Hitbox GetCombatHitbox() const {return m_CombatHitbox;}
|
||||||
|
|
||||||
friend class ActorFactory;
|
friend class ActorFactory;
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define ACTOR_FACTORY_H
|
#define ACTOR_FACTORY_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <SDL3/SDL_rect.h>
|
|
||||||
#include "Actor.h"
|
#include "Actor.h"
|
||||||
#include "MovingActor.h"
|
#include "MovingActor.h"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
#include "MoveComponent.h"
|
#include "MoveComponent.h"
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
|
|
||||||
void MoveComponent::Update(float deltaTime)
|
void MoveComponent::Update(float deltaTime)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
#define MOVE_COMPONENT_H
|
#define MOVE_COMPONENT_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include<math.h>
|
|
||||||
#include <SDL3/SDL_rect.h>
|
|
||||||
#include "../Actors/Actor.h"
|
#include "../Actors/Actor.h"
|
||||||
#include "../DataStructures/NormalizedDirection.h"
|
#include "../DataStructures/NormalizedDirection.h"
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "NormalizedDirection.h"
|
#include "NormalizedDirection.h"
|
||||||
|
|
||||||
|
|
||||||
bool DirectionButtonStatus::GetDirection(NormalizedDirection & ref_direction)
|
bool DirectionButtonStatus::GetDirection(NormalizedDirection & ref_direction) const
|
||||||
{
|
{
|
||||||
SDL_Point direction = {0,0};
|
SDL_Point direction = {0,0};
|
||||||
if(UpPressed) direction.y -= 1;
|
if(UpPressed) direction.y -= 1;
|
||||||
|
@ -11,8 +11,8 @@ bool DirectionButtonStatus::GetDirection(NormalizedDirection & ref_direction)
|
||||||
if(LeftPressed) direction.x -= 1;
|
if(LeftPressed) direction.x -= 1;
|
||||||
if(RightPressed) direction.x += 1;
|
if(RightPressed) direction.x += 1;
|
||||||
|
|
||||||
float x = (float)direction.x;
|
float x = static_cast<float>(direction.x);
|
||||||
float y = (float)direction.y;
|
float y = static_cast<float>(direction.y);
|
||||||
if((direction.y == 1 || direction.y == -1)
|
if((direction.y == 1 || direction.y == -1)
|
||||||
&& (direction.x == 1 || direction.x == -1))
|
&& (direction.x == 1 || direction.x == -1))
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define DIRECTION_BUTTON_STATUS_H
|
#define DIRECTION_BUTTON_STATUS_H
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
#include "NormalizedDirection.h"
|
#include "NormalizedDirection.h"
|
||||||
|
|
||||||
class DirectionButtonStatus
|
class DirectionButtonStatus
|
||||||
|
@ -12,9 +11,9 @@ public:
|
||||||
bool DownPressed = false;
|
bool DownPressed = false;
|
||||||
bool LeftPressed = false;
|
bool LeftPressed = false;
|
||||||
bool RightPressed = 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
|
#endif
|
|
@ -1,10 +1,10 @@
|
||||||
#include "Hitbox.h"
|
#include "Hitbox.h"
|
||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
|
|
||||||
void Hitbox::ApplyVelocity(Vector2D vector)
|
void Hitbox::ApplyVelocity(Vector2D velocity)
|
||||||
{
|
{
|
||||||
x += vector.x;
|
x += velocity.x;
|
||||||
y += vector.y;
|
y += velocity.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hitbox::SetPosition(Vector2D vector)
|
void Hitbox::SetPosition(Vector2D vector)
|
||||||
|
@ -13,7 +13,7 @@ void Hitbox::SetPosition(Vector2D vector)
|
||||||
y = vector.y;
|
y = vector.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2D Hitbox::GetDirectionTo(const Hitbox & other)
|
Vector2D Hitbox::GetDirectionTo(const Hitbox & other) const
|
||||||
{
|
{
|
||||||
Vector2D vec;
|
Vector2D vec;
|
||||||
vec.x = other.x - x;
|
vec.x = other.x - x;
|
||||||
|
|
|
@ -14,7 +14,7 @@ public:
|
||||||
|
|
||||||
void ApplyVelocity(Vector2D velocity);
|
void ApplyVelocity(Vector2D velocity);
|
||||||
void SetPosition(Vector2D vector);
|
void SetPosition(Vector2D vector);
|
||||||
Vector2D GetDirectionTo(const Hitbox & other);
|
Vector2D GetDirectionTo(const Hitbox & other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,5 +1,5 @@
|
||||||
#include "NormalizedDirection.h"
|
#include "NormalizedDirection.h"
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
|
|
||||||
NormalizedDirection::NormalizedDirection(float x, float y, bool isNormalized)
|
NormalizedDirection::NormalizedDirection(float x, float y, bool isNormalized)
|
||||||
{
|
{
|
||||||
|
@ -10,18 +10,14 @@ NormalizedDirection::NormalizedDirection(float x, float y, bool isNormalized)
|
||||||
}
|
}
|
||||||
else
|
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.x = x * normalizeValue;
|
||||||
m_Direction.y = y * normalizeValue;
|
m_Direction.y = y * normalizeValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NormalizedDirection::NormalizedDirection(SDL_FPoint direction, bool isNormalized)
|
NormalizedDirection::NormalizedDirection(SDL_FPoint direction, bool isNormalized):
|
||||||
{
|
NormalizedDirection(direction.x, direction.y, isNormalized) {}
|
||||||
NormalizedDirection(direction.x, direction.y, isNormalized);
|
|
||||||
}
|
|
||||||
|
|
||||||
NormalizedDirection::NormalizedDirection(Vector2D direction, bool isNormalized)
|
NormalizedDirection::NormalizedDirection(Vector2D direction, bool isNormalized) :
|
||||||
{
|
NormalizedDirection(direction.x, direction.y, isNormalized) {}
|
||||||
NormalizedDirection(direction.x, direction.y, isNormalized);
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "Vector2D.h"
|
|
||||||
|
|
||||||
class NormalizedDirection
|
class NormalizedDirection
|
||||||
{
|
{
|
||||||
|
@ -13,9 +12,9 @@ public:
|
||||||
NormalizedDirection(SDL_FPoint direction, bool isNormalized);
|
NormalizedDirection(SDL_FPoint direction, bool isNormalized);
|
||||||
NormalizedDirection(Vector2D direction, bool isNormalized);
|
NormalizedDirection(Vector2D direction, bool isNormalized);
|
||||||
|
|
||||||
float GetX() {return m_Direction.x;}
|
float GetX() const {return m_Direction.x;}
|
||||||
float GetY() {return m_Direction.y;}
|
float GetY() const {return m_Direction.y;}
|
||||||
Vector2D GetDirection() {return m_Direction;};
|
Vector2D GetDirection() const {return m_Direction;};
|
||||||
private:
|
private:
|
||||||
Vector2D m_Direction;
|
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
|
//TODO: read game settings from config file
|
||||||
SetFps(60);
|
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_ESCAPE, new EndGameCommand(this));
|
||||||
m_KeyboardCommandMap.emplace(SDL_SCANCODE_W, new MoveUpCommand(m_Player1DirectionButtonStatus));
|
m_KeyboardCommandMap.emplace(SDL_SCANCODE_W, new MoveUpCommand(m_Player1DirectionButtonStatus));
|
||||||
m_KeyboardCommandMap.emplace(SDL_SCANCODE_A, new MoveLeftCommand(m_Player1DirectionButtonStatus));
|
m_KeyboardCommandMap.emplace(SDL_SCANCODE_A, new MoveLeftCommand(m_Player1DirectionButtonStatus));
|
||||||
|
@ -79,7 +79,7 @@ float Game::GetDeltaTime()
|
||||||
frameTicks = currentTicksNS - m_TickCount;
|
frameTicks = currentTicksNS - m_TickCount;
|
||||||
}
|
}
|
||||||
m_TickCount = currentTicksNS;
|
m_TickCount = currentTicksNS;
|
||||||
return frameTicks / c_NSPerSecond;
|
return static_cast<float>(frameTicks) / static_cast<float>(c_NSPerSecond);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::HandleMovement()
|
void Game::HandleMovement()
|
||||||
|
@ -136,10 +136,10 @@ void Game::HandleGamepadButton(const SDL_Event &event)
|
||||||
|
|
||||||
void Game::HandleGamepadAxis(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())
|
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);
|
commandIterator->second->Execute(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ void Game::SetFps(uint16_t fps)
|
||||||
|
|
||||||
void Game::EndGame()
|
void Game::EndGame()
|
||||||
{
|
{
|
||||||
SDL_Event * event = new SDL_Event();
|
SDL_Event event;
|
||||||
event->type = SDL_EVENT_QUIT;
|
event.type = SDL_EVENT_QUIT;
|
||||||
SDL_PushEvent(event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
|
@ -26,7 +26,7 @@ public:
|
||||||
void EndGame();
|
void EndGame();
|
||||||
private:
|
private:
|
||||||
const float c_GamepadAxisDeadzone = 0.2f; //TODO: make this a setting?
|
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;
|
bool m_running = true;
|
||||||
uint64_t m_TickCount = 0;
|
uint64_t m_TickCount = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue