-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathunit.h
100 lines (83 loc) · 2.85 KB
/
unit.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once
#include "battle_game/core/object.h"
#include "glm/glm.hpp"
namespace battle_game {
class Bullet;
class Unit : public Object {
public:
Unit(GameCore *game_core, uint32_t id, uint32_t player_id);
uint32_t &GetPlayerId() {
return player_id_;
}
[[nodiscard]] uint32_t GetPlayerId() const {
return player_id_;
}
void SetPosition(glm::vec2 position);
void SetRotation(float rotation);
[[nodiscard]] virtual float GetDamageScale() const;
[[nodiscard]] virtual float GetSpeedScale() const;
[[nodiscard]] virtual float BasicMaxHealth() const;
[[nodiscard]] virtual float GetHealthScale() const;
[[nodiscard]] virtual float GetMaxHealth() const {
return std::max(GetHealthScale() * BasicMaxHealth(), 1.0f);
}
/*
* Health value is in range [0, 1], represents the remaining health in ratio
* form. GetHealth() * GetMaxHealth() represent true remaining health of the
* unit.
* */
[[nodiscard]] float GetHealth() const {
return health_;
}
/*
* The value of new_health will be clamped to [0, 1]
* */
void SetHealth(float new_health) {
health_ = std::clamp(new_health, 0.0f, 1.0f);
}
void SetLifeBarLength(float new_length);
void SetLifeBarOffset(glm::vec2 new_offset);
void SetLifeBarFrontColor(glm::vec4 new_color);
void SetLifeBarBackgroundColor(glm::vec4 new_color);
void SetLifeBarFadeoutColor(glm::vec4 new_color);
[[nodiscard]] float GetLifeBarLength();
[[nodiscard]] glm::vec2 GetLifeBarOffset();
[[nodiscard]] glm::vec4 GetLifeBarFrontColor();
[[nodiscard]] glm::vec4 GetLifeBarBackgroundColor();
[[nodiscard]] glm::vec4 GetLifeBarFadeoutColor();
void ShowLifeBar();
void HideLifeBar();
virtual void RenderLifeBar();
/*
* This virtual function is used to render some extra helpers, such as
* predicted trajectory of the bullet the unit will shoot, and etc., only
* in the first-person perspective.
* */
virtual void RenderHelper();
/*
* This virtual function is used to check whether a bullet at the position
* have hit the unit. If the position is inside the unit area, then return
* true, otherwise return false.
* */
[[nodiscard]] virtual bool IsHit(glm::vec2 position) const = 0;
template <class BulletType, class... Args>
void GenerateBullet(glm::vec2 position,
float rotation,
float damage_scale = 1.0f,
Args... args);
[[nodiscard]] virtual const char *UnitName() const;
[[nodiscard]] virtual const char *Author() const;
protected:
uint32_t player_id_{};
float health_{1.0f};
bool lifebar_display_{true};
glm::vec2 lifebar_offset_{};
float lifebar_length_{2.4f};
glm::vec4 front_lifebar_color_{};
glm::vec4 background_lifebar_color_{};
glm::vec4 fadeout_lifebar_color_{};
private:
float fadeout_health_;
};
} // namespace battle_game
// add something to pull