-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSword.cpp
More file actions
72 lines (58 loc) · 1.38 KB
/
Sword.cpp
File metadata and controls
72 lines (58 loc) · 1.38 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
#include "stdafx.h"
#include "Sword.h"
//Constructors and Destructor:
Sword::Sword
(
const int level, const int damage_min, const int damage_max, const float range,
const int value,
const std::string& texture_file_path
)
: MeleeWeapon(level, damage_min, damage_max, range, value, texture_file_path)
{
this->weaponSprite.setOrigin
(
this->weaponSprite.getGlobalBounds().width / 2.f,
this->weaponSprite.getGlobalBounds().height
);
this->damageMin = damage_min;
this->damageMax = damage_max;
this->range = range;
// Timer
this->attackTimerMax = 500; // Milliseconds
}
Sword::~Sword()
{
}
//Functions:
Sword* Sword::clone()
{
return new Sword(*this);
}
void Sword::update(const sf::Vector2f& mouse_position_view, const sf::Vector2f center)
{
//Updating visual weapon
this->weaponSprite.setPosition(center);
float dX = mouse_position_view.x - this->weaponSprite.getPosition().x;
float dY = mouse_position_view.y - this->weaponSprite.getPosition().y;
const float PI = 3.141592f;
float deg = atan2(dY, dX) * 180.f / PI;
if (this->attackTimer.getElapsedTime().asMilliseconds() < this->attackTimerMax)
{
this->weaponSprite.rotate(30.f);
}
else
{
this->weaponSprite.setRotation(deg + 90.f);
}
}
void Sword::render(sf::RenderTarget& target, sf::Shader* shader)
{
if (shader)
{
target.draw(this->weaponSprite, shader);
}
else
{
target.draw(this->weaponSprite);
}
}