basic movement

This commit is contained in:
2026-03-14 22:27:54 +01:00
parent b19f595daf
commit 2983b919cd
24 changed files with 368 additions and 57 deletions

24
include/object/camera.hpp Normal file
View File

@@ -0,0 +1,24 @@
#pragma once
#include <utils.hpp>
#include <mutex>
namespace Game::Object {
class Camera {
public:
Camera() = default;
DISABLE_COPY_AND_MOVE(Camera)
~Camera() = default;
static Camera& getInstance();
void setPosition(float x, float y);
void getPosition(float& x, float& y) const;
void move(float deltaX, float deltaY);
private:
mutable std::mutex mMutex;
float mX = 0.0f;
float mY = 0.0f;
};
}

View File

@@ -7,6 +7,7 @@
#include <SDL3_image/SDL_image.h>
#include <utility>
#include <memory>
#include <renderer/renderer.hpp>
namespace Game::Renderer {
class Renderer;
@@ -24,9 +25,12 @@ namespace Game::Object {
Entity& operator=(Entity&&) noexcept;
virtual ~Entity() = 0;
// Start is called when the entity is spawned
virtual void start() = 0;
// Update is called every update cycle; deltaTime is the time (in seconds) since the last update call
virtual void update(float deltaTime) = 0;
void render(Game::Renderer::Renderer* renderer);
virtual void onWindowResized(int newWidth, int newHeight) {} // Called when the window is resized, with the new width and height in pixels
void render(Game::Renderer::Renderer* renderer, Game::Renderer::RendererConfig config);
// Setters and getters
void setTexture(std::shared_ptr<Game::Renderer::Texture> tex) { mTex = tex; }
@@ -37,12 +41,15 @@ namespace Game::Object {
std::string getName() { return mName; }
Transform* getTransform() { return &mTransform; }
bool isActive() { return mIsActive; }
int getZIndex() const { return mZIndex; }
protected:
std::string mName;
std::shared_ptr<Game::Renderer::Texture> mTex;
Transform mTransform;
bool mIsActive;
int mZIndex = 0; // For rendering order; higher zIndex renders on top of lower zIndex
float mTiledScale = 1.f; // Only used if the texture is tiled, to determine how much to scale the texture when rendering (since the entire texture is rendered as a single tile, this is necessary to be able to have different sized tiles)
private:
float mScaleConstant = 0.25f;
};
}

View File

@@ -5,6 +5,8 @@ namespace Game::Object {
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};