Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
4c3cc24de2
13 changed files with 32 additions and 26 deletions
|
@ -6,9 +6,12 @@ cmake_minimum_required(VERSION 3.24)
|
|||
# Set the project name
|
||||
project(Witch-Game)
|
||||
|
||||
|
||||
#find_package(SDL3 REQUIRED)
|
||||
#find_package(SDL3_image REQUIRED)
|
||||
#disable big libraries
|
||||
#AVIF needs special compilers
|
||||
set(SDLIMAGE_AVIF OFF)
|
||||
set(SDLIMAGE_TIF OFF)
|
||||
set(SDLIMAGE_WEBP OFF)
|
||||
set(SDLIMAGE_JXL OFF)
|
||||
|
||||
#download SDL if not installed
|
||||
#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})
|
||||
|
||||
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
|
||||
if(MSVC)
|
||||
target_compile_options(Witch-Game PRIVATE /W4 /WX)
|
||||
# target_compile_options(Witch-Game PRIVATE /W4 /WX)
|
||||
else()
|
||||
target_compile_options(Witch-Game PRIVATE -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue