more component stuff
This commit is contained in:
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user