Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
49 KB
Referenced Files
None
Subscribers
None
diff --git a/Diagrama.png b/Diagrama.png
new file mode 100644
index 0000000..b8676fc
Binary files /dev/null and b/Diagrama.png differ
diff --git a/Fonts/arial.ttf b/Fonts/arial.ttf
new file mode 100644
index 0000000..cc9a05d
Binary files /dev/null and b/Fonts/arial.ttf differ
diff --git a/Image/Nivel.png b/Image/Nivel.png
new file mode 100644
index 0000000..1734522
Binary files /dev/null and b/Image/Nivel.png differ
diff --git a/Image/Puntuacion.png b/Image/Puntuacion.png
new file mode 100644
index 0000000..e725cd3
Binary files /dev/null and b/Image/Puntuacion.png differ
diff --git a/SRC/AlmacenDeFuentes.cpp b/SRC/AlmacenDeFuentes.cpp
new file mode 100644
index 0000000..c8c0531
--- /dev/null
+++ b/SRC/AlmacenDeFuentes.cpp
@@ -0,0 +1,8 @@
+#include "AlmacenDeFuentes.hpp"
+#include <iostream>
+
+AlmacenDeFuentes::AlmacenDeFuentes()
+{
+ if (!arial.loadFromFile("./Fonts/arial.ttf"))
+ std::cout<<"fallo al leer la fuente "<<std::endl;
+}
diff --git a/SRC/AlmacenDeFuentes.hpp b/SRC/AlmacenDeFuentes.hpp
new file mode 100644
index 0000000..2a6e0ae
--- /dev/null
+++ b/SRC/AlmacenDeFuentes.hpp
@@ -0,0 +1,22 @@
+#ifndef ALMACENDEFUENTES_H
+#define ALMACENDEFUENTES_H
+#include <SFML/Graphics.hpp>
+
+class AlmacenDeFuentes
+{
+ private:
+ AlmacenDeFuentes();
+
+ sf::Font arial;
+public:
+
+ static const AlmacenDeFuentes& getInstancia()
+ {
+ static AlmacenDeFuentes instancia;
+ return instancia;
+ }
+
+ const sf::Font& getArial() const {return arial;}
+};
+
+#endif // ALMACENDEFUENTES_H
diff --git a/SRC/AlmacenDeGraficos.cpp b/SRC/AlmacenDeGraficos.cpp
new file mode 100644
index 0000000..08feafe
--- /dev/null
+++ b/SRC/AlmacenDeGraficos.cpp
@@ -0,0 +1,64 @@
+#include "AlmacenDeGraficos.hpp"
+#include "Tablero.hpp"
+
+AlmacenDeGraficos::AlmacenDeGraficos()
+{
+ cargarSpritesPacman();
+ cargarSpritesFantasma();
+ cargarPuntos();
+}
+
+void AlmacenDeGraficos::cargarSpritesPacman()
+{
+ sf::Image imagen;
+ imagen.loadFromFile("./Sprites/pacman.png");
+
+ for (int i = 0; i < 4; i++)
+ {
+ for (int j = 0; j < 2; j++) // dos animaciones por fotograma
+ {
+ jugador[i][j].loadFromImage(imagen,sf::IntRect(j*Tablero::ESCALA+i*Tablero::ESCALA*2,0,Tablero::ESCALA,Tablero::ESCALA));
+ // Personaje::textura[i][j] = &textura[i][j];
+ }
+ }
+
+ for (int i = 0;i<11;i++)
+ {
+ muerto_jugador[i].loadFromImage(imagen,sf::IntRect(i*Tablero::ESCALA,Tablero::ESCALA,Tablero::ESCALA,Tablero::ESCALA));
+ }
+}
+
+void AlmacenDeGraficos::cargarSpritesFantasma()
+{
+ sf::Image imagen;
+
+ imagen.loadFromFile("./Sprites/Fantasma.png");
+
+ for (int i = 0; i < 4; i++) // 4 fantasmas
+ {
+ for (int j = 0; j < 4; j++) // 4 dirreciones
+ {
+ for (int k = 0; k < 2; k++) // 2 fotogramas
+ {
+ fantasma[i][j][k].loadFromImage(imagen,sf::IntRect(j*40+k*Tablero::ESCALA,i*Tablero::ESCALA,Tablero::ESCALA,Tablero::ESCALA));
+ }
+ }
+
+ muerto_fantasma[i].loadFromImage(imagen,sf::IntRect(80+Tablero::ESCALA*i,80,Tablero::ESCALA,Tablero::ESCALA));
+ //Muerto[i].setTexture(Muerto_Texture[i]);
+
+ panico_fantasma[i].loadFromImage(imagen,sf::IntRect(i*Tablero::ESCALA,80,Tablero::ESCALA,Tablero::ESCALA));
+ //Panico_Final[i].setTexture(Panico_Texture[i]);
+ }
+}
+
+void AlmacenDeGraficos::cargarPuntos()
+{
+ sf::Image imagen;
+ imagen.loadFromFile("./Image/Puntuacion.png");
+
+ for (int i = 0;i<4;i++)
+ {
+ puntos[i].loadFromImage(imagen,sf::IntRect(i*20,0,20,20));
+ }
+}
diff --git a/SRC/AlmacenDeGraficos.hpp b/SRC/AlmacenDeGraficos.hpp
new file mode 100644
index 0000000..ea4081f
--- /dev/null
+++ b/SRC/AlmacenDeGraficos.hpp
@@ -0,0 +1,39 @@
+#ifndef ALMACENDEGRAFICOS_H
+#define ALMACENDEGRAFICOS_H
+#include <SFML/Graphics.hpp>
+//sa
+class AlmacenDeGraficos
+{
+ public:
+
+ static const AlmacenDeGraficos& getInstancia()
+ {
+ static AlmacenDeGraficos instancia;
+ return instancia;
+ }
+
+ const sf::Texture& getJugador(int i,int j) const {return jugador[i][j];}
+ const sf::Texture& getMuertoJugador(int i) const {return muerto_jugador[i];}
+ const sf::Texture& getFantasma(int i,int j,int k) const {return fantasma[i][j][k];}
+ const sf::Texture& getPanicoFantasma(int i) const {return panico_fantasma[i];}
+ const sf::Texture& getMuertoFantasma(int i) const {return muerto_fantasma[i];}
+ const sf::Texture& getPuntos(int i) const {return puntos[i];}
+ protected:
+ private:
+
+ sf::Texture jugador[4][2];
+ sf::Texture muerto_jugador[11];
+ sf::Texture fantasma[4][4][2];
+ sf::Texture panico_fantasma[4];
+ sf::Texture muerto_fantasma[4];
+
+ sf::Texture puntos[4];
+
+ AlmacenDeGraficos();
+
+ void cargarSpritesPacman();
+ void cargarSpritesFantasma();
+ void cargarPuntos();
+};
+
+#endif // ALMACENDEGRAFICOS_H
diff --git a/SRC/AlmacenDeSonido.cpp b/SRC/AlmacenDeSonido.cpp
new file mode 100644
index 0000000..6b43b74
--- /dev/null
+++ b/SRC/AlmacenDeSonido.cpp
@@ -0,0 +1,11 @@
+#include "AlmacenDeSonido.hpp"
+
+AlmacenDeSonido::AlmacenDeSonido()
+{
+ //ctor
+
+ pacman_beginning.loadFromFile("./Sound/pacman_beginning.wav");
+ pacman_death.loadFromFile("./Sound/pacman_death.wav");
+ pacman_eatfruit.loadFromFile("./Sound/pacman_eatfruit.wav");
+ pacman_rampage.loadFromFile("./Sound/pacman_rampage.wav");
+}
diff --git a/SRC/AlmacenDeSonido.hpp b/SRC/AlmacenDeSonido.hpp
new file mode 100644
index 0000000..88dc936
--- /dev/null
+++ b/SRC/AlmacenDeSonido.hpp
@@ -0,0 +1,29 @@
+#ifndef ALMACENDESONIDO_H
+#define ALMACENDESONIDO_H
+#include <SFML/Audio.hpp>
+
+class AlmacenDeSonido
+{
+ public:
+ static const AlmacenDeSonido& getInstancia()
+ {
+ static AlmacenDeSonido instancia;
+ return instancia;
+ }
+
+ const sf::SoundBuffer& getPacman_beginning() const {return pacman_beginning;}
+ const sf::SoundBuffer& getPacman_death() const {return pacman_death;}
+ const sf::SoundBuffer& getPacman_eatfruit() const {return pacman_eatfruit;}
+ const sf::SoundBuffer& getPacman_rampage() const {return pacman_rampage;}
+ protected:
+ private:
+
+ AlmacenDeSonido();
+
+ sf::SoundBuffer pacman_beginning;
+ sf::SoundBuffer pacman_death;
+ sf::SoundBuffer pacman_eatfruit;
+ sf::SoundBuffer pacman_rampage;
+};
+
+#endif // ALMACENDESONIDO_H
diff --git a/SRC/Callback_rampage.hpp b/SRC/Callback_rampage.hpp
new file mode 100644
index 0000000..2be8c92
--- /dev/null
+++ b/SRC/Callback_rampage.hpp
@@ -0,0 +1,13 @@
+#ifndef CALLBACK_RAMPAGE_H
+#define CALLBACK_RAMPAGE_H
+//
+class callback_rampage
+{
+public:
+ virtual void setRampage() = 0;
+ virtual void warningRampage() = 0;
+ virtual void disableRampage() = 0;
+};
+
+
+#endif
diff --git a/SRC/Estado.cpp b/SRC/Estado.cpp
new file mode 100644
index 0000000..8709194
--- /dev/null
+++ b/SRC/Estado.cpp
@@ -0,0 +1,67 @@
+#include "Estado.hpp"
+#include "AlmacenDeSonido.hpp"
+#include "Callback_rampage.hpp"
+
+Estado::Estado()
+{
+ pacman_rampage.setBuffer(AlmacenDeSonido::getInstancia().getPacman_rampage());
+ pacman_rampage.setLoop(true);
+}
+
+void Estado::refresh()
+{
+ if (rampage)
+ {
+ if (warning && reloj_rampage.getElapsedTime() >= sf::seconds(warning_rampage))
+ {
+ warning = false;
+ for (unsigned int i = 0;i<callbacks.size();i++)
+ {
+ callbacks[i]->warningRampage();
+ }
+ }
+ else if (reloj_rampage.getElapsedTime() >= sf::seconds(duracion_rampage))
+ {
+ desactivarRampage();
+ }
+ }
+}
+
+void Estado::activarRampage()
+{
+ rampage = true;
+ warning = true;
+
+ for (unsigned int i = 0;i<callbacks.size();i++)
+ {
+ callbacks[i]->setRampage();
+ }
+ pacman_rampage.play();
+ reloj_rampage.restart();
+}
+
+void Estado::desactivarRampage()
+{
+ rampage = false;
+
+ for (unsigned int i = 0;i<callbacks.size();i++)
+ {
+ callbacks[i]->disableRampage();
+ }
+
+
+ pacman_rampage.stop();
+}
+
+void Estado::anyadirCallback(callback_rampage* c)
+{
+ callbacks.push_back(c);
+}
+
+void Estado::eliminarCallback(callback_rampage* c)
+{
+ auto it = find(callbacks.begin(),callbacks.end(),c);
+
+ if (it != callbacks.end())
+ callbacks.erase(it);
+}
diff --git a/SRC/Estado.hpp b/SRC/Estado.hpp
new file mode 100644
index 0000000..f072b02
--- /dev/null
+++ b/SRC/Estado.hpp
@@ -0,0 +1,42 @@
+#ifndef ESTADO_H
+#define ESTADO_H
+#include <SFML/Audio.hpp>
+//sas
+
+class callback_rampage;
+
+class Estado
+{
+ public:
+ static const int duracion_rampage = 6;
+ static const int warning_rampage = 4;
+
+ static Estado& getInstancia()
+ {
+ static Estado estado;
+ return estado;
+ }
+
+ void refresh();
+ void activarRampage();
+ void desactivarRampage();
+
+ void anyadirCallback(callback_rampage* c);
+ void eliminarCallback(callback_rampage* c);
+
+ bool esRampage() const {return rampage;}
+ protected:
+ private:
+
+ Estado();
+
+ sf::Clock reloj_rampage;
+ bool rampage = false;
+ bool warning = false;
+
+ sf::Sound pacman_rampage;
+
+ std::vector<callback_rampage*> callbacks;
+};
+
+#endif // ESTADO_H
diff --git a/SRC/Fantasma.cpp b/SRC/Fantasma.cpp
new file mode 100644
index 0000000..bbaef03
--- /dev/null
+++ b/SRC/Fantasma.cpp
@@ -0,0 +1,302 @@
+#include "Fantasma.hpp"
+#include "Pacman.hpp"
+#include "Puntuacion.hpp"
+#include <queue>
+#include <iostream>
+#include <climits>
+#include "AlmacenDeGraficos.hpp"
+#include <algorithm>
+#include "Estado.hpp"
+/*
+
+ Fantasma[0].Position = sf::Vector2f(13*ESCALA,13*ESCALA);
+ Fantasma[1].Position = sf::Vector2f(14*ESCALA,13*ESCALA);
+ Fantasma[2].Position = sf::Vector2f(13*ESCALA,14*ESCALA);
+ Fantasma[3].Position = sf::Vector2f(14*ESCALA,14*ESCALA);
+*/
+
+Fantasma::Fantasma(Tablero &mitablero,Pacman& j,Puntuacion& p,int x,int y,int id) :
+
+ Personaje(mitablero,x,y),
+ tablero(mitablero),
+ jugador(j),
+ puntuacion(p),
+ id_fantasma(id),
+ inicial(x,y)
+{
+ for (int j = 0; j < 4; j++) // 4 dirreciones
+ {
+ for (int k = 0; k < 2; k++) // 2 fotogramas
+ {
+ textura[(j+2)%4][k] = &(AlmacenDeGraficos::getInstancia().getFantasma(id_fantasma,j,k));
+ }
+ }
+
+
+ setArribaDireccion();
+ setVelocidad(180);
+
+ direcciones[DERECHA].x = 1;
+ direcciones[DERECHA].y = 0;
+
+ direcciones[IZQUIERDA].x = -1;
+ direcciones[IZQUIERDA].y = 0;
+
+ direcciones[ABAJO].x = 0;
+ direcciones[ABAJO].y = 1;
+
+ direcciones[ARRIBA].x = 0;
+ direcciones[ARRIBA].y = -1;
+
+ Estado::getInstancia().anyadirCallback(this);
+}
+
+void Fantasma::mover()
+{
+ if (!jugador.estaVivo()) return;
+
+ if (listoParaNuevoMovimiento()) // SI no estamos en transicion a nuevo movimiento...
+ {
+ if (!muerto)
+ {
+ if (!Estado::getInstancia().esRampage())
+ {
+ moverNormal();
+ }
+ else moverAsustado();
+ }
+ else moverMuerto();
+ }
+
+ if (!muerto && getPosition() == jugador.getPosition())
+ {
+ if (!Estado::getInstancia().esRampage())
+ jugador.matar();
+ else
+ this->matar();
+ }
+
+ Personaje::mover();
+}
+
+
+void Fantasma::moverAsustado()
+{
+ sf::Vector2i pos = getPosition();
+ sf::Vector2i dest = jugador.getPosition();
+
+ auto posibilidades = contarDireccionesLibres();
+
+ if (posibilidades.size() > 1 || tablero.getColision(pos+getOrientacion()))
+ {
+ int max = getRutaMasCorta(dest,pos+direcciones[0]).size();
+ int index = 0;
+ int cnt;
+
+ for (int i = 1; i<4; i++)
+ {
+ cnt = getRutaMasCorta(dest,pos+direcciones[i]).size();
+ if (cnt > max)
+ {
+ index = i;
+ max = cnt;
+ }
+ }
+
+ setDireccion(index);
+ }
+ else setDireccion(posibilidades[0]);
+}
+
+std::vector<int> Fantasma::contarDireccionesLibres()
+{
+ sf::Vector2i pos = getPosition();
+
+ std::vector<int> devolver;
+
+ for (int i = 0; i<4; i++)
+ {
+ if (direcciones[i] == -getOrientacion()) continue;
+ if (!tablero.getColision(pos+direcciones[i]))
+ {
+ devolver.push_back(i);
+ }
+ }
+
+ return devolver;
+}
+
+
+std::vector<sf::Vector2i> Fantasma::getRutaMasCorta(sf::Vector2i pos,sf::Vector2i dest)
+{
+ struct Nodo
+ {
+ Nodo* padre;
+
+ sf::Vector2i pos;
+
+ Nodo(Nodo* p = nullptr) : padre(p),pos(0,0) {}
+ };
+
+ if (pos.x < 0 || pos.x > 27 || dest.x < 0 || dest.x > 27 ||
+ tablero.getColision(pos) || tablero.getColision(dest) || pos == dest)
+ {
+ return std::vector<sf::Vector2i>();
+
+ }
+
+ std::swap(pos,dest);
+
+ Nodo mapa[Tablero::Tamanyo_Mapa_Y][Tablero::Tamanyo_Mapa_X];
+
+ std::queue<Nodo*> cola;
+ std::vector<sf::Vector2i> devolver;
+ Nodo* actual = &mapa[pos.x][pos.y];
+ actual->padre = actual;
+ actual->pos = pos;
+ cola.push(actual);
+
+ while (!cola.empty())
+ {
+ actual = cola.front();
+ // std::cout<<actual->pos.x<<' '<<actual->pos.y<<std::endl;
+ if (actual->pos == dest) break;
+
+ cola.pop();
+
+ for (int i = 0; i<4; i++)
+ {
+ sf::Vector2i aux = actual->pos+direcciones[i];
+
+ if (aux.x < 0)
+ {
+ aux.x = 0;
+ }
+ else if (aux.x>27)
+ aux.x = 27;
+
+ Nodo* n = &mapa[aux.x][aux.y];
+ if (n->padre == nullptr && !tablero.getColision(aux))
+ {
+ n->padre = actual;
+ n->pos = aux;
+ cola.push(n);
+ }
+ }
+ }
+ actual = &mapa[dest.x][dest.y];
+
+ while (actual != nullptr && actual->padre != actual)
+ {
+ devolver.push_back(actual->pos);
+ actual = actual->padre;
+ };
+
+ return devolver;
+}
+
+
+void Fantasma::moverMuerto()
+{
+ if (!escogerRutaMasCorta(getPosition(),inicial) && !Estado::getInstancia().esRampage())
+ {
+ muerto = false;
+ disableRampage();
+ }
+}
+
+void Fantasma::elegirDireccion(sf::Vector2i pos,sf::Vector2i dest)
+{
+ if (dest.x-pos.x > 0)
+ {
+ setDerechaDireccion();
+ }
+ else if (dest.x-pos.x < 0)
+ {
+ setIzquierdaDireccion();
+ }
+ else if (dest.y-pos.y > 0)
+ {
+ setAbajoDireccion();
+ }
+ else
+ {
+ setArribaDireccion();
+ }
+}
+
+void Fantasma::matar()
+{
+ muerto = true;
+ for (int j = 0; j<4; j++)
+ {
+ for (int k = 0; k<2; k++)
+ {
+ textura[(j+2)%4][k] = &(AlmacenDeGraficos::getInstancia().getMuertoFantasma(j));
+ }
+ }
+
+ puntuacion.comerFantasma(getSprite().getPosition());
+}
+
+void Fantasma::setRampage()
+{
+ if (muerto) return;
+ for (int j = 0; j<4; j++)
+ {
+ for (int k = 0; k<2; k++)
+ {
+ textura[j][k] = &(AlmacenDeGraficos::getInstancia().getPanicoFantasma(j%2));
+ }
+ }
+}
+
+void Fantasma::warningRampage()
+{
+ if (muerto) return;
+ for (int j = 0; j<4; j++)
+ {
+ for (int k = 0; k<2; k++)
+ {
+ textura[j][k] = &(AlmacenDeGraficos::getInstancia().getPanicoFantasma(j%2+k*2));
+ }
+ }
+}
+
+void Fantasma::disableRampage()
+{
+ if (muerto) return;
+ //std::cout<<"Rampage desactivado"<<std::endl;
+ for (int j = 0; j<4; j++)
+ {
+ for (int k = 0; k<2; k++)
+ {
+ textura[(j+2)%4][k] = &(AlmacenDeGraficos::getInstancia().getFantasma(id_fantasma,j,k));
+ }
+ }
+}
+
+bool Fantasma::escogerRutaMasCorta(sf::Vector2i pos,sf::Vector2i dest)
+{
+ //sf::Vector2i(jugador->getPosition().x/Tablero::ESCALA,jugador->getPosition().y/Tablero::ESCALA);
+
+ std::vector<sf::Vector2i> ruta = getRutaMasCorta(pos,dest);
+
+ return escogerRutaMasCorta(ruta,pos,dest);
+}
+
+bool Fantasma::escogerRutaMasCorta(std::vector<sf::Vector2i>& ruta,sf::Vector2i pos,sf::Vector2i dest)
+{
+ if (ruta.empty()) return false;
+
+ sf::Vector2i destino = ruta.size() > 1? ruta[1] : dest;
+
+ elegirDireccion(pos,destino);
+
+ return true;
+}
+
+Fantasma::~Fantasma()
+{
+ Estado::getInstancia().eliminarCallback(this);
+}
diff --git a/SRC/Fantasma.hpp b/SRC/Fantasma.hpp
new file mode 100644
index 0000000..d83bf8c
--- /dev/null
+++ b/SRC/Fantasma.hpp
@@ -0,0 +1,53 @@
+#ifndef FANTASMAS_H
+#define FANTASMAS_H
+#include <vector>
+#include "Callback_rampage.hpp"
+#include "Personaje.hpp"
+
+class Pacman;
+
+class Fantasma : public callback_rampage , protected Personaje
+{
+ public:
+ Fantasma(Tablero &mitablero,Pacman& j,Puntuacion& p,int x,int y,int id);
+
+ void mover();
+ const sf::Sprite& getSprite(){return Personaje::getSprite();}
+
+ void setRampage() override;
+ void warningRampage() override;
+ void disableRampage() override;
+
+ void disableMov(){Personaje::disableMov();}
+ void enableMov(){Personaje::enableMov();}
+
+ ~Fantasma();
+ protected:
+ Tablero &tablero;
+ Pacman& jugador;
+
+ void elegirDireccion(sf::Vector2i pos,sf::Vector2i dest);
+
+ virtual void moverNormal() = 0;
+
+ std::vector<sf::Vector2i> getRutaMasCorta(sf::Vector2i pos,sf::Vector2i dest); // Obtiene la ruta más corta de A hacia B.
+ bool escogerRutaMasCorta(sf::Vector2i pos,sf::Vector2i dest); // Selecciona ruta mas corta de A hacia B, False si no hay ruta (posiblemente porque pos == dest)
+ bool escogerRutaMasCorta(std::vector<sf::Vector2i>&,sf::Vector2i,sf::Vector2i);
+
+ std::vector<int> contarDireccionesLibres();
+ private:
+ Puntuacion& puntuacion;
+ int id_fantasma;
+
+
+ void moverAsustado();
+ void moverMuerto();
+ void matar();
+
+ bool muerto = false;
+
+ sf::Vector2i inicial;
+ sf::Vector2i direcciones[4];
+
+};
+#endif // FANTASMAS_H
diff --git a/SRC/FantasmaAmarillo.cpp b/SRC/FantasmaAmarillo.cpp
new file mode 100644
index 0000000..563ed99
--- /dev/null
+++ b/SRC/FantasmaAmarillo.cpp
@@ -0,0 +1,26 @@
+#include "FantasmaAmarillo.hpp"
+#include "Pacman.hpp"
+
+FantasmaAmarillo::FantasmaAmarillo(Tablero &mitablero,Pacman& j,Puntuacion& p,int x,int y) : Fantasma(mitablero,j,p,x,y,id_fantasma)
+{
+ //ctor
+}
+
+void FantasmaAmarillo::moverNormal()
+{
+ //
+
+ auto ruta = getRutaMasCorta(getPosition(),jugador.getPosition());
+
+ if (ruta.size() > 20)
+ {
+ escogerRutaMasCorta(ruta,getPosition(),jugador.getPosition());
+ }
+ else
+ {
+ auto posibilidades = contarDireccionesLibres();
+
+ setDireccion(posibilidades[rand()%posibilidades.size()]);
+ }
+
+}
diff --git a/SRC/FantasmaAmarillo.hpp b/SRC/FantasmaAmarillo.hpp
new file mode 100644
index 0000000..04ea3b0
--- /dev/null
+++ b/SRC/FantasmaAmarillo.hpp
@@ -0,0 +1,19 @@
+#ifndef FANTASMAAMARILLO_HPP
+#define FANTASMAAMARILLO_HPP
+
+#include "Fantasma.hpp"
+
+
+class FantasmaAmarillo : public Fantasma
+{
+ public:
+ static const int id_fantasma = 3;
+
+ FantasmaAmarillo(Tablero &mitablero,Pacman& j,Puntuacion& p,int x,int y);
+ protected:
+
+ void moverNormal() override;
+ private:
+};
+
+#endif // FANTASMAAMARILLO_HPP
diff --git a/SRC/FantasmaAzul.cpp b/SRC/FantasmaAzul.cpp
new file mode 100644
index 0000000..99da15a
--- /dev/null
+++ b/SRC/FantasmaAzul.cpp
@@ -0,0 +1,31 @@
+#include "FantasmaAzul.hpp"
+#include "Pacman.hpp"
+
+FantasmaAzul::FantasmaAzul(Tablero &mitablero,Pacman& j,Puntuacion& p,int x,int y) : Fantasma(mitablero,j,p,x,y,id_fantasma)
+{
+ //ctor
+
+ puntos_control[0] = sf::Vector2i(21,26);
+ puntos_control[1] = sf::Vector2i(21,4);
+ puntos_control[2] = sf::Vector2i(6,4);
+ puntos_control[3] = sf::Vector2i(6,26);
+
+}
+
+void FantasmaAzul::moverNormal()
+{
+ auto ruta = getRutaMasCorta(getPosition(),jugador.getPosition());
+
+ if (ruta.size() < 9)
+ {
+ escogerRutaMasCorta(ruta,getPosition(),jugador.getPosition());
+ }
+ else
+ {
+ if (getPosition() == puntos_control[punto_actual])
+ {
+ punto_actual = (punto_actual+1) % 4;
+ }
+ escogerRutaMasCorta(getPosition(),puntos_control[punto_actual]);
+ }
+}
diff --git a/SRC/FantasmaAzul.hpp b/SRC/FantasmaAzul.hpp
new file mode 100644
index 0000000..5b26524
--- /dev/null
+++ b/SRC/FantasmaAzul.hpp
@@ -0,0 +1,20 @@
+#ifndef FANTASMAAZUL_H
+#define FANTASMAAZUL_H
+
+#include "Fantasma.hpp"
+
+
+class FantasmaAzul : public Fantasma
+{
+ public:
+ static const int id_fantasma = 2;
+
+ FantasmaAzul(Tablero &mitablero,Pacman& j,Puntuacion& p,int x,int y);
+ protected:
+ void moverNormal() override;
+
+ sf::Vector2i puntos_control[4];
+ int punto_actual = 0;
+};
+
+#endif // FANTASMAAZUL_H
diff --git a/SRC/FantasmaRojo.cpp b/SRC/FantasmaRojo.cpp
new file mode 100644
index 0000000..056e127
--- /dev/null
+++ b/SRC/FantasmaRojo.cpp
@@ -0,0 +1,15 @@
+#include "FantasmaRojo.hpp"
+#include "Pacman.hpp"
+
+FantasmaRojo::FantasmaRojo(Tablero &mitablero,Pacman& j,Puntuacion& p,int x,int y) : Fantasma(mitablero,j,p,x,y,id_fantasma)
+{
+ //ctor
+}
+
+
+void FantasmaRojo::moverNormal()
+{
+ auto ruta = getRutaMasCorta(getPosition(),jugador.getPosition());
+ ultimaPosicion = ruta[ruta.size()-1];
+ escogerRutaMasCorta(ruta,getPosition(),jugador.getPosition());
+}
diff --git a/SRC/FantasmaRojo.hpp b/SRC/FantasmaRojo.hpp
new file mode 100644
index 0000000..c5ca6ec
--- /dev/null
+++ b/SRC/FantasmaRojo.hpp
@@ -0,0 +1,20 @@
+#ifndef FANTASMAROJO_H
+#define FANTASMAROJO_H
+#include "Fantasma.hpp"
+
+class FantasmaRojo : public Fantasma
+{
+ public:
+ static const int id_fantasma = 0;
+
+ FantasmaRojo(Tablero &mitablero,Pacman& j,Puntuacion& p,int x,int y);
+ protected:
+
+ void moverNormal() override;
+ private:
+ friend class FantasmaRosa;
+
+ sf::Vector2i ultimaPosicion;
+};
+
+#endif // FANTASMAROJO_H
diff --git a/SRC/FantasmaRosa.cpp b/SRC/FantasmaRosa.cpp
new file mode 100644
index 0000000..d216563
--- /dev/null
+++ b/SRC/FantasmaRosa.cpp
@@ -0,0 +1,34 @@
+#include "FantasmaRosa.hpp"
+#include "Pacman.hpp"
+#include <iostream>
+#include "FantasmaRojo.hpp"
+
+FantasmaRosa::FantasmaRosa(Tablero &mitablero,Pacman& j,Puntuacion& p,int x,int y,FantasmaRojo &compa) :
+Fantasma(mitablero,j,p,x,y,id_fantasma),companyero(compa)
+{
+ //ctor
+}
+
+void FantasmaRosa::moverNormal()
+{
+
+ //if (rand()%2 == 0)
+ tablero.setColision(companyero.ultimaPosicion);
+
+ auto ruta = getRutaMasCorta(getPosition(),jugador.getPosition());
+
+ if (ruta.empty())
+ {
+ tablero.deleteColision(companyero.ultimaPosicion);
+
+ escogerRutaMasCorta(getPosition(),jugador.getPosition());
+ }
+ else
+ {
+
+ escogerRutaMasCorta(ruta,getPosition(),jugador.getPosition());
+ tablero.deleteColision(companyero.ultimaPosicion);
+
+ }
+ // else setDireccion(rand()%4);
+}
diff --git a/SRC/FantasmaRosa.hpp b/SRC/FantasmaRosa.hpp
new file mode 100644
index 0000000..1eecb85
--- /dev/null
+++ b/SRC/FantasmaRosa.hpp
@@ -0,0 +1,23 @@
+#ifndef FANTASMAROSA_HPP
+#define FANTASMAROSA_HPP
+
+#include "Fantasma.hpp"
+
+class FantasmaRojo;
+
+class FantasmaRosa : public Fantasma
+{
+ public:
+ static const int id_fantasma = 1;
+
+ FantasmaRosa(Tablero &mitablero,Pacman& j,Puntuacion& p,int x,int y,FantasmaRojo &compa);
+ protected:
+
+
+ void moverNormal() override;
+ private:
+
+ FantasmaRojo& companyero;
+};
+
+#endif // FANTASMAROSA_HPP
diff --git a/SRC/Pacman.cpp b/SRC/Pacman.cpp
new file mode 100644
index 0000000..f994620
--- /dev/null
+++ b/SRC/Pacman.cpp
@@ -0,0 +1,69 @@
+#include "Pacman.hpp"
+#include <Estado.hpp>
+#include "AlmacenDeGraficos.hpp"
+#include "AlmacenDeSonido.hpp"
+
+Pacman::Pacman(Tablero &mitablero,const int x,const int y) : Personaje(mitablero,x,y)
+{
+
+ for (int i = 0; i < 4; i++)
+ {
+ for (int j = 0; j < 2; j++) // dos animaciones por fotograma
+ {
+ Personaje::textura[i][j] = & (AlmacenDeGraficos::getInstancia().getJugador(i,j));
+ }
+ }
+
+ setIzquierdaDireccion();//sprite.setTexture(textura[direccion::IZQUIERDA][0]);
+
+ pacman_eatfruit.setBuffer(AlmacenDeSonido::getInstancia().getPacman_eatfruit());
+ pacman_death.setBuffer(AlmacenDeSonido::getInstancia().getPacman_death());
+ Estado::getInstancia().anyadirCallback(this);
+}
+
+void Pacman::mover()
+{
+ if (!vivo)
+ {
+ if (reloj_animacion.getElapsedTime() >= sf::milliseconds(tiempo_de_animacion_muerte))
+ {
+ animarMuerte();
+ }
+ }
+ else
+ {
+ Personaje::mover();
+ }
+}
+
+
+void Pacman::animarMuerte()
+{
+ anim_muerte = (anim_muerte+1);
+ if (anim_muerte >= 11)
+ setTexture(&AlmacenDeGraficos::getInstancia().getMuertoJugador(10));
+ else
+ setTexture(&AlmacenDeGraficos::getInstancia().getMuertoJugador(anim_muerte));
+
+ reloj_animacion.restart();
+}
+
+void Pacman::comer(int x,int y)
+{
+ int comida = tablero.comer(x,y);
+
+ if (comida != 0)
+ {
+ if (pacman_eatfruit.getStatus() != sf::Sound::Playing && !Estado::getInstancia().esRampage())
+ pacman_eatfruit.play();
+ }
+ if (comida < 0)
+ {
+ Estado::getInstancia().activarRampage();
+ }
+}
+
+Pacman::~Pacman()
+{
+ Estado::getInstancia().eliminarCallback(this);
+}
diff --git a/SRC/Pacman.hpp b/SRC/Pacman.hpp
new file mode 100644
index 0000000..ebd89e2
--- /dev/null
+++ b/SRC/Pacman.hpp
@@ -0,0 +1,64 @@
+#ifndef PACMAN_HPP
+#define PACMAN_HPP
+
+#include "Personaje.hpp"
+#include "Callback_rampage.hpp"
+#include <SFML/Audio.hpp>
+
+class Pacman : public Personaje,callback_rampage
+{
+ public:
+ Pacman(Tablero &mitablero,const int x,const int y);
+
+ void mover();
+
+ void setRampage() override
+ {
+ setVelocidad(tiempo_rampage);
+ }
+
+ void disableRampage() override
+ {
+ setVelocidad(tiempo_defecto);
+ }
+
+ void warningRampage() override {}
+
+ bool terminado() const {return vivo == false && anim_muerte == 15;}
+
+ void matar()
+ {
+ vivo = false;
+ anim_muerte = 0;
+ disableMov();
+ tiempo_de_animacion = tiempo_de_animacion_muerte;
+ pacman_death.play();
+ }
+
+ bool estaVivo() const {return vivo;}
+
+ ~Pacman();
+ protected:
+
+ void comer(int x,int y) override;
+ private:
+
+ static const int tiempo_defecto = 160;
+ static const int tiempo_rampage = 80;
+
+ sf::Texture textura[4][2];
+ sf::Texture muerto[11];
+ bool vivo = true;
+
+ int anim_muerte;
+ int tiempo_de_animacion;
+ int tiempo_de_animacion_muerte = 100;
+
+ sf::Clock reloj_animacion;
+ sf::Sound pacman_eatfruit;
+ sf::Sound pacman_death;
+
+ void animarMuerte();
+};
+
+#endif // PACMAN_HPP
diff --git a/SRC/Personaje.cpp b/SRC/Personaje.cpp
new file mode 100644
index 0000000..45d970a
--- /dev/null
+++ b/SRC/Personaje.cpp
@@ -0,0 +1,167 @@
+#include "Personaje.hpp"
+#include "Tablero.hpp"
+#include <iostream>
+
+Personaje::Personaje(Tablero &mitablero,const int x,const int y) : tablero(mitablero),velocidad(-1,0),vPulsada(0,0),tPulsada(0),
+ orientacion(direccion::IZQUIERDA)
+{
+
+ sprite.setPosition(x*Tablero::ESCALA,y*Tablero::ESCALA);
+ tiempo_entre_pixeles = 160/Tablero::ESCALA;
+ en_movimiento = false;
+ anim = 0;
+ reloj.restart();
+}
+
+void Personaje::mover()
+{
+
+ if (reloj_animacion.getElapsedTime() >= sf::milliseconds(tiempo_de_animacion))
+ {
+ animar();
+ }
+
+ if(tPulsada>0)
+ {
+ auto aux = getPosition()+vPulsada;
+ sf::Vector2i pos(aux.x,aux.y);
+
+ if(!tablero.getColision(aux))
+ {
+ velocidad = sf::Vector2f(vPulsada.x, vPulsada.y);
+ tPulsada=0;
+ orientacion=oriPulsada;
+ sprite.setTexture(*textura[oriPulsada][anim]);
+ }
+ tPulsada--;
+ }
+
+ if (!en_movimiento)
+ {
+
+ if (mover_flag)
+ iniciarMovimiento();
+ }
+ else
+ {
+ transicion_movimiento();
+ }
+}
+
+void Personaje::animar()
+{
+
+ anim = (anim+1)%2;
+ sprite.setTexture(*textura[orientacion][anim]);
+
+ reloj_animacion.restart();
+}
+
+void Personaje::iniciarMovimiento()
+{
+ int x = sprite.getPosition().x/Tablero::ESCALA+velocidad.x;
+ int y = sprite.getPosition().y/Tablero::ESCALA+velocidad.y;
+
+ if (!tablero.getColision(x,y))//comer(x,y))
+ {
+ destino = sf::Vector2f(sprite.getPosition())+sf::Vector2f(velocidad.x*Tablero::ESCALA,velocidad.y*Tablero::ESCALA);
+ en_movimiento = true;
+ acum = Tablero::ESCALA;
+ velocidad_aux = velocidad;
+ }
+ reloj.restart();
+}
+
+void Personaje::transicion_movimiento()
+{
+ int incr = ((reloj.getElapsedTime().asMilliseconds())/tiempo_entre_pixeles);
+
+ if (incr >= acum)
+ {
+ incr = acum;
+ en_movimiento = false;
+
+ if (tratar_bordes()) return;
+ }
+
+ acum -= incr;
+ sprite.move(velocidad_aux.x*incr,velocidad_aux.y*incr);
+
+ if (acum <= Tablero::ESCALA/2)
+ {
+ comer(destino.x/Tablero::ESCALA,destino.y/Tablero::ESCALA);
+ }
+ reloj.restart();
+}
+
+bool Personaje::tratar_bordes()
+{
+ if (destino == sf::Vector2f(-Tablero::ESCALA,sprite.getPosition().y))
+ {
+ sprite.setPosition(28*Tablero::ESCALA,sprite.getPosition().y);
+ return true;
+ }
+ else if (destino == sf::Vector2f(28*Tablero::ESCALA,sprite.getPosition().y))
+ {
+ sprite.setPosition(-Tablero::ESCALA,sprite.getPosition().y);
+ return true;
+ }
+ return false;
+}
+
+void Personaje::setArribaDireccion()
+{
+ if (!mover_flag) return;
+
+ vPulsada.x = 0;
+ vPulsada.y = -1;
+ tPulsada=tEspPulsada;
+ oriPulsada = direccion::ARRIBA;
+}
+
+
+void Personaje::setAbajoDireccion()
+{
+ if (!mover_flag) return;
+ vPulsada.x = 0;
+ vPulsada.y = 1;
+ tPulsada=tEspPulsada;
+ oriPulsada = direccion::ABAJO;
+
+}
+
+void Personaje::setIzquierdaDireccion()
+{
+ if (!mover_flag) return;
+ vPulsada.x = -1;
+ vPulsada.y = 0;
+ tPulsada=tEspPulsada;
+ oriPulsada = direccion::IZQUIERDA;
+}
+
+void Personaje::setDerechaDireccion()
+{
+ if (!mover_flag) return;
+ vPulsada.x = 1;
+ vPulsada.y = 0;
+ tPulsada=tEspPulsada;
+ oriPulsada = direccion::DERECHA;
+}
+
+void Personaje::setDireccion(int index)
+{
+ switch (index)
+ {
+ case DERECHA:
+ setDerechaDireccion();
+ break;
+ case IZQUIERDA:
+ setIzquierdaDireccion();
+ break;
+ case ABAJO:
+ setAbajoDireccion();
+ break;
+ case ARRIBA:
+ setArribaDireccion();
+ }
+}
diff --git a/SRC/Personaje.hpp b/SRC/Personaje.hpp
new file mode 100644
index 0000000..8783d60
--- /dev/null
+++ b/SRC/Personaje.hpp
@@ -0,0 +1,99 @@
+#ifndef PERSONAJE_HPP
+#define PERSONAJE_HPP
+#include <SFML/Graphics.hpp>
+#include "Tablero.hpp"
+
+/** Idea para pacman:
+*
+* Crear una estructura personaje, que simbolize a alguien que se mueve. Pacman hereda de esa estructura y añade los métodos (enableRampage() y disableRampage()).
+*
+* Problemas:
+*
+* - La forma de cargar las texturas, en el caso de Pacman se podría sobreescribir el constructor. Si pacman
+*/
+
+class Personaje
+{
+ public:
+ enum direccion
+ {
+ IZQUIERDA,
+ DERECHA,
+ ARRIBA,
+ ABAJO
+ };
+
+ Personaje(Tablero &mitablero,const int x,const int y);
+
+ sf::Vector2i getPosition() const {return sf::Vector2i(sprite.getPosition().x/Tablero::ESCALA,sprite.getPosition().y/Tablero::ESCALA);}
+ void mover();
+ bool listoParaNuevoMovimiento() const {return !en_movimiento;}
+
+ void setArribaDireccion();
+ void setAbajoDireccion();
+ void setIzquierdaDireccion();
+ void setDerechaDireccion();
+
+ void disableMov(){mover_flag= false;}
+ void enableMov(){mover_flag =true;}
+
+ void setDireccion(int index);
+
+ int getDireccion() const {return orientacion;}
+ sf::Vector2i getOrientacion() const {return sf::Vector2i(velocidad.x,velocidad.y);}
+
+ const sf::Sprite& getSprite() const {return sprite;}
+
+
+ protected:
+ Tablero &tablero;
+ sf::Texture const* textura[4][2];
+
+ void setVelocidad(int tiempo_fotograma)
+ {
+ tiempo_entre_pixeles = tiempo_fotograma/Tablero::ESCALA;
+ }
+
+ void setTexture(sf::Texture const* textura)
+ {
+ sprite.setTexture(*textura);
+ }
+
+ virtual void comer(int x,int y){}
+ private:
+
+
+ sf::Sprite sprite;
+
+ sf::Vector2f velocidad;
+ sf::Vector2f velocidad_aux;
+
+ sf::Vector2i vPulsada;
+ int tPulsada;
+ int oriPulsada;
+
+ static const int tEspPulsada =3;
+
+
+ int orientacion; // Hacia donde mira el personaje
+ int anim = 0; // Que fotograma de la animación lleva actualmente
+ bool en_movimiento;
+ int tiempo_de_animacion = 300;
+ sf::Vector2f destino;
+ int acum;
+
+ bool mover_flag =true;
+
+ //sf::Time tiempo_entre_mov;
+ sf::Clock reloj;
+ sf::Clock reloj_animacion;
+
+ int tiempo_entre_pixeles;
+
+ void animar();
+ void iniciarMovimiento();
+ void transicion_movimiento();
+ bool tratar_bordes();
+};
+
+#endif // PERSONAJE_HPP
diff --git a/SRC/Puntuacion.cpp b/SRC/Puntuacion.cpp
new file mode 100644
index 0000000..f3bb3f6
--- /dev/null
+++ b/SRC/Puntuacion.cpp
@@ -0,0 +1,61 @@
+#include "Puntuacion.hpp"
+#include "AlmacenDeFuentes.hpp"
+#include "AlmacenDeGraficos.hpp"
+#include "Puntuacion.hpp"
+#include <sstream>
+#include "Estado.hpp"
+
+Puntuacion::Puntuacion()
+{
+ //ctor
+ marcador.setFont(AlmacenDeFuentes::getInstancia().getArial());
+ marcador.setPosition(300,640);
+ marcador.setCharacterSize(24);
+ marcador.setColor(sf::Color::White);
+ actualizarMarcador();
+
+ Estado::getInstancia().anyadirCallback(this);
+}
+
+void Puntuacion::comerComida()
+{
+ puntos += 20;
+ actualizarMarcador();
+}
+
+void Puntuacion::comerPildora()
+{
+ puntos += 30;
+ actualizarMarcador();
+}
+
+void Puntuacion::comerFantasma(sf::Vector2f pos)
+{
+ puntos += 200*incr;
+ incr *= 2;
+
+ sprite.setPosition(pos);
+ sprite.setTexture(AlmacenDeGraficos::getInstancia().getPuntos(consecutivos));
+
+ consecutivos++;
+ actualizarMarcador();
+}
+
+void Puntuacion::actualizarMarcador()
+{
+ std::stringstream stream;
+ stream<<"Puntos: "<<puntos;
+ marcador.setString(stream.str());
+}
+
+void Puntuacion::disableRampage()
+{
+ consecutivos = 0;
+ incr = 1;
+ sprite.setPosition(-20,-20);
+}
+
+Puntuacion::~Puntuacion()
+{
+ Estado::getInstancia().eliminarCallback(this);
+}
diff --git a/SRC/Puntuacion.hpp b/SRC/Puntuacion.hpp
new file mode 100644
index 0000000..95cf444
--- /dev/null
+++ b/SRC/Puntuacion.hpp
@@ -0,0 +1,38 @@
+#ifndef PUNTUACION_H
+#define PUNTUACION_H
+#include <SFML/Graphics.hpp>
+#include "Callback_rampage.hpp"
+
+class Puntuacion : public callback_rampage
+{
+ public:
+ Puntuacion();
+
+ void comerComida();
+ void comerPildora();
+ void comerFantasma(sf::Vector2f pos);
+
+ int getPuntos() const {return puntos;};
+
+ const sf::Text& getText() const {return marcador;}
+ const sf::Sprite getPuntuacionEmergente() const {return sprite;}
+
+ void setRampage() override{};
+ void warningRampage() override {}
+ void disableRampage() override;
+
+ ~Puntuacion();
+ protected:
+ private:
+
+ void actualizarMarcador();
+
+ sf::Text marcador;
+ sf::Sprite sprite;
+ int puntos = 0;
+
+ int consecutivos = 0;
+ int incr = 1;
+};
+
+#endif // PUNTUACION_H
diff --git a/SRC/Tablero.cpp b/SRC/Tablero.cpp
new file mode 100644
index 0000000..f7b53f0
--- /dev/null
+++ b/SRC/Tablero.cpp
@@ -0,0 +1,139 @@
+#include "Tablero.hpp"
+#include "Puntuacion.hpp"
+
+const char mapa_orig[Tablero::Tamanyo_Mapa_Y][Tablero::Tamanyo_Mapa_X]={
+ {"xxxxxxxxxxxxxxxxxxxxxxxxxxxx"},
+ {"xccccccccccccxxccccccccccccx"},
+ {"xcxxxxcxxxxxcxxcxxxxxcxxxxcx"},
+ {"xCx xcx xcxxcx xcx xCx"},
+/* Fxla 5 */ {"xcxxxxcxxxxxcxxcxxxxxcxxxxcx"},
+ {"xccccccccccccccccccccccccccx"},
+ {"xcxxxxcxxcxxxxxxxxcxxcxxxxcx"},
+ {"xcxxxxcxxcxxxxxxxxcxxcxxxxcx"},
+ {"xccccccxxccccxxccccxxccccccx"},
+/* Fxla 10 */ {"xxxxxxcxxxxxcxxcxxxxxcxxxxxx"},
+ {" xcxxxxxcxxcxxxxxcx "},
+ {" xcxx xxcx "},
+ {" xcxx xxx xxx xxcx "},
+ {"xxxxxxcxx x x xxcxxxxxx"},
+/* Fxla 15 */ {" c x x c "},
+ {"xxxxxxcxx x x xxcxxxxxx"},
+ {" xcxx xxxxxxxx xxcx "},
+ {" xcxx xxcx "},
+ {" xcxx xxxxxxxx xxcx "},
+/* Fxla 20 */ {"xxxxxxcxx xxxxxxxx xxcxxxxxx"},
+ {"xccccccccccccxxccccccccccccx"},
+ {"xcxxxxcxxxxxcxxcxxxxxcxxxxcx"},
+ {"xcxxxxcxxxxxcxxcxxxxxcxxxxcx"},
+ {"xCccxxccccccc ccccccccxxccCx"},
+/* Fxla 25 */ {"xxxcxxcxxcxxxxxxxxcxxcxxcxxx"},
+ {"xxxcxxcxxcxxxxxxxxcxxcxxcxxx"},
+ {"xccccccxxccccxxccccxxccccccx"},
+ {"xcxxxxxxxxxxcxxcxxxxxxxxxxcx"},
+ {"xcxxxxxxxxxxcxxcxxxxxxxxxxcx"},
+/* Fxla 30 */ {"xccccccccccccccccccccccccccx"},
+ {"xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
+ };
+
+
+Tablero::Tablero(const int resolucionx,const int resoluciony,Puntuacion& p)
+: RESOLUCION(resolucionx,resoluciony),puntuacion(p)
+{
+ //ctor
+ for (int i = 0;i<Tamanyo_Mapa_Y;i++)
+ {
+ for (int j = 0;j<Tamanyo_Mapa_X;j++)
+ {
+ mapa[i][j] = mapa_orig[i][j];
+ }
+ }
+
+ campo.loadFromFile("./Image/Nivel.png");
+ campo_con_la_comida.create(resolucionx,resoluciony);
+
+ comida_representacion.setRadius(ESCALA/4);
+ comida_representacion.setFillColor(sf::Color::Yellow);
+
+ pildora_representacion.setRadius(ESCALA/4+2);
+ pildora_representacion.setFillColor(sf::Color::Red);
+
+ generarRepresentacion();
+}
+
+void Tablero::generarRepresentacion()
+{
+ campo_con_la_comida.clear();
+ campo_con_la_comida.draw(sf::Sprite(campo));
+ comida = 0;
+
+ for (int i = 0;i<Tamanyo_Mapa_X;i++)
+ {
+ for (int j = 0;j<Tamanyo_Mapa_Y;j++)
+ {
+ if (esComida(i,j))
+ {
+ comida++;
+ comida_representacion.setPosition(i*ESCALA+ESCALA/4,j*ESCALA+ESCALA/4);
+ campo_con_la_comida.draw(comida_representacion);
+ }
+ else if (esPildora(i,j))
+ {
+ comida++;
+ pildora_representacion.setPosition(i*ESCALA+ESCALA/4-2,j*ESCALA+ESCALA/4-2);
+ campo_con_la_comida.draw(pildora_representacion);
+ }
+ }
+ }
+
+ campo_con_la_comida.display();
+ sprite.setTexture(campo_con_la_comida.getTexture());
+}
+
+bool Tablero::esComida(int x,int y) const
+{
+ return mapa[y][x] == 'c';
+}
+
+bool Tablero::esPildora(int x,int y) const
+{
+ return mapa[y][x] == 'C';
+}
+
+bool Tablero::comible(int x,int y) const
+{
+ return esComida(x,y) || esPildora(x,y);
+}
+
+int Tablero::comer(int x,int y)
+{
+ if (esPared(x,y)) return 0;
+ else
+ {
+ if (comible(x,y))
+ {
+ //puntos++;
+ comida--;
+
+ if (esPildora(x,y))
+ {
+ puntuacion.comerPildora();
+ borrarComida(x,y);
+ return -1;
+ }
+ else
+ {
+ puntuacion.comerComida();
+ borrarComida(x,y);
+ }
+ return 1;
+
+ }
+ return 0;
+ }
+}
+
+void Tablero::borrarComida(int x,int y)
+{
+ mapa[y][x] = ' ';
+ generarRepresentacion();
+}
diff --git a/SRC/Tablero.hpp b/SRC/Tablero.hpp
new file mode 100644
index 0000000..c2542a6
--- /dev/null
+++ b/SRC/Tablero.hpp
@@ -0,0 +1,55 @@
+#ifndef TABLERO_H
+#define TABLERO_H
+#include <SFML/Graphics.hpp>
+
+class Puntuacion;
+
+class Tablero
+{
+ public:
+
+ static const int ESCALA = 20;
+ static const int Tamanyo_Mapa_X = 29;
+ static const int Tamanyo_Mapa_Y = 31;
+
+ Tablero(const int resolucionx,const int resoluciony,Puntuacion& p);
+
+ int comer(sf::Vector2f pos){return comer(pos.x,pos.y);}
+ int comer(int x,int y);
+
+ //int getPuntos() const {return puntos;}
+ int getComida() const {return comida;}
+ bool getColision(sf::Vector2f pos) const{ return getColision(pos.x,pos.y);}
+ bool getColision(sf::Vector2i pos) const {return getColision(pos.x,pos.y);}
+ bool getColision(int x,int y) const{ return esPared(x,y);}
+ const sf::Sprite& getRepresentacion() const {return sprite;;}
+
+ void setColision(sf::Vector2i pos){buffer = mapa[pos.y][pos.x]; mapa[pos.y][pos.x]= 'x';}
+ void deleteColision(sf::Vector2i pos){mapa[pos.y][pos.x] = buffer;}
+ protected:
+ private:
+ const sf::Vector2f RESOLUCION;
+ int comida;
+
+ bool esPared(int x,int y) const {return mapa[y][x] == 'x';} // Puede desbordar en los bordes, en ese caso adcederá a la fila anterior/posterior, leerá un caracter nulo y por tanto devolverá false
+ bool comible(int x,int y) const;
+ bool esComida(int x,int y) const;
+ bool esPildora(int x,int y) const;
+ void borrarComida(int x,int y);
+ void generarRepresentacion();
+
+ char buffer;
+
+ sf::Texture campo;
+ sf::RenderTexture campo_con_la_comida;
+ sf::CircleShape comida_representacion;
+ sf::CircleShape pildora_representacion;
+
+ sf::Sprite sprite;
+
+ Puntuacion &puntuacion;
+
+ char mapa[Tamanyo_Mapa_Y][Tamanyo_Mapa_X];
+};
+
+#endif // TABLERO_H
diff --git a/SRC/main.cpp b/SRC/main.cpp
new file mode 100644
index 0000000..d9325ca
--- /dev/null
+++ b/SRC/main.cpp
@@ -0,0 +1,190 @@
+#include <SFML/Graphics.hpp>
+#include <SFML/Audio.hpp>
+#include "Tablero.hpp"
+#include "Pacman.hpp"
+#include "FantasmaRojo.hpp"
+#include "FantasmaRosa.hpp"
+#include "FantasmaAmarillo.hpp"
+#include "FantasmaAzul.hpp"
+#include "Estado.hpp"
+#include "AlmacenDeSonido.hpp"
+#include "AlmacenDeFuentes.hpp"
+#include "Puntuacion.hpp"
+#include <cstdlib>
+#include <ctime>
+#include <iostream>
+#include <memory>
+
+const int RESOLUCIONX = 560;
+const int RESOLUCIONY = 680;
+const int POS_INICIAL_PACMANX = 13;
+const int POS_INICIAL_PACMANY = 23;
+
+int main()
+{
+ std::srand(std::time(0));
+ // Create the main window
+ sf::RenderWindow app(sf::VideoMode(560, 680), "Comecocos");
+ app.setFramerateLimit(60);
+
+ /**
+ * Bucle principal del juego:
+ *
+ * - Eventos, llamadas a las set Dirrecion
+ * - moverPersonaje()
+ * - moverFantasmas()
+ * - Dibujado
+ */
+
+ int vidas = 3;
+ int nivel = 1;
+
+ sf::Text vidas_y_nivel;
+ vidas_y_nivel.setFont(AlmacenDeFuentes::getInstancia().getArial());
+ vidas_y_nivel.setCharacterSize(24);
+ vidas_y_nivel.setPosition(50,RESOLUCIONY-40);
+
+ sf::Sound introduccion;
+ introduccion.setBuffer(AlmacenDeSonido::getInstancia().getPacman_beginning());
+
+ Puntuacion puntuacion;
+
+ std::unique_ptr<Tablero> tablero(new Tablero(RESOLUCIONX,RESOLUCIONY,puntuacion));
+
+ while (vidas && app.isOpen())
+ {
+ std::cout<<"Vidas: "<<vidas<<std::endl<<"Nivel: "<<nivel<<std::endl<<std::endl;
+
+ vidas_y_nivel.setString("Vidas: "+std::to_string(vidas) + " Nivel: " + std::to_string(nivel));
+
+ //Tablero tablero(RESOLUCIONX,RESOLUCIONY);
+ Pacman pacman(*tablero,POS_INICIAL_PACMANX,POS_INICIAL_PACMANY);
+ FantasmaRojo fantasma_rojo(*tablero,pacman,puntuacion,13,13);
+ FantasmaRosa fantasma_rosa(*tablero,pacman,puntuacion,13,14,fantasma_rojo);
+ FantasmaAmarillo fantasma_amarillo(*tablero,pacman,puntuacion,14,13);
+ FantasmaAzul fantasma_azul(*tablero,pacman,puntuacion,14,14);
+
+ pacman.disableMov();
+ fantasma_rojo.disableMov();
+ fantasma_rosa.disableMov();
+ fantasma_amarillo.disableMov();
+ fantasma_azul.disableMov();
+
+
+ // sf::Event event;
+ sf::Clock reloj;
+ reloj.restart();
+
+ introduccion.play();
+
+ //Fantasmas fantasmas;
+
+ // Start the game loop
+ while (app.isOpen() && tablero->getComida() > 0 && !pacman.terminado())
+ {
+ // Process events
+ sf::Event event;
+ while (app.pollEvent(event))
+ {
+ // Close window : exit
+ if (event.type == sf::Event::Closed)
+ app.close();
+ if (event.type == sf::Event::KeyPressed)
+ {
+ if (event.key.code == sf::Keyboard::A || event.key.code == sf::Keyboard::Left)
+ {
+ pacman.setIzquierdaDireccion();
+ }
+ else if (event.key.code == sf::Keyboard::D || event.key.code == sf::Keyboard::Right)
+ {
+ pacman.setDerechaDireccion();
+ }
+ else if (event.key.code == sf::Keyboard::W || event.key.code == sf::Keyboard::Up)
+ {
+ pacman.setArribaDireccion();
+ }
+ else if (event.key.code == sf::Keyboard::S || event.key.code == sf::Keyboard::Down)
+ {
+ pacman.setAbajoDireccion();
+ }
+ else if (event.key.code == sf::Keyboard::K)
+ {
+ pacman.matar();
+ }
+ else if (event.key.code == sf::Keyboard::Escape)
+ {
+ app.close();
+ }
+ }
+ }
+
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::A) || sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
+ {
+ pacman.setIzquierdaDireccion();
+ }
+ else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D) || sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
+ {
+ pacman.setDerechaDireccion();
+ }
+ else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S) || sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
+ {
+ pacman.setAbajoDireccion();
+ }
+ else if (sf::Keyboard::isKeyPressed(sf::Keyboard::W) || sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
+ {
+ pacman.setArribaDireccion();
+ }
+
+ if (reloj.getElapsedTime() >= sf::seconds(4))
+ {
+ // Ya ha terminado la animación. Ya se puede correr
+
+ pacman.enableMov();
+ fantasma_rojo.enableMov();
+ fantasma_rosa.enableMov();
+ fantasma_amarillo.enableMov();
+ fantasma_azul.enableMov();
+ }
+
+ Estado::getInstancia().refresh();
+
+ pacman.mover();
+
+ fantasma_rojo.mover();
+ fantasma_rosa.mover();
+ fantasma_amarillo.mover();
+ fantasma_azul.mover();
+ /*if (fantasmas.mover())
+ {
+ app.close();
+ }*/
+
+ app.clear();
+ app.draw(tablero->getRepresentacion());
+ app.draw(fantasma_rojo.getSprite());
+ app.draw(fantasma_rosa.getSprite());
+ app.draw(fantasma_amarillo.getSprite());
+ app.draw(fantasma_azul.getSprite());
+ app.draw(pacman.getSprite());
+ app.draw(puntuacion.getText());
+ app.draw(puntuacion.getPuntuacionEmergente());
+ app.draw(vidas_y_nivel);
+
+ //app.draw(sf::Sprite(AlmacenDeGraficos::getInstancia().getFantasma(0,0,1)));
+ app.display();
+ }
+
+ vidas -= pacman.terminado();
+
+ if (tablero->getComida() == 0)
+ {
+ tablero.reset(new Tablero(RESOLUCIONX,RESOLUCIONY,puntuacion));
+ nivel++;
+ }
+
+ Estado::getInstancia().desactivarRampage();
+
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/Sound/pacman_beginning.wav b/Sound/pacman_beginning.wav
new file mode 100644
index 0000000..5303fb1
Binary files /dev/null and b/Sound/pacman_beginning.wav differ
diff --git a/Sound/pacman_death.wav b/Sound/pacman_death.wav
new file mode 100644
index 0000000..153019e
Binary files /dev/null and b/Sound/pacman_death.wav differ
diff --git a/Sound/pacman_eatfruit.wav b/Sound/pacman_eatfruit.wav
new file mode 100644
index 0000000..420c02b
Binary files /dev/null and b/Sound/pacman_eatfruit.wav differ
diff --git a/Sound/pacman_rampage.wav b/Sound/pacman_rampage.wav
new file mode 100644
index 0000000..993b08e
Binary files /dev/null and b/Sound/pacman_rampage.wav differ
diff --git a/Sprites/Fantasma.png b/Sprites/Fantasma.png
new file mode 100644
index 0000000..191b901
Binary files /dev/null and b/Sprites/Fantasma.png differ
diff --git a/Sprites/pacman.png b/Sprites/pacman.png
new file mode 100644
index 0000000..776a717
Binary files /dev/null and b/Sprites/pacman.png differ

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 16, 12:31 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70951
Default Alt Text
(49 KB)

Event Timeline