Skip to content

Commit a852f04

Browse files
committed
2 parents 7d42b02 + abb786f commit a852f04

File tree

7 files changed

+93
-51
lines changed

7 files changed

+93
-51
lines changed

src/accesorios/codigo.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#define PRESIONA_X 12
3838
#define PRESIONA_L 13
3939
#define PRESIONA_P 14
40-
40+
#define PRESIONA_C 15
4141
/* Dimensiones */
4242

4343
#define ANCHO_ESCENARIO 800
@@ -272,4 +272,11 @@
272272
#define COLISION_AVION_CON_POWERUP 14
273273

274274
#define VALOR_POWERUP_1500 1500
275+
276+
/* Eventos del escenarioJuego */
277+
278+
#define CONTINUA_PARTIDA 0
279+
#define RESETEA_PARTIDA 1
280+
#define CIERRA_PARTIDA 2
281+
275282
#endif //INC_1942OLDENAIT_CODIGO_HPP

src/accesorios/colisiones/colisionable.cpp

+17-16
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ Colisionable::Colisionable(float x, float y, float angulo, int tipoDeElemento){
2828
this->crearDisparoEnemigo(x, y, angulo);
2929
break;
3030
case TIPO_POWERUP_BONIFICACION:
31-
this->crearPowerUp(x,y,0);
32-
break;
33-
case TIPO_POWERUP_DESTRUIR_ENEMIGOS:
34-
this->crearPowerUp(x,y,0);
35-
break;
36-
case TIPO_POWERUP_DOS_AMETRALLADORAS:
37-
this->crearPowerUp(x,y,0);
38-
break;
39-
case TIPO_POWERUP_AVIONES_SECUNDARIOS:
40-
this->crearPowerUp(x,y,0);
41-
break;
42-
case TIPO_POWERUP_BONIFICACION_1500:
43-
this->crearPowerUp(x,y,0);
44-
break;
31+
this->crearPowerUp(x,y,0);
32+
break;
33+
case TIPO_POWERUP_DESTRUIR_ENEMIGOS:
34+
this->crearPowerUp(x,y,0);
35+
break;
36+
case TIPO_POWERUP_DOS_AMETRALLADORAS:
37+
this->crearPowerUp(x,y,0);
38+
break;
39+
case TIPO_POWERUP_AVIONES_SECUNDARIOS:
40+
this->crearPowerUp(x,y,0);
41+
break;
42+
case TIPO_POWERUP_BONIFICACION_1500:
43+
this->crearPowerUp(x,y,0);
44+
break;
4545
}
4646
}
4747

@@ -151,11 +151,11 @@ void Colisionable::crearPowerUp(float posX, float posY, float angulo){
151151
this->superficiePrincipal->rotar(angulo, xCentro, yCentro, TIPO_POWERUP);
152152
}
153153

