-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacter.cpp
134 lines (104 loc) · 2.81 KB
/
Character.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
#include "Character.h"
#include "OtherFuncsAndVariables.h"
#include <Windows.h>
#include <MMSystem.h>
//// MÉTODOS CLASE CHARACTER ////
//* Constructores *//
Character::Character() : Model() {
this->health = 0;
this->weapon = Weapon();
this->size = 0.0;
}
Character::Character(const Vector3D& position, const Color& color, const Vector3D& speed,
const Vector3D& orientation, int health, Weapon& weapon, float size)
: Model(position, color, speed, orientation) {
this->health = health;
this->weapon = weapon;
this->size = size;
}
//* Getters *//
int Character::getHealth() const {
return this->health;
}
Weapon Character::getWeapon() {
return this->weapon;
}
float Character::getSize() const {
return this->size;
}
//* Setters *//
void Character::setHealth(int h) {
this->health = h;
}
void Character::setWeapon(const Weapon& w) {
this->weapon = w;
}
void Character::setSize(const float& s) {
this->size = s;
}
//* Arma *//
//Disparar
bool Character::shoot() {
//Si no hay munición
if (this->weapon.getAmmunition() == 0) {
//Devolución de false
return 0;
}
//Actualización de las balas
this->weapon.setAmmunition((this->weapon.getAmmunition()) - 1);
//Actualización del color en consola en función de las balas restantes
if (this->weapon.getAmmunition() < 4) {
changeColorConsole(4);
}
else {
changeColorConsole(7);
}
//Impresión en la consola
goToXY(12, 10);
cout << this->weapon.getAmmunition();
//Reproducción del sonido disparar
PlaySound(TEXT("shoot.wav"), NULL, SND_ASYNC);
//Devolución de true
return 1;
}
//Recargar
void Character::reload() {
//Si el tamaño del cilindro es mayor de 0
if (this->weapon.getCylinderSize() > 0) {
//Cálculo de la cantidad a recargar
int diffAmmo = this->weapon.getInitialAmmunition() - this->weapon.getAmmunition();
//Actualización del cilindro
this->weapon.setCylinderSize(this->weapon.getCylinderSize() - diffAmmo);
//Si es menor que 0
if (this->weapon.getCylinderSize() < 0) {
//Cálculo de las balas restantes
int d = 0 - this->weapon.getCylinderSize();
//Actualización del cilindro
this->weapon.setCylinderSize(0);
//Actualización de las balas a recargar
diffAmmo -= d;
}
//Actualización de las balas
this->weapon.setAmmunition(this->weapon.getAmmunition() + diffAmmo);
//Cambio del color en función de las balas en el cilindro
if (this->weapon.getCylinderSize() < 9 || this->weapon.getAmmunition() < 4) {
changeColorConsole(4);
}
else {
changeColorConsole(7);
}
//Impresión de datos en la consola
goToXY(12,10);
cout << this->weapon.getAmmunition();
goToXY(16,10);
cout << this->weapon.getCylinderSize() << " ";
//Reproducción de sonido de recarga
PlaySound(TEXT("reload.wav"), NULL, SND_ASYNC);
}
}
//* Otros *//
/*void Character::render() const {
}
void Character::update() {
}
*/