-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLifeCounter.cpp
72 lines (59 loc) · 1.65 KB
/
LifeCounter.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
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
#include "LifeCounter.hpp"
LifeCounter::LifeCounter(){
init();
}
LifeCounter::LifeCounter(sf::Vector2f pos){
init();
_position.x = pos.x;
_position.y = pos.y;
}
void LifeCounter::init(){
_lifes = hardmode? PLAYERHPHARD: PLAYERHPNORMAL;
_hitted = false;
_scale = 0;
_position.x = 0;
_position.y = 0;
_sprite.setTexture(Resources::heart);
_sprite.setOrigin(0, _sprite.getGlobalBounds().height/2);
}
float LifeCounter::scale() const
{
return _scale;
}
void LifeCounter::setScale(float scale)
{
_scale = scale;
}
int LifeCounter::lifes() const { return _lifes; }
void LifeCounter::setLifes(int lifes, bool nohit) {
if(nohit && _lifes != lifes){
hit();
}
_lifes = lifes;
}
sf::Vector2f LifeCounter::position() const { return _position; }
void LifeCounter::setPosition(const sf::Vector2f &position) { _position = position; }
void LifeCounter::Update(float dt) {
_dtime = dt;
}
void LifeCounter::Draw(sf::RenderTarget * window){
for(int i = 0; i < _lifes; ++i){
_sprite.setPosition( _position.x+ i*_sprite.getGlobalBounds().width,
_position.y );
window->draw(_sprite);
}
if(_hitted && _scale > 0.1){
_sprite.setPosition( _position.x+ _lifes*_sprite.getGlobalBounds().width,
_position.y );
_sprite.setScale(_scale, _scale);
_scale -= 0.5*_dtime;
window->draw(_sprite);
_sprite.setScale(1,1);
} else {
_hitted = false; _scale = 0;
}
}
void LifeCounter::hit() {
_hitted = true;
_scale = 1;
}