/
PersonajeJugador.cpp
135 lines (106 loc) · 3.51 KB
/
PersonajeJugador.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
#include "PersonajeJugador.h"
#include <SDL2/SDL_mixer.h>
int c=0;
void loop_Gameover();
PersonajeJugador::PersonajeJugador(int x, int y,
SDL_Renderer* renderer,
list<Personaje*>*personajes)
{
this->rectangulo.x = x;
this->rectangulo.y = y;
this->personajes=personajes;
SDL_Texture *textura = IMG_LoadTexture(renderer, "assets/personaje/down1.png");
SDL_QueryTexture(textura, NULL, NULL, &this->rectangulo.w, &this->rectangulo.h);
texturas_down.push_back(textura);
texturas_down.push_back(IMG_LoadTexture(renderer, "assets/personaje/down2.png"));
texturas_up.push_back(IMG_LoadTexture(renderer, "assets/personaje/up1.png"));
texturas_up.push_back(IMG_LoadTexture(renderer, "assets/personaje/up2.png"));
texturas_left.push_back(IMG_LoadTexture(renderer, "assets/personaje/left1.png"));
texturas_left.push_back(IMG_LoadTexture(renderer, "assets/personaje/left2.png"));
texturas_right.push_back(IMG_LoadTexture(renderer, "assets/personaje/right1.png"));
texturas_right.push_back(IMG_LoadTexture(renderer, "assets/personaje/right2.png"));
orientacion="down";
textura_actual=texturas_down.begin();
}
PersonajeJugador::~PersonajeJugador()
{
//dtor
}
void PersonajeJugador::logic(Uint8* teclas_presionadas)
{
Mix_Chunk *Sonido = NULL;
Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 );
Sonido = Mix_LoadWAV("sound.wav");
SDL_Rect temp = this->rectangulo;
if( teclas_presionadas[ SDL_SCANCODE_UP ] )
{
rectangulo.y-=1;
if(orientacion!="up")
textura_actual=texturas_up.begin();
orientacion="up";
}
if( teclas_presionadas[ SDL_SCANCODE_DOWN ] )
{
rectangulo.y+=1;
if(orientacion!="down")
textura_actual=texturas_down.begin();
orientacion="down";
}
if( teclas_presionadas[ SDL_SCANCODE_RIGHT ] )
{
rectangulo.x+=1;
if(orientacion!="right")
textura_actual=texturas_right.begin();
orientacion="right";
}
if( teclas_presionadas[ SDL_SCANCODE_LEFT ] )
{
rectangulo.x-=1;
if(orientacion!="left")
textura_actual=texturas_left.begin();
orientacion="left";
}
// if( teclas_presionadas[ SDL_SCANCODE_X ] )
// {
// SDL_Renderer* renderer2;
// SDL_Rect rect_character;
// SDL_Texture *poder = IMG_LoadTexture(renderer2, "assets/llamas/01.png");
//
//SDL_RenderCopy(renderer2,poder, NULL, &rect_character);
//
// SDL_RenderCopy(renderer2, poder, NULL, &rect_character);
// SDL_RenderPresent(renderer2);
//// rectangulo.x-=1;
//// if(orientacion!="left")
//// textura_actual=texturas_left.begin();
//// orientacion="left";
// }
// for(list<Personaje*>::iterator i = personajes->begin();
// i!=personajes->end();
// i++)
// {
// if(this==(*i))
// continue;
// if(colision(this->rectangulo, (*i)->rectangulo))
// {
// rectangulo=temp;
// c+=1;
// break;
// }
// }
// cout<<c;
for(list<Personaje*>::iterator i = personajes->begin();
i!=personajes->end();
i++)
{
if(this==(*i))
continue;
if(colision(this->rectangulo, (*i)->rectangulo)&&teclas_presionadas[ SDL_SCANCODE_X ])
{
//rectangulo=temp;
personajes->erase(i);
Mix_PlayChannel( -1, Sonido, 0 );
break;
}
}
}