-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weapon.cpp
103 lines (76 loc) · 2.14 KB
/
Weapon.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
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
98
99
100
101
102
103
#include "stdafx.h"
#include "Weapon.h"
// private: FUnctions:
void Weapon::initVariables()
{
this->level = 0;
this->damageMin = 0;
this->damageMax = 0;
this->range = 0.f;
// Timer
this->attackTimer.restart();
this->attackTimerMax = 0; // Milliseconds
}
void Weapon::initTexture(const std::string file_path)
{
if (!this->weaponTexture.loadFromFile(file_path))
{
std::string className = typeid(*this).name();
className.erase(0, 6);
std::cout << "ERROR::" << className << "::initTexture::Failed to load " << file_path << std::endl;
}
}
// Constructors and Destructor:
Weapon::Weapon(const int level, const int value, const std::string& texture_file_path)
: Item(level, value)
{
this->initVariables();
this->initTexture(texture_file_path);
// weaponTexture.loadFromFile("Resources/Images/Sprites/Player/sword.png");
// weaponTexture.loadFromFile("Resources/Images/Sprites/Player/minigun_64x64_red_big.png");
this->weaponSprite.setTexture(this->weaponTexture);
}
Weapon::Weapon(const int level, const int damage_min, const int damage_max, const float range, const int value, const std::string& texture_file_path)
: Item{level, value}
{
this->initVariables();
this->damageMin = damage_min;
this->damageMax = damage_max;
this->range = range;
this->initTexture(texture_file_path);
this->weaponSprite.setTexture(this->weaponTexture);
}
Weapon::~Weapon()
{
}
// Accessors:
const int& Weapon::getDamageMin() const
{
return this->damageMin;
}
const int& Weapon::getDamageMax() const
{
return this->damageMax;
}
const int Weapon::getDamage() const
{
// return rand() % (this->damageMax + 1) + this->damageMin;
std::random_device seed;
std::mt19937 random_damage(seed());
std::uniform_int_distribution<int> generated(this->damageMin, this->damageMax);
return generated(random_damage);
}
const float& Weapon::getRange() const
{
return this->range;
}
const bool Weapon::getAttackTimer()
{
// std::cout << "Attack timer: " << this->attackTimer.getElapsedTime().asMilliseconds() << std::endl;
if (this->attackTimer.getElapsedTime().asMilliseconds() >= this->attackTimerMax)
{
this->attackTimer.restart();
return true;
}
return false;
}