-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFairy.cpp
More file actions
97 lines (73 loc) · 2.25 KB
/
Fairy.cpp
File metadata and controls
97 lines (73 loc) · 2.25 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
#include "Fairy.hpp"
#include "Enemy.hpp"
#include "Weapon.hpp"
Fairy::Fairy() {
loadHorizontalSpriteSheet("Resources/Textures/fairy.png",5);
setOrigin(8, 8);
_hp = 0;
velocity.x = 0.0; velocity.y = 0.0;
centerPosition.x = 0; centerPosition.y = 0;
_bounds = sf::IntRect(-5,-5,10,10);
}
Fairy::~Fairy() { }
void Fairy::draw(sf::RenderTarget* window) {
//deprecated
//this->setColor(sf::Color(255 , 0 + (255* (lifes+0.001)/maxLifes), 0 + (255* (lifes+0.001)/maxLifes), 255));
if( _hittedTime < 1 ) {
if(int(_hittedTime*10) %2) drawEffect(*window);
} else drawEffect(*window);
}
void Fairy::update(float deltatime, sf::Vector2f mousePos) {
updateAnimation(deltatime);
_hittedTime += deltatime;
_angle = getAngle(centerPosition, this->Effect::getPosition());
this->rotate(_angle - this->getRotation());
velocity.x = 0.8*velocity.x + 0.2*(mousePos.x - this->Effect::getPosition().x ) * deltatime;
velocity.y = 0.8*velocity.y + 0.2*(mousePos.y - this->Effect::getPosition().y ) * deltatime;
this->move(velocity);
cmove(velocity);
}
sf::Vector2f Fairy::getCenterPosition() const {
return centerPosition;
}
void Fairy::setCenterPosition(const sf::Vector2f &value) {
centerPosition = value;
}
float Fairy::getCenterAngle() const{
return _angle;
}
sf::Vector2f Fairy::getVelocity() const {
return velocity;
}
void Fairy::setVelocity(const sf::Vector2f &value) {
velocity = value;
}
sf::Vector2f Fairy::getPosition() const {
return sf::Sprite::getPosition();
}
sf::Vector2f Fairy::getBotPosition() {
return sf::Vector2f(_sprite.getPosition().x+_bounds.left+_bounds.width/2, _sprite.getPosition().y + TILESIZE);
}
float Fairy::getHp() const{
return _hp;
}
void Fairy::setHp(float value){
_hp = value;
}
void Fairy::getHit(float qtty, sf::Vector2f){
if(_hittedTime < 1) return;
_hittedTime = 0;
_hp -= qtty;
}
void Fairy::intersectsWith(Collisionable* c) {
Enemy* enemy = dynamic_cast<Enemy*>(c);
if (enemy != nullptr) {
getHit(enemy->getDamage(),sf::Vector2f(0,0));
return;
}
Weapon* weapon = dynamic_cast<Weapon*>(c);
if (weapon != nullptr) {
getHit(weapon->getDamage(),sf::Vector2f(0,0));
return;
}
}