diff --git a/EnemigoAzul.cpp b/EnemigoAzul.cpp index 738de9e..507e310 100644 --- a/EnemigoAzul.cpp +++ b/EnemigoAzul.cpp @@ -25,6 +25,8 @@ void EnemigoAzul::act() atacando = true; else atacando = false; + + attackCheck(); } diff --git a/Personaje.cpp b/Personaje.cpp index ec4520f..f229ff4 100644 --- a/Personaje.cpp +++ b/Personaje.cpp @@ -42,18 +42,40 @@ void Personaje::init(SDL_Renderer* renderer, list *personajes) hitbox_roja = IMG_LoadTexture(renderer,"hitbox/roja.png"); this->personajes = personajes; + + muerto = false; } bool Personaje::colision(SDL_Rect param) { - if(param.x + param.w < rect.x - || param.x > rect.x + rect.w - || param.y + param.h < rect.y - || param.y > rect.y + rect.h) + if(param.x + param.w < hitbox.x + || param.x > hitbox.x + hitbox.w + || param.y + param.h < hitbox.y + || param.y > hitbox.y + hitbox.h) return false; else return true; } - - +void Personaje::attackCheck() +{ + if(atacando) + { + //detecto colision con los demas personajes + list::iterator i; + for(i= personajes->begin(); + i!=personajes->end(); + i++) + { + if((*i)!=this) + { + if(colision((*i)->hitbox)) + { + cout<<"Colision! "<< frame <erase(i); + (*i)->muerto = true; + } + } + } + } +} diff --git a/Personaje.h b/Personaje.h index 78b3035..1bf8bd2 100644 --- a/Personaje.h +++ b/Personaje.h @@ -19,11 +19,13 @@ class Personaje int frame; int animacion; bool atacando; + bool muerto; virtual void draw(SDL_Renderer* renderer); virtual void act()=0; void init(SDL_Renderer* renderer, list *personajes); bool colision(SDL_Rect param); + void attackCheck(); Personaje(); virtual ~Personaje(); diff --git a/SDL2Testground.depend b/SDL2Testground.depend index dfb14aa..2ec4023 100644 --- a/SDL2Testground.depend +++ b/SDL2Testground.depend @@ -557,7 +557,7 @@ -1423853846 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/main.cpp +1423855866 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/main.cpp @@ -571,7 +571,7 @@ 1423853838 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Sho.h "Personaje.h" -1423855167 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Sho.cpp +1423856102 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Sho.cpp "Sho.h" 1423852506 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Enemigo.cpp @@ -583,7 +583,7 @@ 1423853744 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoAzul.h "Enemigo.h" -1423853722 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoAzul.cpp +1423856144 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoAzul.cpp "EnemigoAzul.h" 1423853753 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoRojo.cpp @@ -598,13 +598,13 @@ 1423853736 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/EnemigoVerde.h "Enemigo.h" -1423855091 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Personaje.h +1423856110 /home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Personaje.h -1423854955 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Personaje.cpp +1423856120 source:/home/turupawn/Projects/Clases/Progra3/SDL2TestSimple-master/Personaje.cpp "Personaje.h" diff --git a/SDL2Testground.layout b/SDL2Testground.layout index 4b22732..f323236 100644 --- a/SDL2Testground.layout +++ b/SDL2Testground.layout @@ -1,49 +1,69 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + - + - + - + diff --git a/Sho.cpp b/Sho.cpp index cbb7476..2c76b8e 100644 --- a/Sho.cpp +++ b/Sho.cpp @@ -39,23 +39,7 @@ void Sho::act() rect.x++; } - if(atacando) - { - //detecto colision con los demas personajes - list::iterator i; - for(i= personajes->begin(); - i!=personajes->end(); - i++) - { - if((*i)!=this) - { - if(colision((*i)->rect)) - { - cout<<"Colision! "<< frame <draw(renderer); + + for(list::iterator p=personajes.begin(); + p!=personajes.end(); + p++) + if((*p)->muerto) + { + personajes.erase(p); + p--; + } SDL_RenderPresent(renderer); diff --git a/obj/Debug/EnemigoAzul.o b/obj/Debug/EnemigoAzul.o index 1ce0c54..b89d7ca 100644 Binary files a/obj/Debug/EnemigoAzul.o and b/obj/Debug/EnemigoAzul.o differ diff --git a/obj/Debug/Personaje.o b/obj/Debug/Personaje.o index 6d21403..b52fa06 100644 Binary files a/obj/Debug/Personaje.o and b/obj/Debug/Personaje.o differ diff --git a/obj/Debug/Sho.o b/obj/Debug/Sho.o index 4abc0b8..d14cfd6 100644 Binary files a/obj/Debug/Sho.o and b/obj/Debug/Sho.o differ diff --git a/obj/Debug/main.o b/obj/Debug/main.o index d677417..6b9f78a 100644 Binary files a/obj/Debug/main.o and b/obj/Debug/main.o differ