-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWatermelon.cpp
More file actions
70 lines (55 loc) · 1.58 KB
/
Copy pathWatermelon.cpp
File metadata and controls
70 lines (55 loc) · 1.58 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
#include "Watermelon.hpp"
const std::string WATERMELON_PIC_PATH = "extrafile/watermelon.png";
const float SCALE = .3f;
const int SPEED = 1;
const int DAMAGE = 15;
Watermelon::Watermelon(){
initTexture(WATERMELON_PIC_PATH);
initSprite(SCALE);
movementSpeed = SPEED;
damage = DAMAGE;
}
void Watermelon::initTexture(const std::string& texturePath){
this->texture.loadFromFile(texturePath);
}
void Watermelon::initSprite(float scale){
this->sprite.setTexture(this->texture);
this->sprite.scale(scale, scale);
this->sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2);
}
void Watermelon::move(const float dirX , const float dirY){
this->sprite.move(this->movementSpeed * dirX ,this->movementSpeed * dirY);
}
void Watermelon::render(sf::RenderTarget& target) {
target.draw(this->sprite);
}
void Watermelon::setPosition(float x, float y) {
this->sprite.setPosition(x, y);
}
sf::Sprite Watermelon::getSprite(){
return this->sprite;
}
void Watermelon::addStartPos(sf::Vector2f _startPos){
this->startPos = _startPos;
}
void Watermelon::addEndPos(float _EndPos){
this->endPos = _EndPos;
}
float Watermelon::middleOfDistance(){
return (endPos + startPos.x)/2 ;
}
sf::Vector2f Watermelon::position(){
return this->sprite.getPosition();
}
sf::Vector2f Watermelon::getStartPos(){
return this->startPos;
}
float Watermelon::getEndPos(){
return this->endPos;
}
void Watermelon::assignZombi(Zombie* _zombie){
this->zombie = _zombie;
}
void Watermelon::giveDamage(){
this->zombie->getDamage(this->damage);
}