-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJugadores.h
159 lines (142 loc) · 4.96 KB
/
Jugadores.h
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
#ifndef JUGADORES_H
#define JUGADORES_H
#include"Intf_Jugador.h"
#include"Intf_Bloque.h"
#include"Escopeta.h"
#include"Pistola.h"
#include"Espada.h"
#include<iostream>
using namespace std;
class Jugadores:public Intf_Jugador{
public:
//constructores y destructor
Jugadores(float _vida, string _nombre){
this->vida=_vida;
this->nombre=_nombre;
this->textura.loadFromFile("Assets/LargeEliteKnight_Idle_1.png");
this->sprite.setTexture(textura);
this->sprite.setPosition(100.f, 100.f);
this->sprite.setScale(1.5f,1.5f);
this->sprite.setOrigin(8.f, 23.5f);
lista_de_Armas[2]=make_shared<Espada>();
lista_de_Armas[1]=make_shared<Pistola>();
lista_de_Armas[0]=make_shared<Escopeta>();
armaLista=lista_de_Armas[0];
}
~Jugadores(){}
//Metodos
void takeDamage(float danio)override{
if(escudo>0){
escudo-=danio;
if(escudo<0){
vida-=escudo;
escudo=0;
}
}
else{
vida-=danio;
}
}
void toString()const override{
cout << "Mi nombre es : " <<nombre << " y tenbgo de vida : " <<vida <<" escudo : " << escudo << endl;
}
//GET AND SET
float getVida()const override{
return this->vida;
}
float getEscudo()const override {
return this->escudo;
}
void addVida(float n_vida)override{
this->vida = vida + n_vida;
}
void addEscudo(float n_escudo)override {
this->escudo = escudo + n_escudo;
}
void setVida(float n_vida)override {
this->vida = n_vida;
}
void addVelocidad() {
velocidad += 0.01f;
}
//...
float getArmor()const override{
return 0;
}
//dibujar
void draw(RenderTarget& target, RenderStates states)const override{
target.draw(sprite,states);
target.draw(*armaLista,states);
}
FloatRect getBounds() const override{
return sprite.getGlobalBounds();
}
void update(View& v,RenderWindow & w,vector<unique_ptr<Proyectil>> & disparos,FlyFactory * fabrica)override{
//eventos teclado movimineto
Vector2f mover = { 0,0 };
if (Keyboard::isKeyPressed(Keyboard::W)) {
mover.y = -velocidad;
}
else if (Keyboard::isKeyPressed(Keyboard::S)) {
mover.y = +velocidad;
}
if (Keyboard::isKeyPressed(Keyboard::D)) {
mover.x = +velocidad;
}
else if (Keyboard::isKeyPressed(Keyboard::A)) {
mover.x = -velocidad;
}
//eventos Teclado Armas
if(Keyboard::isKeyPressed(Keyboard::Num1)){
if(armaLista!=lista_de_Armas[0]){
armaLista=lista_de_Armas[0];
}
}
else if(Keyboard::isKeyPressed(Keyboard::Num2)){
if(armaLista!=lista_de_Armas[1]){
armaLista=lista_de_Armas[1];
}
}
else if(Keyboard::isKeyPressed(Keyboard::Num3)){
if(armaLista!=lista_de_Armas[2]){
armaLista=lista_de_Armas[2];
}
}
//mueve el sprite y la vista
armaLista->atacar(w,disparos,fabrica,sprite.getPosition());
sprite.move(mover);
v.setCenter(sprite.getPosition());
armaLista->setPosicion(sprite.getPosition());
}
virtual Vector2f getPosition()override {
return sprite.getPosition();
}
void detector(Intf_Bloque & r2) override{
if (colisiona(r2)) {
FloatRect f_r1 = getBounds();
FloatRect f_r2 = r2.getBounds();
float solapaminetoX = min(f_r1.left + f_r1.width, f_r2.left + f_r2.width) - max(f_r1.left, f_r2.left);
float solapaminetoY = min(f_r1.top + f_r1.height, f_r2.top + f_r2.height) - max(f_r1.top, f_r2.top);
if (solapaminetoX < solapaminetoY) {
if (f_r1.left < f_r2.left) {
sprite.move(-solapaminetoX, 0);
}
else {
sprite.move(solapaminetoX, 0);
}
}
else {
if (f_r1.top < f_r2.top) {
sprite.move(0, -solapaminetoY);
}
else {
sprite.move(0, solapaminetoY);
}
}
}
else if(armaLista->colisiona(r2)&&Mouse::isButtonPressed(Mouse::Left)){
r2.recibirDanio(500);
}
}
};
#endif // JUGADORES_H