154-
155154
void Colisionable::mover(float posX, float posY, float angulo, int tipoElemento){
156155
this->superficiePrincipal->mover(posX, posY);
157156
float xCentral = posX + (this->superficiePrincipal->getAncho() / 2);
158157
float yCentral = posY + (this->superficiePrincipal->getAlto() / 2);
158+
//this->superficiePrincipal->rotar(angulo, xCentral, yCentral);
159159
for(unsigned int i = 0; i < this->superficiesSecundarias.size(); i++){
160160
this->superficiesSecundarias[i]->mover(posX, posY);
161161
this->superficiesSecundarias[i]->rotar(angulo, xCentral, yCentral, tipoElemento);
@@ -277,6 +277,7 @@ float Colisionable::getExtremoSuperior(){
277277
extremoSuperior = superficiePrincipal->getIzqArriba()->getPosY();
278278
}
279279

280+
280281
if(extremoSuperior < superficiePrincipal->getDerArriba()->getPosY()){
281282
extremoSuperior = superficiePrincipal->getDerArriba()->getPosY();
282283
}
@@ -316,4 +317,4 @@ void Colisionable::proyectarColisionable(float timeStep) {
316317
posY += posY * timeStep;
317318
this->superficiePrincipal->getDerArriba()->setPosY(posY);
318319
this->superficiePrincipal->getIzqArriba()->setPosY(posY);
319-
}
320+
}

src/accesorios/colisiones/dimensionSuperficies.hpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
#define DISPARO_ENEMIGO_SUPERFICIE_ANCHO 10
3838
#define DISPARO_ENEMIGO_SUPERFICIE_ALTO 10
3939

40-
#define AVION_ENEMIGO_MEDIANO_ANCHO_1 25
41-
#define AVION_ENEMIGO_MEDIANO_ALTO_1 40
42-
#define OFFSET_AVION_ENEMIGO_MEDIANO_ANCHO_1 15
43-
#define OFFSET_AVION_ENEMIGO_MEDIANO_ALTO_1 5
44-
#define AVION_ENEMIGO_MEDIANO_ANCHO_2 55
45-
#define AVION_ENEMIGO_MEDIANO_ALTO_2 6
46-
#define OFFSET_AVION_ENEMIGO_ALTO_2 25
47-
#define OFFSET_ALTO_AVION_MEDIANO_DEFAULT 15
48-
#define OFFSET_ANCHO_AVION_MEDIANO_DEFAULT 6
49-
50-
#endif //INC_1942OLDENAIT_DIMENSIONSUPERFICIES_HPP_H
40+
#define AVION_ENEMIGO_MEDIANO_ANCHO_1 20
41+
#define AVION_ENEMIGO_MEDIANO_ALTO_1 20
42+
#define OFFSET_AVION_ENEMIGO_MEDIANO_ANCHO_1 25
43+
#define OFFSET_AVION_ENEMIGO_MEDIANO_ALTO_1 12
44+
#define AVION_ENEMIGO_MEDIANO_ANCHO_2 65
45+
#define AVION_ENEMIGO_MEDIANO_ALTO_2 5
46+
#define OFFSET_AVION_ENEMIGO_ALTO_2 41
47+
#define OFFSET_ALTO_AVION_MEDIANO_DEFAULT 20
48+
#define OFFSET_ANCHO_AVION_MEDIANO_DEFAULT 5
49+
50+
#endif //INC_1942OLDENAIT_DIMENSIONSUPERFICIES_HPP_H

src/juego/modelo/escenarioJuego.cpp

+40-12
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ void EscenarioJuego::agregarEtapa(Etapa * etapa) {
116116
this->etapas.push_back(etapa);
117117
}
118118

119-
bool EscenarioJuego::manejarEvento(int nroAvion, int evento) {
119+
int EscenarioJuego::manejarEvento(int nroAvion, int evento) {
120120
vector<Disparo *> disparo;
121-
bool resetea = false;
121+
int eventoIteracion = CONTINUA_PARTIDA;
122122
switch (evento) {
123123
case PRESIONA_R:
124-
resetea = true;
124+
eventoIteracion = RESETEA_PARTIDA;
125125
break;
126126
case PRESIONA_ESPACIO:
127127
disparo = avion(nroAvion)->disparar();
@@ -141,11 +141,13 @@ bool EscenarioJuego::manejarEvento(int nroAvion, int evento) {
141141
case PRESIONA_P:
142142
this->togglePausa();
143143
break;
144+
case PRESIONA_C:
145+
eventoIteracion = CIERRA_PARTIDA;
144146
default:
145147
avion(nroAvion)->manejarEvento(evento);
146148
break;
147149
}
148-
return resetea;
150+
return eventoIteracion;
149151
}
150152

151153
void EscenarioJuego::avanzarEtapa() {
@@ -189,6 +191,29 @@ void EscenarioJuego::reiniciarEtapas() {
189191

190192
}
191193

194+
void EscenarioJuego::terminarEtapas() {
195+
desactivar();
196+
pthread_mutex_lock(&mutexPowerUps);
197+
this->powerUps.clear();
198+
pthread_mutex_unlock(&mutexPowerUps);
199+
pthread_mutex_lock(&mutexListaEnemigos);
200+
this->enemigos.clear();
201+
pthread_mutex_unlock(&mutexListaEnemigos);
202+
pthread_mutex_lock(&mutexListaDisparosEnemigos);this->disparos.clear();
203+
this->disparosEnemigos.clear();
204+
pthread_mutex_unlock(&mutexListaDisparosEnemigos);
205+
pthread_mutex_lock(&mutexListaDisparos);this->disparos.clear();
206+
this->disparos.clear();
207+
pthread_mutex_unlock(&mutexListaDisparos);
208+
209+
while (!this->colaEventos.vacia()) {
210+
this->colaEventos.pop();
211+
}
212+
temporizador.detener();
213+
214+
this->etapas.clear();
215+
}
216+
192217
int EscenarioJuego::comenzarEtapa() {
193218
this->activar();
194219
scrollingOffset = 0;
@@ -234,7 +259,7 @@ int EscenarioJuego::mainLoop() {
234259
}
235260

236261
int EscenarioJuego::actualizarEstado(float timeStep) {
237-
bool resetear = false;
262+
int eventoIteracion = CONTINUA_PARTIDA;
238263
int eventoFinal = AVANZAR_ETAPA;
239264
if (this->posicionY < this->etapaActual()->getLongitud() - 800) {
240265
if (!this->pausado) {
@@ -253,7 +278,7 @@ int EscenarioJuego::actualizarEstado(float timeStep) {
253278
this->moverDisparos(timeStep);
254279
this->getProximoEnemigo();
255280
}
256-
resetear = this->manejarProximoEvento();
281+
eventoIteracion = this->manejarProximoEvento();
257282
} else {
258283
this->moverEnemigos(timeStep);
259284
this->moverDisparosEnemigos(timeStep);
@@ -282,9 +307,12 @@ int EscenarioJuego::actualizarEstado(float timeStep) {
282307
}
283308
}
284309
}
285-
if (resetear){
310+
if (eventoIteracion == RESETEA_PARTIDA){
286311
this->reiniciarEtapas();
287312
eventoFinal = REINICIAR_ESCENARIO;
313+
} else if (eventoIteracion == CIERRA_PARTIDA){
314+
this->terminarEtapas();
315+
eventoFinal = FINALIZAR_JUEGO;
288316
}
289317
return eventoFinal;
290318
}
@@ -351,19 +379,19 @@ int EscenarioJuego::jugar(bool serverActivo) {
351379
return comenzarEtapa();
352380
}
353381

354-
bool EscenarioJuego::manejarProximoEvento() {
355-
bool resetear = false;
382+
int EscenarioJuego::manejarProximoEvento() {
383+
int eventoIteracion = CONTINUA_PARTIDA;
356384
if (!this->colaEventos.vacia()) {
357385
pair<int, int> evento = this->colaEventos.pop();
358386
if (!this->pausado){
359-
resetear = this->manejarEvento(evento.first, evento.second);
387+
eventoIteracion = this->manejarEvento(evento.first, evento.second);
360388
} else {
361389
if (evento.second == PRESIONA_P || evento.second == PRESIONA_R){
362-
resetear = this->manejarEvento(evento.first, evento.second);
390+
eventoIteracion = this->manejarEvento(evento.first, evento.second);
363391
}
364392
}
365393
}
366-
return resetear;
394+
return eventoIteracion;
367395
}
368396

369397
void EscenarioJuego::pushEvento(pair<int, int> evento) {

src/juego/modelo/escenarioJuego.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ class EscenarioJuego {
8585
void agregarEtapa(Etapa * etapa);
8686
void avanzarEtapa();
8787
void reiniciarEtapas();
88+
void terminarEtapas();
8889
int comenzarEtapa();
8990
bool quedanEtapas();
9091
/* Enemigos */
9192
void getProximoEnemigo();
9293
/* Eventos */
93-
bool manejarProximoEvento();
94-
bool manejarEvento(int nroAvion, int evento);
94+
int manejarProximoEvento();
95+
int manejarEvento(int nroAvion, int evento);
9596
void pushEvento(pair<int, int> evento);
9697
/* mainLoop */
9798
int jugar(bool serverActivo);

src/juego/vista/escenarioVista.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ void EscenarioVista::pushEvento(SDL_Event evento){
328328
case SDLK_p:
329329
this->colaEventos.push((int)PRESIONA_P);
330330
break;
331+
case SDLK_c:
332+
this->colaEventos.push((int)PRESIONA_C);
331333
}
332334
} else if( evento.type == SDL_KEYUP && evento.key.repeat == 0 ) {
333335
switch( evento.key.keysym.sym )

src/net/servidor/servidor.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,18 @@ int Servidor::aceptar() {
225225
}
226226

227227
void Servidor::cerrar() {
228-
this->desactivarServidor();
229-
for (map<int, datosCliente>::iterator iterador = getClientes().begin(); iterador != getClientes().end(); iterador++) {
230-
int clienteActual = iterador->first;
231-
shutdown(clienteActual, 0);
232-
close(clienteActual);
233-
iterador->second.colaSalida.avisar();
228+
if (this->servidorActivo()) {
229+
this->desactivarServidor();
230+
for (map<int, datosCliente>::iterator iterador = getClientes().begin();
231+
iterador != getClientes().end(); iterador++) {
232+
int clienteActual = iterador->first;
233+
shutdown(clienteActual, 0);
234+
close(clienteActual);
235+
iterador->second.colaSalida.avisar();
236+
}
237+
cerrarSocket();
234238
}
235239

236-
cerrarSocket();
237-
238240
// Cerramos las colas.
239241
colaDeMensajes.avisar();
240242
this->escenario->desactivar();
@@ -407,9 +409,10 @@ void Servidor::desencolar() {
407409
int intEvento = Decodificador::popInt(clienteMensaje.second);
408410
int intJugador = clientes[clienteMensaje.first].nroJugador;
409411
pair <int, int> evento(intJugador, intEvento);
410-
if(intEvento != PRESIONA_X){
412+
if(intEvento != PRESIONA_X && intEvento != PRESIONA_C){
411413
this->escenario->pushEvento(evento);
412414
} else {
415+
this->escenario->pushEvento(evento);
413416
this->cerrar();
414417
}
415418
}

0 commit comments

Comments
 (0)