Merge remote-tracking branch 'origin/main'

This commit is contained in:
Sarah Faey 2025-05-07 18:34:31 +02:00
commit 4c3cc24de2
13 changed files with 32 additions and 26 deletions

View file

@ -26,10 +26,10 @@ protected:
Vector2D m_Position;
Hitbox m_MoveHitbox;
Hitbox m_CombatHitbox;
std::shared_ptr<InputComponent> m_InputComponent; //Input or AI
/*std::shared_ptr<InputComponent> m_InputComponent; //Input or AI
std::shared_ptr<MoveComponent> m_MoveComponent;
std::shared_ptr<ActionComponent> m_ActionComponent; //Skills, hit with Axe, Fiery rush,...
std::shared_ptr<SpriteComponent> m_SpriteComponent; //Sprites or anim Sprites
std::shared_ptr<SpriteComponent> m_SpriteComponent; //Sprites or anim Sprites*/
//every other action needs a sprite
//move needs input, input maybe needs move?

View file

@ -2,16 +2,16 @@
#include <memory>
std::shared_ptr<Actor> ActorFactory::CreateActor(SDL_FRect hitbox)
std::shared_ptr<Actor> ActorFactory::CreateActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox)
{
auto actor = std::make_shared<Actor>(Actor(hitbox));
auto actor = std::make_shared<Actor>(Actor(position, moveHitbox, combatHitbox));
actor ->Init();
return actor;
}
std::shared_ptr<MovingActor> ActorFactory::CreateMovingActor(SDL_FRect hitbox)
std::shared_ptr<MovingActor> ActorFactory::CreateMovingActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox)
{
auto actor = std::make_shared<MovingActor>(MovingActor(hitbox));
auto actor = std::make_shared<MovingActor>(MovingActor(position, moveHitbox, combatHitbox));
actor ->Init();
return actor;
}

View file

@ -9,8 +9,8 @@
class ActorFactory
{
public:
static std::shared_ptr<Actor> CreateActor(SDL_FRect hitbox);
static std::shared_ptr<MovingActor> CreateMovingActor(SDL_FRect hitbox);
static std::shared_ptr<Actor> CreateActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox);
static std::shared_ptr<MovingActor> CreateMovingActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox);
};

View file

@ -6,7 +6,7 @@ void MovingActor::Init()
m_MoveComponent = std::make_shared<MoveComponent>(MoveComponent(shared_from_this()));
}
MovingActor::MovingActor(SDL_FRect hitbox) : Actor(hitbox)
MovingActor::MovingActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox) : Actor(position, moveHitbox, combatHitbox)
{
//m_MoveComponent = std::make_unique<MoveComponent>(MoveComponent(shared_from_this()));
//m_MoveComponent = std::make_shared<MoveComponent>(MoveComponent(shared_from_this()));

View file

@ -17,7 +17,7 @@ public:
friend class ActorFactory;
protected:
MovingActor(SDL_FRect hitbox);
MovingActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox);
//MovingActor(const MovingActor&) = default;
//MovingActor& operator=(const MovingActor&) = default;
void Init() override;

View file

@ -10,7 +10,7 @@
class MoveComponent
{
public:
MoveComponent(std::weak_ptr<Actor> actor): m_Actor(actor), m_Speed(50) {}; //TODO: speed
MoveComponent(std::weak_ptr<Actor> actor) : m_Actor(actor), m_Direction(NormalizedDirection()), m_Speed(50), m_ForcedDistance(0) {}; //TODO: speed
void Update(float deltaTime);
void SetDirection(const NormalizedDirection & direction);
void SetSpeed(float speed);

View file

@ -11,8 +11,8 @@ bool DirectionButtonStatus::GetDirection(NormalizedDirection & ref_direction)
if(LeftPressed) direction.x -= 1;
if(RightPressed) direction.x += 1;
float x = direction.x;
float y = direction.y;
float x = (float)direction.x;
float y = (float)direction.y;
if((direction.y == 1 || direction.y == -1)
&& (direction.x == 1 || direction.x == -1))
{

View file

@ -12,7 +12,7 @@ public:
bool DownPressed = false;
bool LeftPressed = false;
bool RightPressed = false;
const float c_NormalizedDiagonal = 1 / sqrt(2);
const float c_NormalizedDiagonal = (float)(1.0 / sqrt(2));
bool GetDirection(NormalizedDirection & ref_direction);
};

View file

@ -10,7 +10,7 @@ NormalizedDirection::NormalizedDirection(float x, float y, bool isNormalized)
}
else
{
float normalizeValue = 1 / sqrt(pow(x,2) + pow(y,2));
float normalizeValue = (float)(1.0 / sqrt(pow(x,2) + pow(y,2)));
m_Direction.x = x * normalizeValue;
m_Direction.y = y * normalizeValue;
}

View file

@ -8,7 +8,7 @@
class NormalizedDirection
{
public:
NormalizedDirection() {};
NormalizedDirection() : m_Direction(Vector2D()){};
NormalizedDirection(float x, float y, bool isNormalized);
NormalizedDirection(SDL_FPoint direction, bool isNormalized);
NormalizedDirection(Vector2D direction, bool isNormalized);

View file

@ -17,14 +17,17 @@
Game::Game(SDL_Window *window, SDL_Renderer *renderer)
: m_Window(window, SDL_DestroyWindow),
m_Renderer(renderer, SDL_DestroyRenderer),
m_Gamepad1(nullptr, SDL_CloseGamepad)
m_Gamepad1(nullptr, SDL_CloseGamepad),
m_TickCount(0),
m_Player1DirectionInput({ 0,0 }),
m_Player2DirectionInput({ 0,0 })
{
SDL_FRect player1Hitbox;
player1Hitbox.x = 0;
player1Hitbox.y = 0;
player1Hitbox.w = 20;
player1Hitbox.h = 20;
m_Player1 = ActorFactory::CreateMovingActor(player1Hitbox);
m_Player1 = ActorFactory::CreateMovingActor(Vector2D(0,0), player1Hitbox, player1Hitbox);
//TODO: read keybinds from config if it exists. otherwise initialze standard and write file
m_KeyboardCommandMap.emplace(SDL_SCANCODE_ESCAPE, new EndGameCommand(this));
@ -64,7 +67,7 @@ void Game::Run()
SDL_SetRenderDrawColor(m_Renderer.get(), 255, 255, 255, 255);
SDL_RenderDebugTextFormat(m_Renderer.get(), 10, 440, "%" SDL_PRIu64 " fps", fps);
SDL_RenderDebugTextFormat(m_Renderer.get(), 10, 440, "%" SDL_PRIu32 " fps", fps);
SDL_SetRenderDrawColor(m_Renderer.get(), 150, 0, 150, 255);
SDL_FRect player = m_Player1->GetMovementHitbox();
SDL_RenderFillRect(m_Renderer.get(), &player);

View file

@ -23,11 +23,11 @@ public:
void RemoveGamepad(SDL_JoystickID id);
void EndGame();
private:
const float c_GamepadAxisDeadzone = 0.2; //TODO: make this a setting?
const float c_GamepadAxisDeadzone = (float)0.2; //TODO: make this a setting?
const float c_NSPerSecond = 1000000000;
bool m_running = true;
uint64_t m_TickCount;
uint64_t m_TickCount = 0;
uint64_t m_MinTicksPerFrame = c_NSPerSecond/60;
std::map<SDL_Scancode, GameCommand*> m_KeyboardCommandMap;