fixed windows build
This commit is contained in:
parent
794fa5bba0
commit
5aff6f6326
13 changed files with 33 additions and 27 deletions
|
@ -6,9 +6,12 @@ cmake_minimum_required(VERSION 3.24)
|
||||||
# Set the project name
|
# Set the project name
|
||||||
project(Witch-Game)
|
project(Witch-Game)
|
||||||
|
|
||||||
|
#disable big libraries
|
||||||
#find_package(SDL3 REQUIRED)
|
#AVIF needs special compilers
|
||||||
#find_package(SDL3_image REQUIRED)
|
set(SDLIMAGE_AVIF OFF)
|
||||||
|
set(SDLIMAGE_TIF OFF)
|
||||||
|
set(SDLIMAGE_WEBP OFF)
|
||||||
|
set(SDLIMAGE_JXL OFF)
|
||||||
|
|
||||||
#download SDL if not installed
|
#download SDL if not installed
|
||||||
#use git ls-remote --tags https://github.com/libsdl-org/SDL.git | tail -n 1
|
#use git ls-remote --tags https://github.com/libsdl-org/SDL.git | tail -n 1
|
||||||
|
@ -42,11 +45,11 @@ set(DATA_STRUCTURES src/DataStructures/NormalizedDirection.cpp src/DataStructure
|
||||||
add_executable(Witch-Game main.cpp src/Game.cpp ${ACTORS} ${COMPONENTS} ${DATA_STRUCTURES})
|
add_executable(Witch-Game main.cpp src/Game.cpp ${ACTORS} ${COMPONENTS} ${DATA_STRUCTURES})
|
||||||
|
|
||||||
target_compile_features(Witch-Game PRIVATE cxx_std_17)
|
target_compile_features(Witch-Game PRIVATE cxx_std_17)
|
||||||
target_link_libraries(Witch-Game SDL3 SDL3_image SDL3_ttf)
|
target_link_libraries(Witch-Game SDL3::SDL3 SDL3_image::SDL3_image SDL3_ttf::SDL3_ttf)
|
||||||
|
|
||||||
#set compiler flags for warnings
|
#set compiler flags for warnings
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
target_compile_options(Witch-Game PRIVATE /W4 /WX)
|
# target_compile_options(Witch-Game PRIVATE /W4 /WX)
|
||||||
else()
|
else()
|
||||||
target_compile_options(Witch-Game PRIVATE -Wall -Wextra -Wpedantic)
|
target_compile_options(Witch-Game PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -26,10 +26,10 @@ protected:
|
||||||
Vector2D m_Position;
|
Vector2D m_Position;
|
||||||
Hitbox m_MoveHitbox;
|
Hitbox m_MoveHitbox;
|
||||||
Hitbox m_CombatHitbox;
|
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<MoveComponent> m_MoveComponent;
|
||||||
std::shared_ptr<ActionComponent> m_ActionComponent; //Skills, hit with Axe, Fiery rush,...
|
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
|
//every other action needs a sprite
|
||||||
//move needs input, input maybe needs move?
|
//move needs input, input maybe needs move?
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
|
|
||||||
#include <memory>
|
#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();
|
actor ->Init();
|
||||||
return actor;
|
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();
|
actor ->Init();
|
||||||
return actor;
|
return actor;
|
||||||
}
|
}
|
|
@ -9,8 +9,8 @@
|
||||||
class ActorFactory
|
class ActorFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::shared_ptr<Actor> CreateActor(SDL_FRect hitbox);
|
static std::shared_ptr<Actor> CreateActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox);
|
||||||
static std::shared_ptr<MovingActor> CreateMovingActor(SDL_FRect hitbox);
|
static std::shared_ptr<MovingActor> CreateMovingActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ void MovingActor::Init()
|
||||||
m_MoveComponent = std::make_shared<MoveComponent>(MoveComponent(shared_from_this()));
|
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_unique<MoveComponent>(MoveComponent(shared_from_this()));
|
||||||
//m_MoveComponent = std::make_shared<MoveComponent>(MoveComponent(shared_from_this()));
|
//m_MoveComponent = std::make_shared<MoveComponent>(MoveComponent(shared_from_this()));
|
||||||
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
|
|
||||||
friend class ActorFactory;
|
friend class ActorFactory;
|
||||||
protected:
|
protected:
|
||||||
MovingActor(SDL_FRect hitbox);
|
MovingActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox);
|
||||||
//MovingActor(const MovingActor&) = default;
|
//MovingActor(const MovingActor&) = default;
|
||||||
//MovingActor& operator=(const MovingActor&) = default;
|
//MovingActor& operator=(const MovingActor&) = default;
|
||||||
void Init() override;
|
void Init() override;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
class MoveComponent
|
class MoveComponent
|
||||||
{
|
{
|
||||||
public:
|
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 Update(float deltaTime);
|
||||||
void SetDirection(const NormalizedDirection & direction);
|
void SetDirection(const NormalizedDirection & direction);
|
||||||
void SetSpeed(float speed);
|
void SetSpeed(float speed);
|
||||||
|
|
|
@ -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 = direction.x;
|
float x = (float)direction.x;
|
||||||
float y = direction.y;
|
float y = (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))
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,7 @@ public:
|
||||||
bool DownPressed = false;
|
bool DownPressed = false;
|
||||||
bool LeftPressed = false;
|
bool LeftPressed = false;
|
||||||
bool RightPressed = 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);
|
bool GetDirection(NormalizedDirection & ref_direction);
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ NormalizedDirection::NormalizedDirection(float x, float y, bool isNormalized)
|
||||||
}
|
}
|
||||||
else
|
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.x = x * normalizeValue;
|
||||||
m_Direction.y = y * normalizeValue;
|
m_Direction.y = y * normalizeValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
class NormalizedDirection
|
class NormalizedDirection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NormalizedDirection() {};
|
NormalizedDirection() : m_Direction(Vector2D()){};
|
||||||
NormalizedDirection(float x, float y, bool isNormalized);
|
NormalizedDirection(float x, float y, bool isNormalized);
|
||||||
NormalizedDirection(SDL_FPoint direction, bool isNormalized);
|
NormalizedDirection(SDL_FPoint direction, bool isNormalized);
|
||||||
NormalizedDirection(Vector2D direction, bool isNormalized);
|
NormalizedDirection(Vector2D direction, bool isNormalized);
|
||||||
|
|
11
src/Game.cpp
11
src/Game.cpp
|
@ -17,14 +17,17 @@
|
||||||
Game::Game(SDL_Window *window, SDL_Renderer *renderer)
|
Game::Game(SDL_Window *window, SDL_Renderer *renderer)
|
||||||
: m_Window(window, SDL_DestroyWindow),
|
: m_Window(window, SDL_DestroyWindow),
|
||||||
m_Renderer(renderer, SDL_DestroyRenderer),
|
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;
|
SDL_FRect player1Hitbox;
|
||||||
player1Hitbox.x = 0;
|
player1Hitbox.x = 0;
|
||||||
player1Hitbox.y = 0;
|
player1Hitbox.y = 0;
|
||||||
player1Hitbox.w = 20;
|
player1Hitbox.w = 20;
|
||||||
player1Hitbox.h = 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
|
//TODO: read keybinds from config if it exists. otherwise initialze standard and write file
|
||||||
m_KeyboardCommandMap.emplace(SDL_SCANCODE_ESCAPE, new EndGameCommand(this));
|
m_KeyboardCommandMap.emplace(SDL_SCANCODE_ESCAPE, new EndGameCommand(this));
|
||||||
|
@ -46,7 +49,7 @@ void Game::Run()
|
||||||
float deltaTime = (SDL_GetTicks() - m_TickCount) / 1000.0f;
|
float deltaTime = (SDL_GetTicks() - m_TickCount) / 1000.0f;
|
||||||
uint64_t ticks = SDL_GetTicks() - m_TickCount;
|
uint64_t ticks = SDL_GetTicks() - m_TickCount;
|
||||||
ticks = ticks > 0 ? ticks : 1;
|
ticks = ticks > 0 ? ticks : 1;
|
||||||
int fps = 1000/(ticks);
|
long fps = 1000/(ticks);
|
||||||
m_TickCount = SDL_GetTicks();
|
m_TickCount = SDL_GetTicks();
|
||||||
HandleMovement();
|
HandleMovement();
|
||||||
m_Player1->Update(deltaTime);
|
m_Player1->Update(deltaTime);
|
||||||
|
@ -56,7 +59,7 @@ void Game::Run()
|
||||||
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(m_Renderer.get(), 255, 255, 255, 255);
|
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_SetRenderDrawColor(m_Renderer.get(), 150, 0, 150, 255);
|
||||||
SDL_FRect player = m_Player1->GetMovementHitbox();
|
SDL_FRect player = m_Player1->GetMovementHitbox();
|
||||||
SDL_RenderFillRect(m_Renderer.get(), &player);
|
SDL_RenderFillRect(m_Renderer.get(), &player);
|
||||||
|
|
|
@ -23,10 +23,10 @@ public:
|
||||||
void RemoveGamepad(SDL_JoystickID id);
|
void RemoveGamepad(SDL_JoystickID id);
|
||||||
void EndGame();
|
void EndGame();
|
||||||
private:
|
private:
|
||||||
const float c_GamepadAxisDeadzone = 0.2; //TODO: make this a setting?
|
const float c_GamepadAxisDeadzone = (float)0.2; //TODO: make this a setting?
|
||||||
|
|
||||||
bool m_running = true;
|
bool m_running = true;
|
||||||
uint64_t m_TickCount;
|
uint64_t m_TickCount = 0;
|
||||||
std::map<SDL_Scancode, GameCommand*> m_KeyboardCommandMap;
|
std::map<SDL_Scancode, GameCommand*> m_KeyboardCommandMap;
|
||||||
std::map<SDL_GamepadButton, GameCommand*> m_Gamepad1ButtonCommandMap;
|
std::map<SDL_GamepadButton, GameCommand*> m_Gamepad1ButtonCommandMap;
|
||||||
std::map<SDL_GamepadButton, GameCommand*> m_Gamepad2ButtonCommandMap;
|
std::map<SDL_GamepadButton, GameCommand*> m_Gamepad2ButtonCommandMap;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue