input, changes

This commit is contained in:
2026-03-16 08:21:04 +01:00
parent d522881358
commit f6a1e59ebb
12 changed files with 109 additions and 44 deletions

View File

@@ -19,8 +19,6 @@ namespace Game::AGame {
}
private:
float mSpeed = 200.f; // Pixels per second
int mScreenW, mScreenH;
int mEdgeTolerance = 200;
};
}

View File

@@ -8,6 +8,9 @@
#include <chrono>
#include <functional>
#include <object/camera.hpp>
#include <game/input.hpp>
#include <unordered_map>
#include <memory>
namespace Game {
using clock = std::chrono::steady_clock;
@@ -22,8 +25,14 @@ namespace Game {
void run(std::stop_token stopToken);
void setTargetUpdatesPerSecond(int target) { mTargetUpdatesPerSecond = target; }
int getTargetUpdatesPerSecond() { return mTargetUpdatesPerSecond; }
static void setSharedData(const std::string& key, std::string data);
static std::string getSharedData(const std::string& key);
static void removeSharedData(const std::string& key);
private:
int mTargetUpdatesPerSecond = TARGET_UPDATE_RATE;
clock::time_point mLastUpdate;
static std::unordered_map<std::string, std::string> mSharedStrings;
};
}

19
include/game/input.hpp Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include <SDL3/SDL.h>
namespace Game {
class Input {
public:
Input() = delete;
static void update();
static bool isKeyPressed(SDL_Scancode key);
static bool isKeyJustPressed(SDL_Scancode key);
static bool isKeyJustReleased(SDL_Scancode key);
private:
static const bool* mCurrentKeyStates;
static bool* mPreviousKeyStates;
static int mNumKeys;
};
}

View File

@@ -1,13 +1,13 @@
#pragma once
namespace Game::Object {
typedef struct {
struct Transform {
float x, y;
float rotation; // In degrees, clockwise
float scaleX, scaleY;
float adjustedScaleX() const { return scaleX * UNIVERSAL_SCALE_COEFFICIENT; }
float adjustedScaleY() const { return scaleY * UNIVERSAL_SCALE_COEFFICIENT; }
} Transform;
};
constexpr Transform DEFAULT_TRANSFORM{0.f, 0.f, 0.f, 1.f, 1.f};
}

View File

@@ -24,6 +24,9 @@
#define ERROR(Msg) \
std::cout << "\033[31m[ERROR] " << __PRETTY_FUNCTION__ << ' ' << Msg << "\033[0m\n";
#define PLNIMP(Msg) \
std::cout << "\033[92m" << Msg << "\033[0m\n";
#define GAME_ENTITY(ClassName) \
class ClassName : public Object::Entity { \
using Object::Entity::Entity;