more component stuff

This commit is contained in:
Josh Lyon
2025-08-13 22:21:37 -06:00
parent f6de0ed9f3
commit 7259d9307b
8 changed files with 151 additions and 43 deletions

View File

@@ -1,18 +1,39 @@
#pragma once
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_rect.h>
#include <memory>
#include "GameState.h"
#include "Graphics.h"
#include "components/GraphicsComponent.h"
#include "components/InputComponent.h"
class GameObject : std::enable_shared_from_this<GameObject> {
constexpr int HORIZONTAL_SPEED = 10;
class GameObject {
public:
GameObject(std::unique_ptr<GraphicsComponent> graphics)
: m_graphics(std::move(graphics)) {}
GameObject(
std::unique_ptr<GraphicsComponent> graphics,
std::unique_ptr<InputComponent> input)
: m_graphics(std::move(graphics))
, m_input(std::move(input))
{ /* Intentionally empty */ }
void update(Graphics &graphics) {
if (m_input->moveUp) {
speed.x = HORIZONTAL_SPEED;
}
m_graphics->update(graphics);
}
GameState processInput(SDL_Event const* event) {
return m_input->update(event);
}
private:
std::unique_ptr<GraphicsComponent> m_graphics;
std::unique_ptr<InputComponent> m_input;
SDL_Point speed;
};