-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHealthBar.cpp
39 lines (31 loc) · 1.12 KB
/
HealthBar.cpp
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
#include "Player.h"
#include "HealthBar.h"
#include "Window.h"
void HealthBar::setHp(double x){
hp = x;
}
void HealthBar::setMaxHp(double x){
maxHp = x;
}
void HealthBar::drawBaseBar(sf::RenderWindow &window, float x, float y, double rotation, int xsize, int ysize){
baseBar.setSize(sf::Vector2f(xsize, ysize));
baseBar.setOrigin(0, ysize/2);
baseBar.setPosition(x-sin((rotation+angleMod)*pi/180.0)*dist, y+cos((rotation+angleMod)*pi/180.0)*dist);
baseBar.setFillColor(sf::Color(1,1,1));
window.draw(baseBar);
}
void HealthBar::updateHealthBar(float x, float y, double rotation, int xsize, int ysize){
healthBar.setSize(sf::Vector2f(xsize*hp/maxHp, ysize));
healthBar.setPosition(x-sin((rotation+angleMod-1.8)*pi/180.0)*(dist-1.5), y+cos((rotation+angleMod-1.8)*pi/180.0)*(dist-1.5));
healthBar.setOrigin(0, ysize/2);
healthBar.setFillColor(sf::Color(((maxHp-hp)/maxHp)*255, hp/maxHp*255, 0));
}
void HealthBar::drawHealthBar(sf::RenderWindow &window){
window.draw(healthBar);
}
void HealthBar::setDist(double x){
dist = x;
}
void HealthBar::setAngleMod(double x){
angleMod = x;
}