37 lines
1.0 KiB
C++
37 lines
1.0 KiB
C++
#pragma once
|
|
#include "J3ML/LinearAlgebra/Vector2.hpp"
|
|
#include <vector>
|
|
|
|
class Entity {
|
|
protected:
|
|
std::vector<Entity*> children{};
|
|
Vector2 position = {0, 0};
|
|
// Assuming 0 radians is up.
|
|
float face_angle = 0.0f;
|
|
void UpdateChildren();
|
|
public:
|
|
// Movements independent of the rotation.
|
|
void MoveX(float speed);
|
|
void MoveY(float speed);
|
|
|
|
// Movements dependent on face angle.
|
|
void MoveForward(float speed);
|
|
void MoveBackward(float speed);
|
|
void MoveLeft(float speed);
|
|
void MoveRight(float speed);
|
|
|
|
void Rotate(float speed);
|
|
void SetRotation(float new_rotation);
|
|
|
|
[[nodiscard]] bool AppendChild(Entity* entity);
|
|
void DestroyChild(Entity* entity);
|
|
void RemoveChild(Entity* entity);
|
|
public:
|
|
[[nodiscard]] float GetRotation() const;
|
|
[[nodiscard]] Vector2 GetPosition() const;
|
|
public:
|
|
virtual void Update() {}
|
|
public:
|
|
explicit Entity(const Vector2& position, float rotation = 0.0f) : position(position), face_angle(rotation) {}
|
|
virtual ~Entity();
|
|
}; |