Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cambio a entidad_t #28

Merged
merged 7 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ Tablero de Trello - [link](https://trello.com/b/sdukQHiL/tp-taller)
### Pre-requisitos
Listado de software/herramientas necesarias para el proyecto

* C++
* SDL2 / SDL2_image / SDL2_ttf / SDL2_mixer
* CMake
* Sistema operativo basado en Linux

## Ejecutando las pruebas
Para ejecutar las pruebas...
A lo largo del desarrollo del trabajo se han hecho algunas
pruebas para poder evaluar el correcto funcionamiento del modelo.
Estas se pueden ejecutar de las siguientes maneras.
```
./Mario -t
./Mario --test

* Siendo Mario el nombre del ejecutable que se tenga
```

## Ejecutando la aplicación
Para ejecutar la aplicación...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ void DibujadorPuntos::dibujarPuntosTotalesGameOver(JuegoCliente *juegoCliente) {
ancho_puntosJugador,
alto_puntosJugador};

renderizarTexto(cuadradoTituloPuntos, tituloPuntos.str().c_str(), colorDefault);
renderizarTexto(cuadradoTituloPuntos, tituloPuntos.str(), colorDefault);
int indiceJugador = 0;
for (auto const& parIdJugador : juegoCliente->obtenerJugadores()){

puntosJugador.str("");
//int id;
string nombreJugador = parIdJugador.second.nombreJugador;
puntosJugador << "Puntos de "<< nombreJugador <<": " << parIdJugador.second.puntos;
puntosJugador << "Puntos de "<< nombreJugador <<": " << parIdJugador.second.mario.puntos;

cuadradoPuntos = {ancho_pantalla/4 - ancho_puntosJugador/2,
alto_pantalla/2 - alto_puntosJugador/2 + desfase_puntosJugador - 100,
Expand All @@ -200,7 +200,7 @@ void DibujadorPuntos::dibujarPuntosTotalesGameOver(JuegoCliente *juegoCliente) {
idColor = MARIO_GRIS;
}

renderizarTexto(cuadradoPuntos, puntosJugador.str().c_str(), colores[idColor]);
renderizarTexto(cuadradoPuntos, puntosJugador.str(), colores[idColor]);

desfase_puntosJugador +=40;
indiceJugador++;
Expand Down
72 changes: 36 additions & 36 deletions src/Client/App/Dibujadores/DibujadoresJuego/DibujadorJuego.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,93 +55,93 @@ void DibujadorJuego::dibujar(){
}

void DibujadorJuego::dibujarEnemigos(){
list<enemigo_t> enemigos = juegoCliente->obtenerEnemigos();
list<entidad_t> enemigos = juegoCliente->obtenerEnemigos();
string tipo;
SDL_Texture* texturaEnemigo = nullptr;
for (auto const& enemigo : enemigos) {
SDL_Rect recorteTextura;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acá se pide a gritos el refactor de los dibujadores

Aquel que no realiza dicho if allá abajo.

Son cosas que vendrán pronto

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sip

if(enemigo.tipoEnemigo==GOOMBA){
recorteTextura = recorteSpriteGoomba->obtenerRecorte(enemigo.numeroRecorteX,enemigo.numeroRecorteY);
if(enemigo.tipo==GOOMBA){
recorteTextura = recorteSpriteGoomba->obtenerRecorte(enemigo.recorteX,enemigo.recorteY);
texturaEnemigo = cargadorTexturas->obtenerTextura(CLAVE_TEXTURA_GOOMBA);
}
else{
recorteTextura = recorteSpriteKoopa->obtenerRecorte(enemigo.numeroRecorteX,enemigo.numeroRecorteY);
recorteTextura = recorteSpriteKoopa->obtenerRecorte(enemigo.recorteX,enemigo.recorteY);
texturaEnemigo = cargadorTexturas->obtenerTextura(CLAVE_TEXTURA_KOOPAS);
}

SDL_Rect rectanguloEnemigo = {enemigo.posX-rectanguloCamara.x,
alto_pantalla - enemigo.posY - ALTO_ENEMIGOS,
SDL_Rect rectanguloEnemigo = {enemigo.x-rectanguloCamara.x,
alto_pantalla - enemigo.y - ALTO_ENEMIGOS,
ANCHO_ENEMIGOS, ALTO_ENEMIGOS};

//SDL_SetRenderDrawColor(renderizador, 0, 0, 0, 0x0F );
//SDL_RenderDrawRect(renderizador, &rectanguloEnemigo);

SDL_RenderCopyEx(renderizador,texturaEnemigo,&recorteTextura,&rectanguloEnemigo,0,
nullptr,enemigo.espejar?SDL_FLIP_HORIZONTAL:SDL_FLIP_NONE);
nullptr,enemigo.espejado?SDL_FLIP_HORIZONTAL:SDL_FLIP_NONE);
}
}

void DibujadorJuego::dibujarPlataformas(){
list<bloque_t> bloques = juegoCliente->obtenerBloques();
list<entidad_t> bloques = juegoCliente->obtenerBloques();
SDL_Texture* texturaBloques = cargadorTexturas->obtenerTextura(CLAVE_TEXTURA_BLOQUES);
for (auto const& bloque : bloques) {

SDL_Rect rectanguloBloque = {bloque.posX - rectanguloCamara.x,
alto_pantalla - bloque.posY - LARGO_BLOQUE,
SDL_Rect rectanguloBloque = {bloque.x - rectanguloCamara.x,
alto_pantalla - bloque.y - LARGO_BLOQUE,
LARGO_BLOQUE, LARGO_BLOQUE};
SDL_Rect recorteBloque = recorteSpriteBloque->obtenerRecorte(bloque.numeroRecorteX,bloque.numeroRecorteY);
SDL_Rect recorteBloque = recorteSpriteBloque->obtenerRecorte(bloque.recorteX,bloque.recorteY);
SDL_RenderCopy( renderizador, texturaBloques, &recorteBloque, &rectanguloBloque);
}

}

void DibujadorJuego::dibujarFondoPozos() {
list<pozo_t> pozos = juegoCliente->obtenerPozos();
list<entidad_t> pozos = juegoCliente->obtenerPozos();
SDL_Texture* texturaFondoPozos = cargadorTexturas->obtenerTextura(CLAVE_TEXTURA_FONDO_POZO);
for (auto const& pozo : pozos) {
SDL_Rect rectanguloPozo = {pozo.posX - rectanguloCamara.x,
SDL_Rect rectanguloPozo = {pozo.x - rectanguloCamara.x,
alto_pantalla - (int)(alto_pantalla*0.12),
ANCHO_POZO, (int)(alto_pantalla*0.12)};
SDL_Rect recortePozo = recortes[POZO_RECORTE]->obtenerRecorte(0,pozo.fondo);
SDL_Rect recortePozo = recortes[POZO_RECORTE]->obtenerRecorte(0,pozo.tipo);
recortePozo.y += 1; // TODO acomodar o crear un nuevo recorte, agarra una parte de la imagen de arriba
SDL_RenderCopy( renderizador, texturaFondoPozos, &recortePozo, &rectanguloPozo);
}
}


void DibujadorJuego::dibujarPozos(){
list<pozo_t> pozos = juegoCliente->obtenerPozos();
list<entidad_t> pozos = juegoCliente->obtenerPozos();
SDL_Texture* texturaPozos = cargadorTexturas->obtenerTextura(CLAVE_TEXTURA_POZO);
for (auto const& pozo : pozos) {
SDL_Rect rectanguloPozo = {pozo.posX - rectanguloCamara.x,
SDL_Rect rectanguloPozo = {pozo.x - rectanguloCamara.x,
alto_pantalla - ALTO_POZO,
ANCHO_POZO, ALTO_POZO};
SDL_Rect recortePozo = recortes[POZO_RECORTE]->obtenerRecorte(0,pozo.tipo);
SDL_Rect recortePozo = recortes[POZO_RECORTE]->obtenerRecorte(0,pozo.recorteY);
SDL_RenderCopy( renderizador, texturaPozos, &recortePozo, &rectanguloPozo);
}
}

void DibujadorJuego::dibujarMonedas(){
list<moneda_t> monedas = juegoCliente->obtenerMonedas();
list<entidad_t> monedas = juegoCliente->obtenerMonedas();
SDL_Texture* texturaMoneda = cargadorTexturas->obtenerTextura(CLAVE_TEXTURA_MONEDA);
for (auto const& moneda : monedas) {
SDL_Rect rectanguloMoneda = {moneda.posX - rectanguloCamara.x,
alto_pantalla - moneda.posY - LARGO_MONEDA,
SDL_Rect rectanguloMoneda = {moneda.x - rectanguloCamara.x,
alto_pantalla - moneda.y - LARGO_MONEDA,
LARGO_MONEDA, LARGO_MONEDA};
SDL_Rect recorteMoneda = recorteSpriteMoneda->obtenerRecorte(moneda.numeroRecorte);
SDL_Rect recorteMoneda = recorteSpriteMoneda->obtenerRecorte(moneda.recorteX);
SDL_RenderCopy( renderizador, texturaMoneda, &recorteMoneda, &rectanguloMoneda);
}
}

void DibujadorJuego::dibujarTuberias() {
list<tuberia_t> tuberias = juegoCliente->obtenerTuberias();
list<entidad_t> tuberias = juegoCliente->obtenerTuberias();
SDL_Texture* texturaTuberia = cargadorTexturas->obtenerTextura(CLAVE_TEXTURA_TUBERIAS);
for (auto const& tuberia : tuberias) {
SDL_Rect recorteTuberia = recorteSpriteTuberia->obtenerRecorte(tuberia.tipo,tuberia.color);
SDL_Rect rectanguloTuberia = {tuberia.posX - rectanguloCamara.x,
alto_pantalla - recorteSpriteTuberia->obtenerAlturaParaDibujarImagen(tuberia.tipo) - tuberia.posY,
recorteSpriteTuberia->obtenerAnchuraParaDibujarImagen(tuberia.tipo),
recorteSpriteTuberia->obtenerAlturaParaDibujarImagen(tuberia.tipo)};
SDL_Rect recorteTuberia = recorteSpriteTuberia->obtenerRecorte(tuberia.recorteX,tuberia.recorteY);
SDL_Rect rectanguloTuberia = {tuberia.x - rectanguloCamara.x,
alto_pantalla - recorteSpriteTuberia->obtenerAlturaParaDibujarImagen(tuberia.recorteX) - tuberia.y,
recorteSpriteTuberia->obtenerAnchuraParaDibujarImagen(tuberia.recorteX),
recorteSpriteTuberia->obtenerAlturaParaDibujarImagen(tuberia.recorteX)};
SDL_RenderCopy( renderizador, texturaTuberia, &recorteTuberia, &rectanguloTuberia);
}
}
Expand Down Expand Up @@ -186,18 +186,18 @@ void DibujadorJuego::dibujarMarios(){
}

void DibujadorJuego::dibujarEfectos() {
list<efecto_t> efectos = juegoCliente->obtenerEfectos();
list<entidad_t> efectos = juegoCliente->obtenerEfectos();
for (auto const& efecto : efectos) {
if(efecto.tipoDeEfecto == BOLA_DE_FUEGO || efecto.tipoDeEfecto == CHISPA || efecto.tipoDeEfecto == FLOR || efecto.tipoDeEfecto == MONEDA_FLOTANTE) {
SDL_Texture* textura = cargadorTexturas->obtenerTextura(clavesEfectos[efecto.tipoDeEfecto]);
Recorte* recorteEfecto = recortes[efecto.tipoDeEfecto];
SDL_Rect rectanguloRecorte = recorteEfecto->obtenerRecorte(efecto.numeroRecorte);
SDL_Rect rectanguloEfecto = {efecto.posX - rectanguloCamara.x,
alto_pantalla - efecto.posY -
if(efecto.tipo == BOLA_DE_FUEGO || efecto.tipo == CHISPA || efecto.tipo == FLOR || efecto.tipo == MONEDA_FLOTANTE) {
SDL_Texture* textura = cargadorTexturas->obtenerTextura(clavesEfectos[efecto.tipo]);
Recorte* recorteEfecto = recortes[efecto.tipo];
SDL_Rect rectanguloRecorte = recorteEfecto->obtenerRecorte(efecto.recorteX);
SDL_Rect rectanguloEfecto = {efecto.x - rectanguloCamara.x,
alto_pantalla - efecto.y -
recorteEfecto->obtenerAlturaParaDibujarImagen(0),
recorteEfecto->obtenerAnchuraParaDibujarImagen(0),
recorteEfecto->obtenerAlturaParaDibujarImagen(0)};
SDL_RendererFlip flip = recorteEfecto->direccion(efecto.numeroRecorte) == DERECHA?SDL_FLIP_NONE:SDL_FLIP_HORIZONTAL;
SDL_RendererFlip flip = recorteEfecto->direccion(efecto.recorteX) == DERECHA?SDL_FLIP_NONE:SDL_FLIP_HORIZONTAL; // todo usar el espejado
SDL_RenderCopyEx(renderizador, textura, &rectanguloRecorte, &rectanguloEfecto, 0, nullptr, flip);
}
}
Expand All @@ -219,7 +219,7 @@ void DibujadorJuego::dibujarTexto(){
SDL_Texture* texturaCorazon = cargadorTexturas->obtenerTextura(CLAVE_TEXTURA_CORAZON);
for(auto const& parClaveJugador:jugadores){
textoDePuntos.str("");
textoDePuntos << parClaveJugador.second.nombreJugador << ": "<<parClaveJugador.second.puntos;
textoDePuntos << parClaveJugador.second.nombreJugador << ": "<<parClaveJugador.second.mario.puntos;
SDL_Rect cuadradoPuntos = { 10 + espacioX, 10, 140, 30 };
SDL_Rect cuadradoCorazon = { 20 + espacioX, 50, 20, 20 };
int id = parClaveJugador.first;
Expand Down
76 changes: 31 additions & 45 deletions src/Client/App/JuegoCliente/JuegoCliente.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

pthread_mutex_t mutexJuegoCliente = PTHREAD_MUTEX_INITIALIZER;

bool operator == (const bloque_t &bloque1, const bloque_t &bloque2){
return bloque1.posX == bloque2.posX && bloque1.posY == bloque2.posY && bloque1.numeroRecorteY == bloque2.numeroRecorteY;
bool operator == (const entidad_t &bloque1, const entidad_t &bloque2){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nunca había visto esto... Habría que extenderlo a entidad_t y no quedarse sólo con ladrillo, no?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se puede hacer tambien

return bloque1.x == bloque2.x && bloque1.y == bloque2.y && bloque1.recorteY == bloque2.recorteY;
}


Expand Down Expand Up @@ -59,6 +59,13 @@ SDL_Rect JuegoCliente::obtenerCamara()const{
return rectanguloCamara;
}

void JuegoCliente::cargarLista(list<entidad_t>* listaACargar, entidad_t *vector, unsigned short tope) {
listaACargar->clear();
for(int i=0;i<tope;i++){
listaACargar->push_front(vector[i]);
}
}

void JuegoCliente::actualizar(){
if(rondas.empty()){
return;
Expand All @@ -81,33 +88,20 @@ void JuegoCliente::actualizar(){
ganaron = ronda.ganaron;
perdieron = ronda.perdieron;

bloques.clear();
enemigos.clear();
jugadores.clear();
monedas.clear();
efectos.clear();
cargarLista(&bloques,ronda.bloques,ronda.topeBloques);
cargarLista(&enemigos,ronda.enemigos,ronda.topeEnemigos);
cargarLista(&monedas,ronda.monedas,ronda.topeMonedas);
cargarLista(&efectos,ronda.efectos,ronda.topeEfectos);

for(int i=0;i<ronda.topeBloques;i++){
bloques.push_front(ronda.bloques[i]);
}
for(int i=0;i<ronda.topeEnemigos;i++){
enemigos.push_front(ronda.enemigos[i]);
}
for(int i=0;i<ronda.topeMonedas;i++){
monedas.push_front(ronda.monedas[i]);
}
for(int i=0;i<cantidadJugadores;i++){
jugadores[i]=ronda.jugadores[i];
jugadores[i].mario=ronda.jugadores[i];
}
for(int i=0;i<ronda.topeEfectos;i++){
efectos.push_front(ronda.efectos[i]);
}

list<bloque_t> ladrillosASacar;
list<bloque_t> ladrillosNuevos;
list<entidad_t> ladrillosASacar;
list<entidad_t> ladrillosNuevos;
bool agregado = false;
for(auto ladrillo: ladrillos){
if(enRango(ladrillo.posX, LARGO_BLOQUE)){
if(enRango(ladrillo.x, LARGO_BLOQUE)){
for(auto bloque : bloques) {
if(ladrillo == bloque){
ladrillosASacar.push_front(ladrillo);
Expand Down Expand Up @@ -138,19 +132,19 @@ map<int,jugador_t> JuegoCliente::obtenerJugadores(){
return jugadores;
}

list<enemigo_t> JuegoCliente::obtenerEnemigos(){
list<entidad_t> JuegoCliente::obtenerEnemigos(){
return enemigos;
}

list<bloque_t> JuegoCliente::obtenerBloques(){
list<entidad_t> JuegoCliente::obtenerBloques(){
return bloques;
}

bool JuegoCliente::enRango(int posX, int w) const {
return (rectanguloCamara.x - RANGO_VISTA) <= posX + w && posX <= (rectanguloCamara.x + anchoVista + RANGO_VISTA);
}

list<moneda_t> JuegoCliente::obtenerMonedas(){
list<entidad_t> JuegoCliente::obtenerMonedas(){
return monedas;
}

Expand All @@ -166,29 +160,29 @@ int JuegoCliente::obtenerMundoActual() const{
return numeroMundo;
}

list<pozo_t> JuegoCliente::obtenerPozos() {
list<pozo_t> pozosAMostrar;
list<entidad_t> JuegoCliente::obtenerPozos() {
list<entidad_t> pozosAMostrar;
for(auto pozo:pozos){
if(enRango(pozo.posX, ANCHO_POZO)){
if(enRango(pozo.x, ANCHO_POZO)){
pozosAMostrar.push_front(pozo);
}
}
return pozosAMostrar;
}


list<tuberia_t> JuegoCliente::obtenerTuberias() {
list<tuberia_t> tuberiasAMostrar;
list<entidad_t> JuegoCliente::obtenerTuberias() {
list<entidad_t> tuberiasAMostrar;
for(auto tuberia:tuberias){
int ancho = tuberia.tipo==TUBERIA_CHICA?ANCHO_TUBERIA_CHICA:ANCHO_TUBERIA_GRANDE;
if(enRango(tuberia.posX, ancho)){
if(enRango(tuberia.x, ancho)){
tuberiasAMostrar.push_front(tuberia);
}
}
return tuberiasAMostrar;
}

list<efecto_t> JuegoCliente::obtenerEfectos() {
list<entidad_t> JuegoCliente::obtenerEfectos() {
return efectos;
}

Expand All @@ -198,18 +192,10 @@ void JuegoCliente::agregarNivel(nivel_t nivel) {
this->hayQueMostrarPuntosDeNivel = true;
}
numeroMundo = nivel.mundo;
ladrillos.clear();
tuberias.clear();
pozos.clear();
for(int i=0;i<nivel.topeBloques;i++){
ladrillos.push_front(nivel.bloques[i]);
}
for(int i=0;i<nivel.topeTuberias;i++){
tuberias.push_front(nivel.tuberias[i]);
}
for(int i=0;i<nivel.topePozos;i++){
pozos.push_front(nivel.pozos[i]);
}

cargarLista(&ladrillos,nivel.bloques,nivel.topeBloques);
cargarLista(&tuberias,nivel.tuberias,nivel.topeTuberias);
cargarLista(&pozos,nivel.pozos,nivel.topePozos);

if(!hayQueCargarPodioNivel){
hayQueCargarPodioNivel = true;
Expand Down
Loading