macros and ui element

This commit is contained in:
2026-03-16 14:56:32 +01:00
parent 3a22a3746f
commit 29bb9ca0fe
11 changed files with 190 additions and 30 deletions

View File

@@ -6,15 +6,8 @@
#include <object/sound.hpp>
namespace Game::AGame {
class Background : public Object::Entity {
using Object::Entity::Entity;
public:
~Background() override = default;
void start() override;
void update(float deltaTime) override;
GAME_ENTITY(Background)
private:
Object::Sound mSound;
};
END_GAME_ENTITY()
}

View File

@@ -6,13 +6,8 @@
#include <object/sound.hpp>
namespace Game::AGame {
class CamController : public Object::Entity {
using Object::Entity::Entity;
GAME_ENTITY(CamController)
public:
~CamController() override = default;
void start() override;
void update(float deltaTime) override;
void onWindowResized(int newWidth, int newHeight) override {
mScreenW = newWidth;
mScreenH = newHeight;
@@ -20,5 +15,5 @@ namespace Game::AGame {
private:
int mScreenW, mScreenH;
};
END_GAME_ENTITY()
}

View File

@@ -6,16 +6,9 @@
#include <object/sound.hpp>
namespace Game::AGame {
class Player : public Object::Entity {
using Object::Entity::Entity;
public:
~Player() override = default;
void start() override;
void update(float deltaTime) override;
GAME_ENTITY(Player)
private:
Object::Sound mSound;
float mSpeed = 200.f; // Pixels per second
};
END_GAME_ENTITY()
}

View File

@@ -11,9 +11,18 @@ namespace Game {
static bool isKeyPressed(SDL_Scancode key);
static bool isKeyJustPressed(SDL_Scancode key);
static bool isKeyJustReleased(SDL_Scancode key);
static bool isMouseButtonPressed(Uint8 button);
static bool isMouseButtonJustPressed(Uint8 button);
static bool isMouseButtonJustReleased(Uint8 button);
static float getMouseX();
static float getMouseY();
private:
static const bool* mCurrentKeyStates;
static bool* mPreviousKeyStates;
static const bool* mPreviousKeyStates;
static int mNumKeys;
static SDL_MouseButtonFlags mCurrentMouseButtonStates;
static SDL_MouseButtonFlags mPreviousMouseButtonStates;
static float mMouseX;
static float mMouseY;
};
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include <object/entity.hpp>
#include <renderer/font.hpp>
#include <renderer/texture.hpp>
#include <utility>
#include <game/input.hpp>
namespace Game::Object {
class UIButton : public Entity {
public:
UIButton(const std::string& name, std::shared_ptr<Renderer::Texture> texture, const Transform& transform, void* clickFunction = nullptr, float x = 0.f, float y = 0.f);
~UIButton() override = default;
void start() override;
void update(float deltaTime) override;
void setText(const std::string& text);
std::string getText() const;
void setPosition(float x, float y) { mX = x; mY = y; }
std::pair<float, float> getPosition() const { return {mX, mY}; }
private:
void* mClickFunction = nullptr;
float mX, mY;
std::string mText;
};
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include <object/entity.hpp>
#include <renderer/font.hpp>
#include <renderer/texture.hpp>
#include <utility>
#include <game/input.hpp>
namespace Game::Object {
class UIText : public Entity {
public:
UIText(const std::string& name, std::shared_ptr<Renderer::Font> font, const Transform& transform, float x = 0.f, float y = 0.f);
~UIText() override = default;
void start() override;
void update(float deltaTime) override;
void setText(const std::string& text);
std::string getText() const;
void setPosition(float x, float y) { mX = x; mY = y; }
std::pair<float, float> getPosition() const { return {mX, mY}; }
private:
//void* mClickFunction = nullptr;
float mX, mY;
std::string mText;
};
}

View File

@@ -29,7 +29,11 @@
#define GAME_ENTITY(ClassName) \
class ClassName : public Object::Entity { \
using Object::Entity::Entity;
using Object::Entity::Entity; \
public: \
~ClassName() override = default; \
void start() override; \
void update(float deltaTime) override;
#define END_GAME_ENTITY() \
};