-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hud.cpp
167 lines (142 loc) · 6.75 KB
/
Hud.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "hud.h"
namespace SSJ{
Hud::Hud() : Object(){
if(!this->consola.loadFromFile("./visitor1.ttf"))
std::cout << "Nie ma czcionki" << std::endl;
this->isReloading = false;
this->bulletHud.AddTexture("bulletHud", "./bulletHud.png");
this->reloadedBulletAmount = 1;
this->allBulletsReloadTime = 0;
}
Hud::~Hud(){
}
void Hud::draw(){
int ammo, allAmmo;
if(DataContainer::MainPlayer != NULL){
ammo = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getWeapon1()->getAmmo();
allAmmo = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getWeapon1()->getAllAmmo();
}
else{
ammo = 0;
allAmmo = 0;
}
std::string sAmmo = intToString(ammo) + "/" + intToString(allAmmo);
sf::Text tAmmo(sAmmo, consola);
tAmmo.setCharacterSize(30);
tAmmo.setColor(sf::Color::Cyan);
tAmmo.setPosition(10,DataContainer::ScreenHeight-80);
DataContainer::window->draw(tAmmo);
if(DataContainer::MainPlayer != NULL){
/**********************************
RELOADING ANIMATION
**********************************/
if(!this->isReloading){
this->bulletHud.getSprite()->setColor(sf::Color(255,255,255,255));
for(int i = 0, k = 0; i < ammo; i++, k+=5){
this->bulletHud.getSprite()->setPosition(10+k, DataContainer::ScreenHeight-40);
DataContainer::window->draw(*(this->bulletHud.getSprite()));
}
this->reloadedBulletAmount = 1;
this->allBulletsReloadTime = 0;
}
else{
this->bulletHud.getSprite()->setColor(sf::Color(255,255,255,60));
for(int i = 0, spriteDistance = 0; i < this->reloadedBulletAmount; i++, spriteDistance += 5){
this->bulletHud.getSprite()->setPosition(10+spriteDistance, DataContainer::ScreenHeight-40);
DataContainer::window->draw(*(this->bulletHud.getSprite()));
}
}
/**********************************
ACTIVE WEAPON DRAWING
**********************************/
std::string sWeaponPP = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getSelectedWeapon(-2)->getName();
sf::Text tWeaponPP(sWeaponPP, consola);
tWeaponPP.setCharacterSize(13);
tWeaponPP.setColor(sf::Color(Cornflower,80));
tWeaponPP.setPosition(10,DataContainer::ScreenHeight-147);
DataContainer::window->draw(tWeaponPP);
std::string sWeaponP = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getSelectedWeapon(-1)->getName();
sf::Text tWeaponP(sWeaponP, consola);
tWeaponP.setCharacterSize(20);
tWeaponP.setColor(sf::Color(Cornflower,120));
tWeaponP.setPosition(10,DataContainer::ScreenHeight-140);
DataContainer::window->draw(tWeaponP);
std::string sWeapon1 = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getSelectedWeapon(0)->getName();
sf::Text tWeapon1(sWeapon1, consola);
tWeapon1.setCharacterSize(30);
tWeapon1.setColor(sf::Color::Cyan);
tWeapon1.setPosition(10,DataContainer::ScreenHeight-130);
DataContainer::window->draw(tWeapon1);
std::string sWeaponN = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getSelectedWeapon(1)->getName();
sf::Text tWeaponN(sWeaponN, consola);
tWeaponN.setCharacterSize(20);
tWeaponN.setColor(sf::Color(Cornflower,120));
tWeaponN.setPosition(10,DataContainer::ScreenHeight-105);
DataContainer::window->draw(tWeaponN);
std::string sWeaponNN = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getSelectedWeapon(2)->getName();
sf::Text tWeaponNN(sWeaponNN, consola);
tWeaponNN.setCharacterSize(13);
tWeaponNN.setColor(sf::Color(Cornflower,80));
tWeaponNN.setPosition(10,DataContainer::ScreenHeight-87);
DataContainer::window->draw(tWeaponNN);
// WEAPON RANGE
sf::CircleShape weaponRange((float)this->currentRadius, 100);
weaponRange.setOutlineColor(sf::Color(Cornflower,120));
weaponRange.setOutlineThickness(3);
weaponRange.setPosition(dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getScreenPosition().x - (double)this->currentRadius,
dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getScreenPosition().y - (double)this->currentRadius);
weaponRange.setFillColor(sf::Color::Transparent);
DataContainer::window->draw(weaponRange);
// LIFE
sf::RectangleShape hpFrame(sf::Vector2f(100,20));
hpFrame.setFillColor(sf::Color::Transparent);
hpFrame.setOutlineColor(sf::Color(Cornflower,120));
hpFrame.setOutlineThickness(4);
hpFrame.setPosition(DataContainer::ScreenWidth-150, DataContainer::ScreenHeight-30);
DataContainer::window->draw(hpFrame);
int hp = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getHP();
int lackHp = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getMaxHP() - hp;
sf::RectangleShape rHp(sf::Vector2f(hp, 20));
rHp.setFillColor(sf::Color(Cornflower));
rHp.setPosition(DataContainer::ScreenWidth-150, DataContainer::ScreenHeight-30);
DataContainer::window->draw(rHp);
sf::RectangleShape rLackHp(sf::Vector2f(lackHp, 20));
rLackHp.setFillColor(sf::Color(Cornflower,60));
rLackHp.setPosition(DataContainer::ScreenWidth-150+hp, DataContainer::ScreenHeight-30);
DataContainer::window->draw(rLackHp);
std::string sfrags = "DEATHS: " + intToString(dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getFrags());
sf::Text tfrags(sfrags, consola);
tfrags.setCharacterSize(30);
tfrags.setColor(sf::Color::Cyan);
tfrags.setPosition(DataContainer::ScreenWidth/2,50);
DataContainer::window->draw(tfrags);
}
}
void Hud::update(){
if(DataContainer::MainPlayer != NULL){
if(dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getWeapon1()->getReloading()){
this->isReloading = true;
this->timeBetweenReloadingBullets = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getWeapon1()->getReloadClockElapsedTime();
int reloadTime = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getWeapon1()->getReloadTime();
int bulletAmount = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getWeapon1()->getAmmoInMag();
float bulletReloadTime = (float)reloadTime / (float)bulletAmount;
if(this->timeBetweenReloadingBullets.asSeconds() > allBulletsReloadTime && this->reloadedBulletAmount != bulletAmount){
this->allBulletsReloadTime = (double)this->reloadedBulletAmount * (double)bulletReloadTime;
this->reloadedBulletAmount = (this->timeBetweenReloadingBullets.asSeconds() / reloadTime) * bulletAmount;
if(this->reloadedBulletAmount == 0) reloadedBulletAmount = 1;
if(this->reloadedBulletAmount > bulletAmount){
this->reloadedBulletAmount = bulletAmount;
}
}
}
else{
this->isReloading = false;
this->reloadedBulletAmount = 1;
this->allBulletsReloadTime = 0;
}
this->currentRadius = dynamic_cast<MainPlayer*>(DataContainer::MainPlayer)->getWeapon1()->getRange();
}
}
void Hud::SynchronizationObject(Json::Value){
}
}