40 lines
853 B
C++
40 lines
853 B
C++
#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"
|
|
|
|
constexpr int HORIZONTAL_SPEED = 10;
|
|
|
|
class GameObject {
|
|
public:
|
|
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;
|
|
|
|
};
|