-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.cpp
More file actions
135 lines (113 loc) · 2.74 KB
/
Copy pathEntity.cpp
File metadata and controls
135 lines (113 loc) · 2.74 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "Entity.hpp"
#include <iostream>
#include <raymath.h>
#include "Constants.hpp"
Entity::Entity(
const char* name,
EntityType entityType,
float healthPoints,
Vector2 position,
Animation* idleAnimation,
Animation* deathAnimation,
Animation* attackAnimation,
Animation* damageAnimation,
MoveType weakness) {
m_Name = name;
m_EntityType = entityType;
m_HealthPoints = healthPoints;
m_Position = position;
m_IdleAnimation = idleAnimation;
m_DeathAnimation = deathAnimation;
m_AttackAnimation = attackAnimation;
m_DamageAnimation = damageAnimation;
m_Movements.reserve(Constants::MAX_MOVEMENTS);
m_Weakness = weakness;
// The current animation is always "idle", unless another
// system actively changes it.
m_CurrentAnimation = m_IdleAnimation;
}
Entity::~Entity() {
// Freeing all the animations
if (m_IdleAnimation != NULL) {
delete m_IdleAnimation;
}
if (m_DeathAnimation != NULL) {
delete m_DeathAnimation;
}
if (m_AttackAnimation != NULL) {
delete m_AttackAnimation;
}
if (m_DamageAnimation != NULL) {
delete m_DamageAnimation;
}
// Freeing the movements
for (const Move* move : m_Movements) {
delete move;
}
}
float Entity::GetHealthPoints() const {
return m_HealthPoints;
}
const char* Entity::GetName() const {
return m_Name;
}
Vector2 Entity::GetPosition() const {
return m_Position;
}
const EntityType& Entity::GetEntityType() const {
return m_EntityType;
}
void Entity::PlayAnimation(AnimationType animationType) {
// The animation that is currently playing should have its
// state reset so that, when played again,
// it should always start at the first frame.
m_CurrentAnimation->ResetState();
switch (animationType)
{
case Idle:
m_CurrentAnimation = m_IdleAnimation;
break;
case Attack:
m_CurrentAnimation = m_AttackAnimation;
break;
case Damage:
m_CurrentAnimation = m_DamageAnimation;
break;
case Death:
m_CurrentAnimation = m_DeathAnimation;
break;
}
}
const Animation* Entity::GetCurrentAnimation() const {
return m_CurrentAnimation;
}
void Entity::Update() {
if (m_CurrentAnimation != NULL) {
if (m_CurrentAnimation->GetAnimationType() != AnimationType::Idle &&
m_CurrentAnimation->PlayedAnimationOnce()) {
PlayAnimation(AnimationType::Idle);
}
m_CurrentAnimation->Update(GetHealthPoints() > 0 ? WHITE : GRAY);
}
}
void Entity::AddMove(Move* move) {
m_Movements.push_back(move);
}
const std::vector<Move*>& Entity::GetMoves() const {
return m_Movements;
}
void Entity::RemoveHealth(float damage)
{
m_HealthPoints -= damage;
}
void Entity::AddHealth(float healing) {
m_HealthPoints += Clamp(m_HealthPoints + healing, 0, 98);
}
void Entity::SetHealth(float healthPoints)
{
m_HealthPoints = healthPoints;
}
MoveType Entity::GetWeakness() const
{
return m_Weakness;
}