forked from Yao-class-cpp-studio/battle_game_2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.h
43 lines (39 loc) · 1.13 KB
/
object.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include "battle_game/graphics/graphics.h"
#include "glm/glm.hpp"
#define SKILL_ADD_FUNCTION(function_) std::bind(&function_, this)
#define SKILL_SWITCH_BULLET(function_) \
std::bind(&function_, this, std::placeholders::_1)
#define SKILL_ADD_NULL nullptr
namespace battle_game {
class GameCore;
class Object {
public:
Object(GameCore *game_core,
uint32_t id,
glm::vec2 position = glm::vec2{0.0f},
float rotation = 0.0f);
virtual ~Object();
[[nodiscard]] glm::vec2 LocalToWorld(glm::vec2 p) const;
[[nodiscard]] glm::vec2 WorldToLocal(glm::vec2 p) const;
[[nodiscard]] glm::vec2 GetPosition() const {
return position_;
}
[[nodiscard]] float GetRotation() const {
return rotation_;
}
[[nodiscard]] GameCore *GetGameCore() const {
return game_core_;
}
[[nodiscard]] uint32_t GetId() const {
return id_;
}
virtual void Render() = 0;
virtual void Update() = 0;
protected:
GameCore *game_core_{nullptr};
glm::vec2 position_{0.0f}; // offset from the origin (0, 0)
float rotation_{0.0f}; // angle in radians
uint32_t id_{0};
};
} // namespace battle_game