forked from WenlinMao/SleepWalking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthBarObject.cpp
More file actions
85 lines (65 loc) · 1.86 KB
/
Copy pathHealthBarObject.cpp
File metadata and controls
85 lines (65 loc) · 1.86 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
/**
* @ Author: Wenlin Mao
* @ Create Time: 2021-10-30 18:35:37
* @ Modified by: Wenlin Mao
* @ Modified time: 2021-11-30 02:11:48
* @ Description: implementation of square object
*/
#include "HealthBarObject.hpp"
#include "Inivar.hpp"
#include "PlayerStats.hpp"
HealthBarObject::HealthBarObject(){
}
HealthBarObject::HealthBarObject(float maxHealth, const glm::vec3& pos,
float w, float h, const std::string& filename):
UIObject(10.f, glm::vec3(pos.x - w/2.f, pos.y, pos.z), filename),
width(w), height(h), maxWidth(w){
color = glm::vec4(1.0f, 0.0f, 0.0f, 0.6f);
step = w / maxHealth;
createVerts();
prepareDraw();
}
HealthBarObject::~HealthBarObject(){}
void HealthBarObject::createVerts(){
vertex_positions = vector<glm::vec4>({
glm::vec4(width, height/2, 0.0f, 1.0f), // top right
glm::vec4(width, -height/2, 0.0f, 1.0f), // bottom right
glm::vec4(0.f, -height/2, 0.0f, 1.0f), // bottom left
glm::vec4(0.f, height/2, 0.0f, 1.0f) // top left
});
vertex_texcoords = vector<glm::vec2>({
glm::vec2(1.f,1.f),
glm::vec2(1.f,0.f),
glm::vec2(0.f,0.f),
glm::vec2(0.f,1.f)
});
indices = std::vector<unsigned int>({ 0, 1, 2, 2, 3, 0 });
}
void HealthBarObject::reset(){
GameObject::reset();
vertex_positions.clear();
}
void HealthBarObject::setHealth(float w){
width = w * step;
vertex_positions.clear();
createVerts();
prepareDraw();
}
void HealthBarObject::increase(){
if (width + step < maxWidth)
width += step;
else
width = maxWidth;
vertex_positions.clear();
createVerts();
prepareDraw();
}
void HealthBarObject::decrease(){
if (width - step > 0.f)
width -= step;
else
width = 0.f;
vertex_positions.clear();
createVerts();
prepareDraw();
}