Compare commits
36 Commits
v2.0.1
...
b092d3f86a
| Author | SHA1 | Date | |
|---|---|---|---|
| b092d3f86a | |||
| 837bcbd1da | |||
| 26bc47d9f6 | |||
| 9e089e9092 | |||
| 25616e1e6c | |||
| ed67e429d8 | |||
| 4ebd034b59 | |||
| 38f3e2e4d3 | |||
| 6493b73f4f | |||
| 6637ba9f10 | |||
| a74c8d5122 | |||
| 4df0db088f | |||
| 27cb772933 | |||
| 778b07cce1 | |||
| 1fa5c75466 | |||
| 0b00acf31b | |||
| 2979a6752c | |||
| f6494e69c8 | |||
| 5167a5857d | |||
| 28fe1130cf | |||
| e92b7eab4e | |||
| 14f7a79927 | |||
| 4f6a6a4918 | |||
| f5b35cee6b | |||
| 454791fe96 | |||
| 3f165be114 | |||
| 778672a6f5 | |||
| 8c919abc9d | |||
| 7e37da3999 | |||
| 842d5dd56b | |||
| ea3f16b8ac | |||
| 3fe0861e4f | |||
| b28d798545 | |||
| bdf092d46e | |||
| 09421a093d | |||
| a7d7cdd047 |
11
.gitignore
vendored
11
.gitignore
vendored
@@ -1,12 +1,5 @@
|
||||
.vscode
|
||||
*.DS_Store
|
||||
bin
|
||||
data/config.bin
|
||||
data/score.bin
|
||||
dll
|
||||
docs
|
||||
icon
|
||||
releases
|
||||
resources
|
||||
scripts
|
||||
*.opk
|
||||
*.DS_Store
|
||||
data/score.bin
|
||||
6
Makefile
6
Makefile
@@ -6,4 +6,8 @@ macos:
|
||||
linux:
|
||||
mkdir -p bin
|
||||
g++ source/*.cpp -std=c++11 -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o bin/$(executable)_linux
|
||||
strip -s -R .comment -R .gnu.version bin/$(executable)_linux --strip-unneeded
|
||||
strip -s -R .comment -R .gnu.version bin/$(executable)_linux --strip-unneeded
|
||||
opendingux:
|
||||
mkdir -p bin
|
||||
/opt/gcw0-toolchain/usr/bin/mipsel-linux-gcc -D GCWZERO -O2 -std=c++11 -I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include/SDL2 -D_GNU_SOURCE=1 -D_REENTRANT -lSDL2 -lSDL2_mixer -lstdc++ source/*.cpp -o bin/$(executable)_opendingux
|
||||
/opt/gcw0-toolchain/usr/bin/mksquashfs ./default.gcw0.desktop ./icon.png ./bin ./data ./media coffee_crisis.opk -all-root -noappend -no-exports -no-xattrs
|
||||
@@ -1,6 +1,6 @@
|
||||
# Coffee Crisis
|
||||
|
||||
Coffe Crisis es un juego arcade que pondrá a prueba tus reflejos. Empezado el verano de 2020 y terminado el verano de 2021. Intenta conseguir todos los puntos que puedas con una sola vida y ayuda a Bal1 a defender la UPV ante la invasión de la cafeína durante 10 estresantes oleadas.
|
||||
Coffee Crisis es un juego arcade que pondrá a prueba tus reflejos. Empezado durante el verano de 2020 y terminado un año despues, en el verano de 2021. Intenta conseguir todos los puntos que puedas con una sola vida a traves de los 10 niveles de juego y ayuda a Bal1 a defender la UPV de la invasión de la cafeína esférica y saltarina.
|
||||
|
||||
## Compilar
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 8.1 KiB |
@@ -157,7 +157,7 @@
|
||||
# 108 l
|
||||
8
|
||||
# 109 m
|
||||
10
|
||||
20
|
||||
# 110 n
|
||||
14
|
||||
# 111 o
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 6.9 KiB |
@@ -75,21 +75,21 @@ Temps detes:
|
||||
## 37 - TEXTOS DEL JUEGO
|
||||
D E M O
|
||||
## 38 - TEXTOS DEL JUEGO
|
||||
Pantalla
|
||||
## 39 - MARCADOR
|
||||
PUNTS
|
||||
## 40 - MARCADOR
|
||||
MAX.PUNT.
|
||||
## 41 - MARCADOR
|
||||
MULT
|
||||
## 42 - MARCADOR
|
||||
PANTALLA
|
||||
fases mes!
|
||||
## 39 -
|
||||
|
||||
## 40 -
|
||||
|
||||
## 41 -
|
||||
|
||||
## 42 -
|
||||
|
||||
## 43 - PANTALLA DE GAME OVER
|
||||
FI DEL JOC
|
||||
## 44 - PANTALLA DE GAME OVER
|
||||
ELS TEUS PUNTS:
|
||||
## 45 - PANTALLA DE GAME OVER
|
||||
REINTENTAR?
|
||||
CONTINUAR?
|
||||
## 46 - MENU DE PAUSA
|
||||
CONTINUAR
|
||||
## 47 - MENU DE PAUSA
|
||||
@@ -113,7 +113,7 @@ mult
|
||||
## 56 MARCADOR
|
||||
max. puntuacio
|
||||
## 57 MARCADOR
|
||||
pantalla
|
||||
fase
|
||||
## 58 - MENU DE OPCIONES
|
||||
MODE DE VISUALITZACIO
|
||||
## 59 - MENU DE OPCIONES
|
||||
@@ -126,10 +126,10 @@ SINC. VERTICAL
|
||||
CONTROLS DEL JUGADOR 1
|
||||
## 63 - MENU DE OPCIONES
|
||||
CONTROLS DEL JUGADOR 2
|
||||
## 64 - MENU DE OPCIONES
|
||||
TECLAT
|
||||
## 65 - MENU DE OPCIONES
|
||||
MANDO
|
||||
## 64 -
|
||||
|
||||
## 65 -
|
||||
|
||||
## 66 - MENU DE OPCIONES
|
||||
FACIL
|
||||
## 67 - MENU DE OPCIONES
|
||||
@@ -155,4 +155,6 @@ Endavant!
|
||||
## 77 - PANTALLA DE GAME OVER
|
||||
PUNTS J1:
|
||||
## 78 - PANTALLA DE GAME OVER
|
||||
PUNTS J2:
|
||||
PUNTS J2:
|
||||
## 79 - TEXTOS DEL JUEGO
|
||||
Ultima fase!
|
||||
@@ -75,21 +75,21 @@ Time stopped:
|
||||
## 37 - TEXTOS DEL JUEGO
|
||||
D E M O
|
||||
## 38 - TEXTOS DEL JUEGO
|
||||
Stage
|
||||
## 39 - MARCADOR
|
||||
SCORE
|
||||
## 40 - MARCADOR
|
||||
HI-SCORE
|
||||
## 41 - MARCADOR
|
||||
MULT
|
||||
## 42 - MARCADOR
|
||||
STAGE
|
||||
stages left!
|
||||
## 39 -
|
||||
|
||||
## 40 -
|
||||
|
||||
## 41 -
|
||||
|
||||
## 42 -
|
||||
|
||||
## 43 - PANTALLA DE GAME OVER
|
||||
GAME OVER
|
||||
## 44 - PANTALLA DE GAME OVER
|
||||
YOUR SCORE:
|
||||
## 45 - PANTALLA DE GAME OVER
|
||||
RETRY?
|
||||
CONTINUE?
|
||||
## 46 - MENU DE PAUSA
|
||||
CONTINUE
|
||||
## 47 - MENU DE PAUSA
|
||||
@@ -126,10 +126,10 @@ VSYNC
|
||||
PLAYER 1 CONTROLS
|
||||
## 63 - MENU DE OPCIONES
|
||||
PLAYER 2 CONTROLS
|
||||
## 64 - MENU DE OPCIONES
|
||||
KEYBOARD
|
||||
## 65 - MENU DE OPCIONES
|
||||
GAME CONTROLLER
|
||||
## 64 -
|
||||
|
||||
## 65 -
|
||||
|
||||
## 66 - MENU DE OPCIONES
|
||||
EASY
|
||||
## 67 - MENU DE OPCIONES
|
||||
@@ -155,4 +155,6 @@ Get Ready!
|
||||
## 77 - PANTALLA DE GAME OVER
|
||||
PLAYER1 SCORE:
|
||||
## 78 - PANTALLA DE GAME OVER
|
||||
PLAYER2 SCORE:
|
||||
PLAYER2 SCORE:
|
||||
## 79 - TEXTOS DEL JUEGO
|
||||
Last stage!
|
||||
@@ -75,21 +75,21 @@ Tiempo:
|
||||
## 37 - TEXTOS DEL JUEGO
|
||||
D E M O
|
||||
## 38 - TEXTOS DEL JUEGO
|
||||
Fase
|
||||
## 39 - MARCADOR
|
||||
PUNTOS
|
||||
## 40 - MARCADOR
|
||||
MAX.PUNT.
|
||||
## 41 - MARCADOR
|
||||
MULT
|
||||
## 42 - MARCADOR
|
||||
FASE
|
||||
fases mas!
|
||||
## 39 -
|
||||
|
||||
## 40 -
|
||||
|
||||
## 41 -
|
||||
|
||||
## 42 -
|
||||
|
||||
## 43 - PANTALLA DE GAME OVER
|
||||
FIN DE JUEGO
|
||||
## 44 - PANTALLA DE GAME OVER
|
||||
TU PUNTUACION:
|
||||
## 45 - PANTALLA DE GAME OVER
|
||||
REINTENTAR?
|
||||
CONTINUAR?
|
||||
## 46 - MENU DE PAUSA
|
||||
CONTINUAR
|
||||
## 47 - MENU DE PAUSA
|
||||
@@ -113,7 +113,7 @@ mult
|
||||
## 56 - MARCADOR
|
||||
max. puntuacion
|
||||
## 57 - MARCADOR
|
||||
fase
|
||||
FASE
|
||||
## 58 - MENU DE OPCIONES
|
||||
MODO DE VISUALIZACION
|
||||
## 59 - MENU DE OPCIONES
|
||||
@@ -126,10 +126,10 @@ SINC. VERTICAL
|
||||
CONTROLES DEL JUGADOR 1
|
||||
## 63 - MENU DE OPCIONES
|
||||
CONTROLES DEL JUGADOR 2
|
||||
## 64 - MENU DE OPCIONES
|
||||
TECLADO
|
||||
## 65 - MENU DE OPCIONES
|
||||
MANDO
|
||||
## 64 -
|
||||
|
||||
## 65 -
|
||||
|
||||
## 66 - MENU DE OPCIONES
|
||||
FACIL
|
||||
## 67 - MENU DE OPCIONES
|
||||
@@ -155,4 +155,6 @@ Adelante!
|
||||
## 77 - PANTALLA DE GAME OVER
|
||||
PUNTUACION J1:
|
||||
## 78 - PANTALLA DE GAME OVER
|
||||
PUNTUACION J2:
|
||||
PUNTUACION J2:
|
||||
## 79 - TEXTOS DEL JUEGO
|
||||
Ultima fase!
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,123 +1,333 @@
|
||||
#include "const.h"
|
||||
|
||||
#include "animatedsprite.h"
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite()
|
||||
AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::string file)
|
||||
{
|
||||
//init(nullptr, nullptr);
|
||||
// Copia los punteros
|
||||
setTexture(texture);
|
||||
setRenderer(renderer);
|
||||
|
||||
// Carga las animaciones
|
||||
load(file);
|
||||
|
||||
// Inicializa variables
|
||||
currentAnimation = 0;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
AnimatedSprite::~AnimatedSprite()
|
||||
{
|
||||
//init(nullptr, nullptr);
|
||||
for (auto &a : animation)
|
||||
{
|
||||
a.frames.clear();
|
||||
}
|
||||
animation.clear();
|
||||
}
|
||||
|
||||
// Iniciador
|
||||
void AnimatedSprite::init(LTexture *texture, SDL_Renderer *renderer)
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int AnimatedSprite::getIndex(std::string name)
|
||||
{
|
||||
mRenderer = renderer;
|
||||
mTexture = texture;
|
||||
for (int i = 0; i < 20; i++)
|
||||
int index = -1;
|
||||
|
||||
for (auto a : animation)
|
||||
{
|
||||
mAnimation[i].numFrames = 0;
|
||||
mAnimation[i].speed = 0;
|
||||
mAnimation[i].loop = true;
|
||||
mAnimation[i].completed = false;
|
||||
for (int j = 0; i < 20; i++)
|
||||
index++;
|
||||
if (a.name == name)
|
||||
{
|
||||
mAnimation[i].frames[j].x = 0;
|
||||
mAnimation[i].frames[j].y = 0;
|
||||
mAnimation[i].frames[j].w = 0;
|
||||
mAnimation[i].frames[j].h = 0;
|
||||
return index;
|
||||
}
|
||||
}
|
||||
mCurrentFrame = 0;
|
||||
mAnimationCounter = 0;
|
||||
|
||||
printf("** Warning: could not find \"%s\" animation\n", name.c_str());
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Calcula el frame correspondiente a la animación
|
||||
void AnimatedSprite::animate(int index)
|
||||
void AnimatedSprite::animate()
|
||||
{
|
||||
if (mEnabled)
|
||||
if (!enabled || animation[currentAnimation].speed == 0)
|
||||
{
|
||||
// Calculamos el frame actual a partir del contador
|
||||
mCurrentFrame = mAnimationCounter / mAnimation[index].speed;
|
||||
return;
|
||||
}
|
||||
|
||||
// Si alcanzamos el final de la animación, reiniciamos el contador de la animación
|
||||
// en función de la variable loop
|
||||
if (mCurrentFrame >= mAnimation[index].numFrames)
|
||||
{
|
||||
if (mAnimation[index].loop)
|
||||
mAnimationCounter = 0;
|
||||
else
|
||||
mCurrentFrame = mAnimation[index].numFrames;
|
||||
// Calcula el frame actual a partir del contador
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].counter / animation[currentAnimation].speed;
|
||||
|
||||
// Si alcanza el final de la animación, reinicia el contador de la animación
|
||||
// en función de la variable loop y coloca el nuevo frame
|
||||
if (animation[currentAnimation].currentFrame >= (int)animation[currentAnimation].frames.size())
|
||||
{
|
||||
if (animation[currentAnimation].loop == -1)
|
||||
{ // Si no hay loop, deja el último frame
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].frames.size();
|
||||
animation[currentAnimation].completed = true;
|
||||
}
|
||||
// En caso contrario
|
||||
else
|
||||
{
|
||||
// Escogemos el frame correspondiente de la animación
|
||||
setSpriteClip(mAnimation[index].frames[mCurrentFrame]);
|
||||
|
||||
// Incrementamos el contador de la animacion
|
||||
mAnimationCounter++;
|
||||
{ // Si hay loop, vuelve al frame indicado
|
||||
animation[currentAnimation].counter = 0;
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].loop;
|
||||
}
|
||||
}
|
||||
// En caso contrario
|
||||
else
|
||||
{
|
||||
// Escoge el frame correspondiente de la animación
|
||||
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
|
||||
|
||||
// Incrementa el contador de la animacion
|
||||
animation[currentAnimation].counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
void AnimatedSprite::setCurrentFrame(Uint8 num)
|
||||
void AnimatedSprite::setCurrentFrame(int num)
|
||||
{
|
||||
mCurrentFrame = num;
|
||||
// Descarta valores fuera de rango
|
||||
if (num >= (int)animation[currentAnimation].frames.size())
|
||||
{
|
||||
num = 0;
|
||||
}
|
||||
|
||||
// Cambia el valor de la variable
|
||||
animation[currentAnimation].counter = animation[currentAnimation].speed * num;
|
||||
|
||||
// Escoge el frame correspondiente de la animación
|
||||
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
|
||||
}
|
||||
|
||||
// Establece el valor del contador
|
||||
void AnimatedSprite::setAnimationCounter(Uint16 num)
|
||||
void AnimatedSprite::setAnimationCounter(std::string name, int num)
|
||||
{
|
||||
mAnimationCounter = num;
|
||||
animation[getIndex(name)].counter = num;
|
||||
}
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
|
||||
{
|
||||
animation[getIndex(name)].counter = speed;
|
||||
}
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void AnimatedSprite::setAnimationSpeed(int index, int speed)
|
||||
{
|
||||
animation[index].counter = speed;
|
||||
}
|
||||
|
||||
// Establece si la animación se reproduce en bucle
|
||||
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
||||
{
|
||||
animation[getIndex(name)].loop = loop;
|
||||
}
|
||||
|
||||
// Establece si la animación se reproduce en bucle
|
||||
void AnimatedSprite::setAnimationLoop(int index, int loop)
|
||||
{
|
||||
animation[index].loop = loop;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
||||
{
|
||||
animation[getIndex(name)].completed = value;
|
||||
}
|
||||
|
||||
// OLD - Establece el valor de la variable
|
||||
void AnimatedSprite::setAnimationCompleted(int index, bool value)
|
||||
{
|
||||
animation[index].completed = value;
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool AnimatedSprite::animationIsCompleted()
|
||||
{
|
||||
return animation[currentAnimation].completed;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
|
||||
{
|
||||
return animation[getIndex(name)].frames[index];
|
||||
}
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
bool AnimatedSprite::load(std::string filePath)
|
||||
{
|
||||
int frames_per_row = 0;
|
||||
int frame_width = 0;
|
||||
int frame_height = 0;
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
|
||||
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||
std::ifstream file(filePath);
|
||||
std::string line;
|
||||
|
||||
// El fichero se puede abrir
|
||||
if (file.good())
|
||||
{
|
||||
// Procesa el fichero linea a linea
|
||||
printf("Reading file %s\n", filename.c_str());
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
{
|
||||
t_animation buffer;
|
||||
buffer.counter = 0;
|
||||
buffer.currentFrame = 0;
|
||||
buffer.completed = false;
|
||||
|
||||
do
|
||||
{
|
||||
std::getline(file, line);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != (int)line.npos)
|
||||
{
|
||||
if (line.substr(0, pos) == "name")
|
||||
{
|
||||
buffer.name = line.substr(pos + 1, line.length());
|
||||
}
|
||||
else if (line.substr(0, pos) == "speed")
|
||||
{
|
||||
buffer.speed = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
else if (line.substr(0, pos) == "loop")
|
||||
{
|
||||
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
else if (line.substr(0, pos) == "frames")
|
||||
{
|
||||
// Se introducen los valores separados por comas en un vector
|
||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
||||
std::string tmp;
|
||||
SDL_Rect rect = {0, 0, frame_width, frame_height};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
int num_tile = std::stoi(tmp);
|
||||
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||
buffer.frames.push_back(rect);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
|
||||
// Añade la animación al vector de animaciones
|
||||
animation.push_back(buffer);
|
||||
}
|
||||
|
||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||
else
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != (int)line.npos)
|
||||
{
|
||||
if (line.substr(0, pos) == "frames_per_row")
|
||||
{
|
||||
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_width")
|
||||
{
|
||||
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||
|
||||
// Normaliza valores
|
||||
if (frames_per_row == 0)
|
||||
{
|
||||
frames_per_row = texture->getWidth() / frame_width;
|
||||
}
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_height")
|
||||
{
|
||||
frame_height = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
printf("Closing file %s\n\n", filename.c_str());
|
||||
file.close();
|
||||
}
|
||||
// El fichero no se puede abrir
|
||||
else
|
||||
{
|
||||
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Pone un valor por defecto
|
||||
setPos({0, 0, frame_width, frame_height});
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(std::string name)
|
||||
{
|
||||
const int newAnimation = getIndex(name);
|
||||
if (currentAnimation != newAnimation)
|
||||
{
|
||||
currentAnimation = newAnimation;
|
||||
animation[currentAnimation].currentFrame = 0;
|
||||
animation[currentAnimation].counter = 0;
|
||||
animation[currentAnimation].completed = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(int index)
|
||||
{
|
||||
const int newAnimation = index;
|
||||
if (currentAnimation != newAnimation)
|
||||
{
|
||||
currentAnimation = newAnimation;
|
||||
animation[currentAnimation].currentFrame = 0;
|
||||
animation[currentAnimation].counter = 0;
|
||||
animation[currentAnimation].completed = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void AnimatedSprite::update()
|
||||
{
|
||||
animate();
|
||||
MovingSprite::update();
|
||||
}
|
||||
|
||||
// Establece el rectangulo para un frame de una animación
|
||||
void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
|
||||
{
|
||||
mAnimation[index_animation].frames[index_frame].x = x;
|
||||
mAnimation[index_animation].frames[index_frame].y = y;
|
||||
mAnimation[index_animation].frames[index_frame].w = w;
|
||||
mAnimation[index_animation].frames[index_frame].h = h;
|
||||
animation[index_animation].frames.push_back({x, y, w, h});
|
||||
}
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void AnimatedSprite::setAnimationSpeed(Uint8 index, Uint8 speed)
|
||||
// OLD - Establece el contador para todas las animaciones
|
||||
void AnimatedSprite::setAnimationCounter(int value)
|
||||
{
|
||||
mAnimation[index].speed = speed;
|
||||
}
|
||||
|
||||
// Establece el numero de frames de una animación
|
||||
void AnimatedSprite::setAnimationNumFrames(Uint8 index, Uint8 num)
|
||||
{
|
||||
mAnimation[index].numFrames = num;
|
||||
}
|
||||
|
||||
// Establece si la animación se reproduce en bucle
|
||||
void AnimatedSprite::setAnimationLoop(Uint8 index, bool loop)
|
||||
{
|
||||
mAnimation[index].loop = loop;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void AnimatedSprite::setCompleted(Uint8 index, bool value)
|
||||
{
|
||||
mAnimation[index].completed = value;
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool AnimatedSprite::isCompleted(Uint8 index)
|
||||
{
|
||||
return mAnimation[index].completed;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
SDL_Rect AnimatedSprite::getAnimationClip(Uint8 index_animation, Uint8 index_frame)
|
||||
{
|
||||
return mAnimation[index_animation].frames[index_frame];
|
||||
for (auto &a:animation)
|
||||
{
|
||||
a.counter = value;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +1,84 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "movingsprite.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#ifndef ANIMATEDSPRITE_H
|
||||
#define ANIMATEDSPRITE_H
|
||||
|
||||
#define MAX_FRAMES 30
|
||||
#define MAX_ANIMATIONS 20
|
||||
|
||||
// Clase AnimatedSprite
|
||||
class AnimatedSprite : public MovingSprite
|
||||
{
|
||||
private:
|
||||
struct sAnimation
|
||||
struct t_animation
|
||||
{
|
||||
SDL_Rect frames[MAX_FRAMES]; // Cada uno de los frames que componen la animación
|
||||
Uint8 numFrames; // Numero de frames que componen la animación
|
||||
Uint8 speed; // Velocidad de la animación
|
||||
bool loop; // Indica si la animación se reproduce en bucle
|
||||
bool completed; // Indica si ha finalizado la animación
|
||||
std::string name; // Nombre de la animacion
|
||||
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
|
||||
int speed; // Velocidad de la animación
|
||||
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
|
||||
bool completed; // Indica si ha finalizado la animación
|
||||
int currentFrame; // Frame actual
|
||||
int counter; // Contador para las animaciones
|
||||
};
|
||||
sAnimation mAnimation[MAX_ANIMATIONS]; // Vector con las diferentes animaciones
|
||||
|
||||
Uint8 mCurrentFrame; // Frame actual
|
||||
Uint16 mAnimationCounter; // Contador para las animaciones
|
||||
std::vector<t_animation> animation; // Vector con las diferentes animaciones
|
||||
int currentAnimation; // Animacion activa
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
AnimatedSprite();
|
||||
AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "");
|
||||
|
||||
// Destructor
|
||||
~AnimatedSprite();
|
||||
|
||||
// Iniciador
|
||||
void init(LTexture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Calcula el frame correspondiente a la animación
|
||||
void animate(int index);
|
||||
// Calcula el frame correspondiente a la animación actual
|
||||
void animate();
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
void setCurrentFrame(Uint8 num);
|
||||
void setCurrentFrame(int num);
|
||||
|
||||
// Establece el valor del contador
|
||||
void setAnimationCounter(Uint16 num);
|
||||
|
||||
// Establece el rectangulo para un frame de una animación
|
||||
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
||||
void setAnimationCounter(std::string name, int num);
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void setAnimationSpeed(Uint8 index, Uint8 speed);
|
||||
void setAnimationSpeed(std::string name, int speed);
|
||||
void setAnimationSpeed(int index, int speed);
|
||||
|
||||
// Establece el numero de frames de una animación
|
||||
void setAnimationNumFrames(Uint8 index, Uint8 num);
|
||||
|
||||
// Establece si la animación se reproduce en bucle
|
||||
void setAnimationLoop(Uint8 index, bool loop);
|
||||
// Establece el frame al que vuelve la animación al finalizar
|
||||
void setAnimationLoop(std::string name, int loop);
|
||||
void setAnimationLoop(int index, int loop);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setCompleted(Uint8 index, bool value);
|
||||
void setAnimationCompleted(std::string name, bool value);
|
||||
void setAnimationCompleted(int index, bool value);
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool isCompleted(Uint8 index);
|
||||
bool animationIsCompleted();
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
SDL_Rect getAnimationClip(Uint8 index_animation, Uint8 index_frame);
|
||||
SDL_Rect getAnimationClip(std::string name, Uint8 index);
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int getIndex(std::string name);
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
bool load(std::string filePath);
|
||||
|
||||
// Establece la animacion actual
|
||||
void setCurrentAnimation(std::string name = "default");
|
||||
void setCurrentAnimation(int index = 0);
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update();
|
||||
|
||||
// OLD - Establece el rectangulo para un frame de una animación
|
||||
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
||||
|
||||
// OLD - Establece el contador para todas las animaciones
|
||||
void setAnimationCounter(int value);
|
||||
};
|
||||
|
||||
#endif
|
||||
160
source/asset.cpp
Normal file
160
source/asset.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
#include "asset.h"
|
||||
|
||||
// Constructor
|
||||
Asset::Asset(std::string path)
|
||||
{
|
||||
executablePath = path;
|
||||
longest_name = 0;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Asset::~Asset()
|
||||
{
|
||||
}
|
||||
|
||||
// Añade un elemento a la lista
|
||||
void Asset::add(std::string file, enum assetType type, bool required)
|
||||
{
|
||||
item_t temp;
|
||||
temp.file = executablePath + file;
|
||||
temp.type = type;
|
||||
temp.required = required;
|
||||
fileList.push_back(temp);
|
||||
|
||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
||||
longest_name = SDL_max(longest_name, filename.size());
|
||||
}
|
||||
|
||||
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
||||
std::string Asset::get(std::string text)
|
||||
{
|
||||
for (auto f : fileList)
|
||||
{
|
||||
if (f.file.find(text) != std::string::npos)
|
||||
{
|
||||
return f.file;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Warning: file %s not found\n", text.c_str());
|
||||
return "";
|
||||
}
|
||||
|
||||
// Comprueba que existen todos los elementos
|
||||
bool Asset::check()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
printf("\n** Checking files.\n");
|
||||
|
||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||
for (int type = 0; type < maxAssetType; ++type)
|
||||
{
|
||||
// Comprueba si hay ficheros de ese tipo
|
||||
bool any = false;
|
||||
|
||||
for (auto f : fileList)
|
||||
{
|
||||
if ((f.required) && (f.type == type))
|
||||
{
|
||||
any = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Si hay ficheros de ese tipo, comprueba si existen
|
||||
if (any)
|
||||
{
|
||||
printf("\n>> %s FILES\n", getTypeName(type).c_str());
|
||||
|
||||
for (auto f : fileList)
|
||||
{
|
||||
if ((f.required) && (f.type == type))
|
||||
{
|
||||
success &= checkFile(f.file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resultado
|
||||
if (success)
|
||||
{
|
||||
printf("\n** All files OK.\n\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n** A file is missing. Exiting.\n\n");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Comprueba que existe un fichero
|
||||
bool Asset::checkFile(std::string path)
|
||||
{
|
||||
bool success = false;
|
||||
std::string result = "ERROR";
|
||||
|
||||
// Comprueba si existe el fichero
|
||||
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(path.c_str(), "r+b");
|
||||
|
||||
if (file != nullptr)
|
||||
{
|
||||
result = "OK";
|
||||
success = true;
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
|
||||
const std::string s = "Checking file %-" + std::to_string(longest_name) + "s [" + result + "]\n";
|
||||
printf(s.c_str(), filename.c_str());
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Devuelve el nombre del tipo de recurso
|
||||
std::string Asset::getTypeName(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case bitmap:
|
||||
return "BITMAP";
|
||||
break;
|
||||
|
||||
case music:
|
||||
return "MUSIC";
|
||||
break;
|
||||
|
||||
case sound:
|
||||
return "SOUND";
|
||||
break;
|
||||
|
||||
case font:
|
||||
return "FONT";
|
||||
break;
|
||||
|
||||
case lang:
|
||||
return "LANG";
|
||||
break;
|
||||
|
||||
case data:
|
||||
return "DATA";
|
||||
break;
|
||||
|
||||
case room:
|
||||
return "ROOM";
|
||||
break;
|
||||
|
||||
case enemy:
|
||||
return "ENEMY";
|
||||
break;
|
||||
|
||||
case item:
|
||||
return "ITEM";
|
||||
break;
|
||||
|
||||
default:
|
||||
return "ERROR";
|
||||
break;
|
||||
}
|
||||
}
|
||||
64
source/asset.h
Normal file
64
source/asset.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef ASSET_H
|
||||
#define ASSET_H
|
||||
|
||||
enum assetType
|
||||
{
|
||||
bitmap,
|
||||
music,
|
||||
sound,
|
||||
font,
|
||||
lang,
|
||||
data,
|
||||
room,
|
||||
enemy,
|
||||
item,
|
||||
maxAssetType
|
||||
};
|
||||
|
||||
// Clase Asset
|
||||
class Asset
|
||||
{
|
||||
private:
|
||||
// Estructura para definir un item
|
||||
struct item_t
|
||||
{
|
||||
std::string file; // Ruta del fichero desde la raiz del directorio
|
||||
enum assetType type; // Indica el tipo de recurso
|
||||
bool required; // Indica si es un fichero que debe de existir
|
||||
};
|
||||
|
||||
int longest_name; // Contiene la longitud del nombre de fichero mas largo
|
||||
|
||||
std::vector<item_t> fileList;
|
||||
std::string executablePath;
|
||||
|
||||
// Comprueba que existe un fichero
|
||||
bool checkFile(std::string path);
|
||||
|
||||
// Devuelve el nombre del tipo de recurso
|
||||
std::string getTypeName(int type);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Asset(std::string path);
|
||||
|
||||
// Destructor
|
||||
~Asset();
|
||||
|
||||
// Añade un elemento a la lista
|
||||
void add(std::string file, enum assetType type, bool required = true);
|
||||
|
||||
// Devuelve un elemento de la lista a partir de una cadena
|
||||
std::string get(std::string text);
|
||||
|
||||
// Comprueba que existen todos los elementos
|
||||
bool check();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -55,13 +55,19 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
||||
|
||||
// Establece los frames de cada animación
|
||||
for (int i = 0; i < NUM_FRAMES_BALLON; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUM_FRAMES_BALLON_POP; i++)
|
||||
{
|
||||
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -351,13 +357,16 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
||||
mPosX = x;
|
||||
mPosY = y;
|
||||
|
||||
mBouncing.enabled = false; // Si el efecto está activo
|
||||
mBouncing.counter = 0; // Countador para el efecto
|
||||
mBouncing.speed = 0; // Velocidad a la que transcurre el efecto
|
||||
mBouncing.zoomW = 1.0f; // Zoom aplicado a la anchura
|
||||
mBouncing.zoomH = 1.0f; // Zoom aplicado a la altura
|
||||
mBouncing.despX = 0.0f; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
|
||||
// Valores para el efecto de rebote
|
||||
mBouncing.enabled = false;
|
||||
mBouncing.counter = 0;
|
||||
mBouncing.speed = 0;
|
||||
mBouncing.zoomW = 1.0f;
|
||||
mBouncing.zoomH = 1.0f;
|
||||
mBouncing.despX = 0.0f;
|
||||
mBouncing.despY = 0.0f;
|
||||
mBouncing.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
|
||||
mBouncing.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
|
||||
|
||||
// Textura con los gráficos del sprite
|
||||
mSprite->setTexture(texture);
|
||||
@@ -404,13 +413,13 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
||||
mKind = kind;
|
||||
|
||||
// Inicializa las variables para la animación
|
||||
mSprite->setCurrentFrame(0);
|
||||
mSprite->setAnimationCounter(0);
|
||||
// mSprite->setCurrentFrame(0);
|
||||
// mSprite->setAnimationCounter(0);
|
||||
|
||||
// Establece el numero de frames de cada animacion
|
||||
mSprite->setAnimationNumFrames(BALLOON_MOVING_ANIMATION, NUM_FRAMES_BALLON);
|
||||
mSprite->setAnimationNumFrames(BALLOON_POP_ANIMATION, NUM_FRAMES_BALLON_POP);
|
||||
mSprite->setAnimationNumFrames(BALLOON_BORN_ANIMATION, NUM_FRAMES_BALLON_BORN);
|
||||
// mSprite->setAnimationNumFrames(BALLOON_MOVING_ANIMATION, NUM_FRAMES_BALLON);
|
||||
// mSprite->setAnimationNumFrames(BALLOON_POP_ANIMATION, NUM_FRAMES_BALLON_POP);
|
||||
// mSprite->setAnimationNumFrames(BALLOON_BORN_ANIMATION, NUM_FRAMES_BALLON_BORN);
|
||||
|
||||
// Establece la velocidad de cada animación
|
||||
mSprite->setAnimationSpeed(BALLOON_MOVING_ANIMATION, 10);
|
||||
@@ -432,13 +441,9 @@ void Balloon::allignTo(int x)
|
||||
mPosX = float(x - (mWidth / 2));
|
||||
|
||||
if (mPosX < PLAY_AREA_LEFT)
|
||||
{
|
||||
mPosX = PLAY_AREA_LEFT + 1;
|
||||
}
|
||||
else if ((mPosX + mWidth) > PLAY_AREA_RIGHT)
|
||||
{
|
||||
mPosX = float(PLAY_AREA_RIGHT - mWidth - 1);
|
||||
}
|
||||
|
||||
// Posición X,Y del sprite
|
||||
mSprite->setPosX(getPosX());
|
||||
@@ -531,10 +536,12 @@ void Balloon::move()
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Para aplicar la gravedad, el diseño original la aplicaba en cada iteración del bucle
|
||||
Al añadir el modificador de velocidad se reduce la distancia que recorre el objeto y por
|
||||
tanto recibe mas gravedad. Para solucionarlo se va a aplicar la gravedad cuando se haya
|
||||
recorrido una distancia igual a la velocidad en Y, que era el cálculo inicial
|
||||
|
||||
*/
|
||||
|
||||
// Incrementa la variable que calcula la distancia acumulada en Y
|
||||
@@ -550,11 +557,6 @@ void Balloon::move()
|
||||
mVelY += mGravity;
|
||||
std::min(mVelY, mMaxVelY);
|
||||
}
|
||||
// Aplica la gravedad al objeto
|
||||
//if (mVelY > mMaxVelY)
|
||||
// mVelY = mMaxVelY;
|
||||
//else if (mCounter % 1 == 0)
|
||||
// mVelY += mGravity;
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
mSprite->setPosX(getPosX());
|
||||
@@ -603,7 +605,7 @@ void Balloon::disable()
|
||||
void Balloon::pop()
|
||||
{
|
||||
setPopping(true);
|
||||
mSprite->setAnimationCounter(0);
|
||||
mSprite->setAnimationCounter(0);
|
||||
mSprite->disableRotate();
|
||||
setTimeToLive(120);
|
||||
setStop(true);
|
||||
@@ -635,9 +637,9 @@ void Balloon::updateState()
|
||||
{
|
||||
setInvulnerable(true);
|
||||
setStop(true);
|
||||
if (mSprite->isCompleted(BALLOON_POP_ANIMATION))
|
||||
if (mSprite->animationIsCompleted())
|
||||
{
|
||||
mSprite->setCompleted(BALLOON_POP_ANIMATION, false);
|
||||
mSprite->setAnimationCompleted(BALLOON_POP_ANIMATION, false);
|
||||
mTimeToLive = 0;
|
||||
disable();
|
||||
}
|
||||
@@ -679,12 +681,6 @@ void Balloon::updateState()
|
||||
updateColliders();
|
||||
}
|
||||
|
||||
// Hace visible el globo de forma intermitente
|
||||
//if (mCreationCounter > 100)
|
||||
// setVisible(mCreationCounter / 10 % 2 == 0);
|
||||
//else
|
||||
// setVisible(mCreationCounter / 5 % 2 == 0);
|
||||
|
||||
mCreationCounter--;
|
||||
}
|
||||
// El contador ha llegado a cero
|
||||
@@ -709,10 +705,14 @@ void Balloon::updateState()
|
||||
{
|
||||
// Si está detenido, reduce el contador
|
||||
if (mStoppedCounter > 0)
|
||||
{
|
||||
mStoppedCounter--;
|
||||
}
|
||||
// Si el contador ha llegado a cero, ya no está detenido
|
||||
else if (!isPopping()) // Quitarles el estado "detenido" si no estan explosionandoxq
|
||||
else if (!isPopping())
|
||||
{ // Quitarles el estado "detenido" si no estan explosionando
|
||||
setStop(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,11 +721,19 @@ void Balloon::updateAnimation()
|
||||
{
|
||||
// Establece el frame de animación
|
||||
if (isPopping())
|
||||
mSprite->animate(BALLOON_POP_ANIMATION);
|
||||
{
|
||||
mSprite->setCurrentAnimation(BALLOON_POP_ANIMATION);
|
||||
}
|
||||
else if (isBeingCreated())
|
||||
mSprite->animate(BALLOON_BORN_ANIMATION);
|
||||
{
|
||||
mSprite->setCurrentAnimation(BALLOON_BORN_ANIMATION);
|
||||
}
|
||||
else
|
||||
mSprite->animate(BALLOON_MOVING_ANIMATION);
|
||||
{
|
||||
mSprite->setCurrentAnimation(BALLOON_MOVING_ANIMATION);
|
||||
}
|
||||
|
||||
mSprite->animate();
|
||||
}
|
||||
|
||||
// Comprueba si el globo está habilitado
|
||||
@@ -910,7 +918,6 @@ circle_t &Balloon::getCollider()
|
||||
// Alinea el circulo de colisión con la posición del objeto globo
|
||||
void Balloon::updateColliders()
|
||||
{
|
||||
// Align collider to center of balloon
|
||||
mCollider.x = Uint16(mPosX + mCollider.r);
|
||||
mCollider.y = mPosY + mCollider.r;
|
||||
}
|
||||
@@ -940,6 +947,7 @@ void Balloon::bounceStart()
|
||||
mBouncing.despX = 0;
|
||||
mBouncing.despY = 0;
|
||||
}
|
||||
|
||||
void Balloon::bounceStop()
|
||||
{
|
||||
mBouncing.enabled = false;
|
||||
@@ -951,6 +959,7 @@ void Balloon::bounceStop()
|
||||
mBouncing.despX = 0.0f;
|
||||
mBouncing.despY = 0.0f;
|
||||
}
|
||||
|
||||
void Balloon::updateBounce()
|
||||
{
|
||||
if (mBouncing.enabled)
|
||||
|
||||
124
source/balloon.h
124
source/balloon.h
@@ -1,16 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "animatedsprite.h"
|
||||
#include <vector>
|
||||
|
||||
#ifndef BALLOON_H
|
||||
#define BALLOON_H
|
||||
|
||||
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
||||
#define MAX_BOUNCE 10
|
||||
|
||||
// Clase globo
|
||||
// Tipos de globo
|
||||
#define BALLOON_1 1
|
||||
#define BALLOON_2 2
|
||||
#define BALLOON_3 3
|
||||
#define BALLOON_4 4
|
||||
#define HEXAGON_1 5
|
||||
#define HEXAGON_2 6
|
||||
#define HEXAGON_3 7
|
||||
#define HEXAGON_4 8
|
||||
#define POWER_BALL 9
|
||||
|
||||
// Puntos de globo
|
||||
#define BALLOON_SCORE_1 50
|
||||
#define BALLOON_SCORE_2 100
|
||||
#define BALLOON_SCORE_3 200
|
||||
#define BALLOON_SCORE_4 400
|
||||
|
||||
// Tamaños de globo
|
||||
#define BALLOON_SIZE_1 1
|
||||
#define BALLOON_SIZE_2 2
|
||||
#define BALLOON_SIZE_3 3
|
||||
#define BALLOON_SIZE_4 4
|
||||
|
||||
// Clases de globo
|
||||
#define BALLOON_CLASS 0
|
||||
#define HEXAGON_CLASS 1
|
||||
|
||||
// Velocidad del globo
|
||||
#define BALLOON_VELX_POSITIVE 0.7f
|
||||
#define BALLOON_VELX_NEGATIVE -0.7f
|
||||
|
||||
// Indice para las animaciones de los globos
|
||||
#define BALLOON_MOVING_ANIMATION 0
|
||||
#define BALLOON_POP_ANIMATION 1
|
||||
#define BALLOON_BORN_ANIMATION 2
|
||||
|
||||
// Cantidad posible de globos
|
||||
#define MAX_BALLOONS 100
|
||||
|
||||
// Velocidades a las que se mueven los globos
|
||||
#define BALLOON_SPEED_1 0.60f
|
||||
#define BALLOON_SPEED_2 0.70f
|
||||
#define BALLOON_SPEED_3 0.80f
|
||||
#define BALLOON_SPEED_4 0.90f
|
||||
#define BALLOON_SPEED_5 1.00f
|
||||
|
||||
// Tamaño de los globos
|
||||
#define BALLOON_WIDTH_1 8
|
||||
#define BALLOON_WIDTH_2 13
|
||||
#define BALLOON_WIDTH_3 21
|
||||
#define BALLOON_WIDTH_4 37
|
||||
|
||||
// PowerBall
|
||||
#define POWERBALL_SCREENPOWER_MINIMUM 10
|
||||
#define POWERBALL_COUNTER 8
|
||||
|
||||
// Clase Balloon
|
||||
class Balloon
|
||||
{
|
||||
private:
|
||||
// Estructura para las variables para el efecto de los rebotes
|
||||
struct bouncing
|
||||
{
|
||||
bool enabled; // Si el efecto está activo
|
||||
Uint8 counter; // Countador para el efecto
|
||||
Uint8 speed; // Velocidad a la que transcurre el efecto
|
||||
float zoomW; // Zoom aplicado a la anchura
|
||||
float zoomH; // Zoom aplicado a la altura
|
||||
float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
|
||||
float despY; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom
|
||||
std::vector<float> w; // Vector con los valores de zoom para el ancho del globo
|
||||
std::vector<float> h; // Vector con los valores de zoom para el alto del globo
|
||||
};
|
||||
|
||||
float mPosX; // Posición en el eje X
|
||||
float mPosY; // Posición en el eje Y
|
||||
Uint8 mWidth; // Ancho
|
||||
@@ -41,32 +115,34 @@ private:
|
||||
float mSpeed; // Velocidad a la que se mueven los globos
|
||||
Uint8 mSize; // Tamaño del globo
|
||||
Uint8 mPower; // Cantidad de poder que alberga el globo
|
||||
bouncing mBouncing; // Contiene las variables para el efecto de rebote
|
||||
|
||||
struct bouncing // Estructura para las variables para el efecto de los rebotes
|
||||
{
|
||||
bool enabled; // Si el efecto está activo
|
||||
Uint8 counter; // Countador para el efecto
|
||||
Uint8 speed; // Velocidad a la que transcurre el efecto
|
||||
float zoomW; // Zoom aplicado a la anchura
|
||||
float zoomH; // Zoom aplicado a la altura
|
||||
float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
|
||||
float despY; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom
|
||||
// Alinea el circulo de colisión con la posición del objeto globo
|
||||
void updateColliders();
|
||||
|
||||
// Vector con los valores de zoom para el ancho y alto del globo
|
||||
float w[MAX_BOUNCE] = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
|
||||
float h[MAX_BOUNCE] = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
|
||||
};
|
||||
bouncing mBouncing;
|
||||
// Activa el efecto
|
||||
void bounceStart();
|
||||
|
||||
void updateColliders(); // Alinea el circulo de colisión con la posición del objeto globo
|
||||
void bounceStart(); // Activa el efecto
|
||||
void bounceStop(); // Detiene el efecto
|
||||
void updateBounce(); // Aplica el efecto
|
||||
void updateState(); // Actualiza los estados del globo
|
||||
void updateAnimation(); // Establece la animación correspondiente
|
||||
void setBeingCreated(bool state); // Establece el valor de la variable
|
||||
void setTimeToLive(Uint16 time); // Establece el valor de la variable
|
||||
Uint16 getTimeToLive(); // Obtiene del valor de la variable
|
||||
// Detiene el efecto
|
||||
void bounceStop();
|
||||
|
||||
// Aplica el efecto
|
||||
void updateBounce();
|
||||
|
||||
// Actualiza los estados del globo
|
||||
void updateState();
|
||||
|
||||
// Establece la animación correspondiente
|
||||
void updateAnimation();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setBeingCreated(bool state);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setTimeToLive(Uint16 time);
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
Uint16 getTimeToLive();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
|
||||
@@ -11,7 +11,6 @@ Bullet::Bullet()
|
||||
// Destructor
|
||||
Bullet::~Bullet()
|
||||
{
|
||||
//init(0, 0, NO_KIND, nullptr, nullptr);
|
||||
delete mSprite;
|
||||
mSprite = nullptr;
|
||||
}
|
||||
@@ -107,7 +106,7 @@ void Bullet::render()
|
||||
Uint8 Bullet::move()
|
||||
{
|
||||
// Variable con el valor de retorno
|
||||
Uint8 msg = MSG_OK;
|
||||
Uint8 msg = BULLET_MOVE_OK;
|
||||
|
||||
// Mueve el objeto a su nueva posición
|
||||
mPosX += mVelX;
|
||||
@@ -119,7 +118,7 @@ Uint8 Bullet::move()
|
||||
mKind = NO_KIND;
|
||||
|
||||
// Mensaje de salida
|
||||
msg = MSG_BULLET_OUT;
|
||||
msg = BULLET_MOVE_OUT;
|
||||
}
|
||||
|
||||
// Mueve el objeto a su nueva posición en vertical
|
||||
@@ -132,7 +131,7 @@ Uint8 Bullet::move()
|
||||
mKind = NO_KIND;
|
||||
|
||||
// Mensaje de salida
|
||||
msg = MSG_BULLET_OUT;
|
||||
msg = BULLET_MOVE_OUT;
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
@@ -145,18 +144,6 @@ Uint8 Bullet::move()
|
||||
return msg;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
void Bullet::testMove()
|
||||
{
|
||||
// Update sprite position
|
||||
mSprite->setPosX(mPosX);
|
||||
mSprite->setPosY(mPosY);
|
||||
|
||||
// Update circle colliders
|
||||
shiftColliders();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Deshabilita el objeto
|
||||
void Bullet::erase()
|
||||
{
|
||||
@@ -167,13 +154,9 @@ void Bullet::erase()
|
||||
bool Bullet::isActive()
|
||||
{
|
||||
if (mKind == NO_KIND)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "sprite.h"
|
||||
|
||||
#ifndef BULLET_H
|
||||
#define BULLET_H
|
||||
|
||||
// Clase bala
|
||||
// Tipos de bala
|
||||
#define BULLET_UP 1
|
||||
#define BULLET_LEFT 2
|
||||
#define BULLET_RIGHT 3
|
||||
|
||||
// Tipos de retorno de la funcion move de la bala
|
||||
#define BULLET_MOVE_OK 0
|
||||
#define BULLET_MOVE_OUT 1
|
||||
|
||||
// Clase Bullet
|
||||
class Bullet
|
||||
{
|
||||
private:
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "sprite.h"
|
||||
|
||||
#ifndef COFFEEDROP_H
|
||||
|
||||
296
source/const.h
296
source/const.h
@@ -1,85 +1,19 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "lang.h"
|
||||
#include <string>
|
||||
|
||||
#ifndef CONST_H
|
||||
#define CONST_H
|
||||
|
||||
// Textos
|
||||
#define WINDOW_CAPTION "Coffee Crisis"
|
||||
#define TEXT_COPYRIGHT "@2020,2021 JailDesigner (v2.0.1)"
|
||||
|
||||
// Recursos
|
||||
#define BINFILE_SCORE 0
|
||||
#define BINFILE_DEMO 1
|
||||
#define BINFILE_CONFIG 2
|
||||
|
||||
#define TOTAL_BINFILE 3
|
||||
|
||||
#define MUSIC_INTRO 0
|
||||
#define MUSIC_PLAYING 1
|
||||
#define MUSIC_TITLE 2
|
||||
|
||||
#define TOTAL_MUSIC 3
|
||||
|
||||
#define SOUND_BALLOON 0
|
||||
#define SOUND_BUBBLE1 1
|
||||
#define SOUND_BUBBLE2 2
|
||||
#define SOUND_BUBBLE3 3
|
||||
#define SOUND_BUBBLE4 4
|
||||
#define SOUND_BULLET 5
|
||||
#define SOUND_COFFEE_OUT 6
|
||||
#define SOUND_HISCORE 7
|
||||
#define SOUND_ITEM_DROP 8
|
||||
#define SOUND_ITEM_PICKUP 9
|
||||
#define SOUND_MENU_CANCEL 10
|
||||
#define SOUND_MENU_MOVE 11
|
||||
#define SOUND_MENU_SELECT 12
|
||||
#define SOUND_PLAYER_COLLISION 13
|
||||
#define SOUND_STAGE_CHANGE 14
|
||||
#define SOUND_TITLE 15
|
||||
#define SOUND_CLOCK 16
|
||||
#define SOUND_POWERBALL 17
|
||||
|
||||
#define TOTAL_SOUND 18
|
||||
|
||||
#define TEXTURE_BALLOON 0
|
||||
#define TEXTURE_BULLET 1
|
||||
#define TEXTURE_FONT_BLACK 2
|
||||
#define TEXTURE_FONT_BLACK_X2 3
|
||||
#define TEXTURE_FONT_NOKIA 4
|
||||
#define TEXTURE_FONT_WHITE 5
|
||||
#define TEXTURE_FONT_WHITE_X2 6
|
||||
#define TEXTURE_GAME_BG 7
|
||||
#define TEXTURE_GAME_TEXT 8
|
||||
#define TEXTURE_INTRO 9
|
||||
#define TEXTURE_ITEMS 10
|
||||
#define TEXTURE_LOGO 11
|
||||
#define TEXTURE_MENU 12
|
||||
#define TEXTURE_PLAYER_BODY 13
|
||||
#define TEXTURE_PLAYER_DEATH 14
|
||||
#define TEXTURE_PLAYER_LEGS 15
|
||||
#define TEXTURE_TITLE 16
|
||||
|
||||
#define TOTAL_TEXTURE 17
|
||||
|
||||
// Tamaño de bloque
|
||||
#define BLOCK 8
|
||||
#define HALF_BLOCK BLOCK / 2
|
||||
|
||||
// Tamaño de la pantalla real
|
||||
// Tamaño de la pantalla de juego
|
||||
#define SCREEN_WIDTH 256
|
||||
const int SCREEN_HEIGHT = SCREEN_WIDTH * 3 / 4;
|
||||
|
||||
// Tamaño de la pantalla que se muestra
|
||||
const int VIEW_WIDTH = SCREEN_WIDTH * 3;
|
||||
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3;
|
||||
|
||||
// Cantidad de enteros a escribir en los ficheros de datos
|
||||
#define TOTAL_SCORE_DATA 3
|
||||
#define TOTAL_DEMO_DATA 2000
|
||||
#define SCREEN_HEIGHT 192
|
||||
|
||||
// Zona de juego
|
||||
const int PLAY_AREA_TOP = (0 * BLOCK);
|
||||
@@ -103,48 +37,6 @@ const int SCREEN_CENTER_Y = SCREEN_HEIGHT / 2;
|
||||
const int SCREEN_FIRST_QUARTER_Y = SCREEN_HEIGHT / 4;
|
||||
const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
|
||||
|
||||
// Opciones de menu
|
||||
#define MENU_NO_OPTION -1
|
||||
#define MENU_OPTION_START 0
|
||||
#define MENU_OPTION_QUIT 1
|
||||
#define MENU_OPTION_TOTAL 2
|
||||
|
||||
// Tipos de fondos para el menu
|
||||
#define MENU_BACKGROUND_TRANSPARENT 0
|
||||
#define MENU_BACKGROUND_SOLID 1
|
||||
|
||||
// Estados del jugador
|
||||
#define PLAYER_STATUS_WALKING_LEFT 0
|
||||
#define PLAYER_STATUS_WALKING_RIGHT 1
|
||||
#define PLAYER_STATUS_WALKING_STOP 2
|
||||
|
||||
#define PLAYER_STATUS_FIRING_UP 0
|
||||
#define PLAYER_STATUS_FIRING_LEFT 1
|
||||
#define PLAYER_STATUS_FIRING_RIGHT 2
|
||||
#define PLAYER_STATUS_FIRING_NO 3
|
||||
|
||||
#define PLAYER_ANIMATION_LEGS_WALKING_LEFT 0
|
||||
#define PLAYER_ANIMATION_LEGS_WALKING_RIGHT 1
|
||||
#define PLAYER_ANIMATION_LEGS_WALKING_STOP 2
|
||||
|
||||
#define PLAYER_ANIMATION_BODY_WALKING_LEFT 0
|
||||
#define PLAYER_ANIMATION_BODY_FIRING_LEFT 1
|
||||
#define PLAYER_ANIMATION_BODY_WALKING_RIGHT 2
|
||||
#define PLAYER_ANIMATION_BODY_FIRING_RIGHT 3
|
||||
#define PLAYER_ANIMATION_BODY_WALKING_STOP 4
|
||||
#define PLAYER_ANIMATION_BODY_FIRING_UP 5
|
||||
|
||||
#define PLAYER_ANIMATION_HEAD_WALKING_LEFT 0
|
||||
#define PLAYER_ANIMATION_HEAD_FIRING_LEFT 1
|
||||
#define PLAYER_ANIMATION_HEAD_WALKING_RIGHT 2
|
||||
#define PLAYER_ANIMATION_HEAD_FIRING_RIGHT 3
|
||||
#define PLAYER_ANIMATION_HEAD_WALKING_STOP 4
|
||||
#define PLAYER_ANIMATION_HEAD_FIRING_UP 5
|
||||
|
||||
// Variables del jugador
|
||||
#define PLAYER_INVULNERABLE_COUNTER 200
|
||||
#define PLAYER_POWERUP_COUNTER 1500
|
||||
|
||||
// Secciones del programa
|
||||
#define PROG_SECTION_LOGO 0
|
||||
#define PROG_SECTION_INTRO 1
|
||||
@@ -162,197 +54,17 @@ const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
|
||||
#define TITLE_SECTION_3 5
|
||||
#define TITLE_SECTION_INSTRUCTIONS 6
|
||||
|
||||
// Modo para las instrucciones
|
||||
#define INSTRUCTIONS_MODE_MANUAL 0
|
||||
#define INSTRUCTIONS_MODE_AUTO 1
|
||||
|
||||
// Estados de cada elemento que pertenece a un evento
|
||||
#define EVENT_WAITING 1
|
||||
#define EVENT_RUNNING 2
|
||||
#define EVENT_COMPLETED 3
|
||||
|
||||
// Cantidad de eventos de la intro
|
||||
#define INTRO_TOTAL_BITMAPS 6
|
||||
#define INTRO_TOTAL_TEXTS 9
|
||||
const int INTRO_TOTAL_EVENTS = INTRO_TOTAL_BITMAPS + INTRO_TOTAL_TEXTS;
|
||||
|
||||
// Cantidad de eventos de la pantalla de titulo
|
||||
#define TITLE_TOTAL_EVENTS 2
|
||||
|
||||
// Relaciones de Id con nomnbres
|
||||
#define BITMAP0 0
|
||||
#define BITMAP1 1
|
||||
#define BITMAP2 2
|
||||
#define BITMAP3 3
|
||||
#define BITMAP4 4
|
||||
#define BITMAP5 5
|
||||
#define TEXT0 6
|
||||
#define TEXT1 7
|
||||
#define TEXT2 8
|
||||
#define TEXT3 9
|
||||
#define TEXT4 10
|
||||
#define TEXT5 11
|
||||
#define TEXT6 12
|
||||
#define TEXT7 13
|
||||
#define TEXT8 14
|
||||
|
||||
// Anclajes para el marcador de puntos
|
||||
const int SCORE_WORD_X = (SCREEN_WIDTH / 4) - ((5 * BLOCK) / 2);
|
||||
const int SCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
|
||||
const int SCORE_NUMBER_X = (SCREEN_WIDTH / 4) - ((6 * BLOCK) / 2);
|
||||
const int SCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
|
||||
|
||||
const int HISCORE_WORD_X = ((SCREEN_WIDTH / 4) * 3) - ((8 * BLOCK) / 2);
|
||||
const int HISCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
|
||||
const int HISCORE_NUMBER_X = ((SCREEN_WIDTH / 4) * 3) - ((6 * BLOCK) / 2);
|
||||
const int HISCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
|
||||
|
||||
const int MULTIPLIER_WORD_X = (SCREEN_WIDTH / 2) - ((4 * BLOCK) / 2);
|
||||
const int MULTIPLIER_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
|
||||
const int MULTIPLIER_NUMBER_X = (SCREEN_WIDTH / 2) - ((3 * BLOCK) / 2);
|
||||
const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
|
||||
|
||||
// Ningun tipo
|
||||
#define NO_KIND 0
|
||||
|
||||
// Tipos de globo
|
||||
#define BALLOON_1 1
|
||||
#define BALLOON_2 2
|
||||
#define BALLOON_3 3
|
||||
#define BALLOON_4 4
|
||||
#define HEXAGON_1 5
|
||||
#define HEXAGON_2 6
|
||||
#define HEXAGON_3 7
|
||||
#define HEXAGON_4 8
|
||||
#define POWER_BALL 9
|
||||
|
||||
// Puntos de globo
|
||||
#define BALLOON_SCORE_1 50
|
||||
#define BALLOON_SCORE_2 100
|
||||
#define BALLOON_SCORE_3 200
|
||||
#define BALLOON_SCORE_4 400
|
||||
|
||||
// Tamaños de globo
|
||||
#define BALLOON_SIZE_1 1
|
||||
#define BALLOON_SIZE_2 2
|
||||
#define BALLOON_SIZE_3 3
|
||||
#define BALLOON_SIZE_4 4
|
||||
|
||||
// Clases de globo
|
||||
#define BALLOON_CLASS 0
|
||||
#define HEXAGON_CLASS 1
|
||||
|
||||
// Velocidad del globo
|
||||
#define BALLOON_VELX_POSITIVE 0.7f
|
||||
#define BALLOON_VELX_NEGATIVE -0.7f
|
||||
|
||||
// Indice para las animaciones de los globos
|
||||
#define BALLOON_MOVING_ANIMATION 0
|
||||
#define BALLOON_POP_ANIMATION 1
|
||||
#define BALLOON_BORN_ANIMATION 2
|
||||
|
||||
// Cantidad posible de globos
|
||||
#define MAX_BALLOONS 100
|
||||
|
||||
// Velocidades a las que se mueven los enemigos
|
||||
#define BALLOON_SPEED_1 0.60f
|
||||
#define BALLOON_SPEED_2 0.70f
|
||||
#define BALLOON_SPEED_3 0.80f
|
||||
#define BALLOON_SPEED_4 0.90f
|
||||
#define BALLOON_SPEED_5 1.00f
|
||||
|
||||
// Tamaño de los globos
|
||||
#define BALLOON_WIDTH_1 8
|
||||
#define BALLOON_WIDTH_2 13
|
||||
#define BALLOON_WIDTH_3 21
|
||||
#define BALLOON_WIDTH_4 37
|
||||
|
||||
// PowerBall
|
||||
#define POWERBALL_SCREENPOWER_MINIMUM 10
|
||||
#define POWERBALL_COUNTER 8
|
||||
|
||||
// Tipos de bala
|
||||
#define BULLET_UP 1
|
||||
#define BULLET_LEFT 2
|
||||
#define BULLET_RIGHT 3
|
||||
|
||||
// Cantidad posible de globos
|
||||
#define MAX_BULLETS 50
|
||||
|
||||
// Tipos de objetos
|
||||
#define ITEM_POINTS_1_DISK 1
|
||||
#define ITEM_POINTS_2_GAVINA 2
|
||||
#define ITEM_POINTS_3_PACMAR 3
|
||||
#define ITEM_CLOCK 4
|
||||
#define ITEM_COFFEE 5
|
||||
#define ITEM_POWER_BALL 6
|
||||
#define ITEM_COFFEE_MACHINE 7
|
||||
|
||||
// Porcentaje de aparición de los objetos
|
||||
#define ITEM_POINTS_1_DISK_ODDS 10
|
||||
#define ITEM_POINTS_2_GAVINA_ODDS 6
|
||||
#define ITEM_POINTS_3_PACMAR_ODDS 3
|
||||
#define ITEM_CLOCK_ODDS 5
|
||||
#define ITEM_COFFEE_ODDS 5
|
||||
#define ITEM_POWER_BALL_ODDS 0
|
||||
#define ITEM_COFFEE_MACHINE_ODDS 4
|
||||
|
||||
// Cantidad de objetos simultaneos
|
||||
#define MAX_ITEMS 10
|
||||
|
||||
// Valores para las variables asociadas a los objetos
|
||||
#define REMAINING_EXPLOSIONS 3
|
||||
#define REMAINING_EXPLOSIONS_COUNTER 50
|
||||
#define TIME_STOPPED_COUNTER 300
|
||||
|
||||
// Estados de entrada
|
||||
#define NO_INPUT 0
|
||||
#define INPUT_FIRE_LEFT 7
|
||||
#define INPUT_FIRE_UP 8
|
||||
#define INPUT_FIRE_RIGHT 9
|
||||
#define INPUT_PAUSE 10
|
||||
|
||||
// Zona muerta del mando analógico
|
||||
#define JOYSTICK_DEAD_ZONE 8000
|
||||
|
||||
// Tipos de mensajes para el retorno de las funciones
|
||||
#define MSG_OK 0
|
||||
#define MSG_BULLET_OUT 1
|
||||
|
||||
// Tipos de texto
|
||||
#define TEXT_FIXED 0
|
||||
#define TEXT_VARIABLE 1
|
||||
|
||||
// Cantidad de elementos del vector de SmartSprites
|
||||
#define MAX_SMART_SPRITES 10
|
||||
|
||||
// Cantidad máxima de gotas de café
|
||||
#define MAX_COFFEE_DROPS 100
|
||||
|
||||
// Contadores
|
||||
#define TITLE_COUNTER 800
|
||||
#define STAGE_COUNTER 200
|
||||
#define INSTRUCTIONS_COUNTER 600
|
||||
#define DEATH_COUNTER 350
|
||||
#define SHAKE_COUNTER 10
|
||||
#define HELP_COUNTER 1000
|
||||
|
||||
// Colores
|
||||
const color_t bgColor = {0x27, 0x27, 0x36};
|
||||
const color_t noColor = {0xFF, 0xFF, 0xFF};
|
||||
const color_t shdwTxtColor = {0x43, 0x43, 0x4F};
|
||||
|
||||
// Formaciones enemigas
|
||||
#define NUMBER_OF_ENEMY_FORMATIONS 100
|
||||
#define MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION 50
|
||||
|
||||
// Dificultad del juego
|
||||
#define DIFFICULTY_EASY 0
|
||||
#define DIFFICULTY_NORMAL 1
|
||||
#define DIFFICULTY_HARD 2
|
||||
|
||||
// Tipo de filtro
|
||||
#define FILTER_NEAREST 0
|
||||
#define FILTER_LINEAL 1
|
||||
|
||||
#endif
|
||||
@@ -3,68 +3,43 @@
|
||||
#include "director.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#ifdef __MIPSEL__
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Director::Director(std::string path)
|
||||
{
|
||||
// Inicializa la ruta
|
||||
setExecutablePath(path);
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
mAsset = new Asset(path.substr(0, path.find_last_of("\\/")) + "../");
|
||||
|
||||
// Establece la lista de ficheros
|
||||
setFileList();
|
||||
|
||||
// Si falta algún fichero no inicies el programa
|
||||
Uint8 section = PROG_SECTION_LOGO;
|
||||
if (!checkFileList())
|
||||
if (!setFileList())
|
||||
{// Si falta algún fichero no inicies el programa
|
||||
section = PROG_SECTION_QUIT;
|
||||
}
|
||||
|
||||
// Inicializa el objeto de idioma
|
||||
mLang = new Lang(mFileList);
|
||||
// Crea el objeto de idioma
|
||||
mLang = new Lang(mAsset);
|
||||
|
||||
// Crea el puntero a la estructura y carga el fichero de configuración
|
||||
mOptions = new options_t;
|
||||
if (!loadConfigFile())
|
||||
{
|
||||
mOptions->fullScreenMode = 0;
|
||||
mOptions->windowSize = 3;
|
||||
mOptions->language = en_UK;
|
||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
mOptions->filter = FILTER_NEAREST;
|
||||
mOptions->vSync = true;
|
||||
}
|
||||
loadConfigFile();
|
||||
|
||||
// Crea los objetos
|
||||
mInput = new Input(mFileList[53]);
|
||||
mInput = new Input(mAsset->get("controllerdb.txt"));
|
||||
|
||||
// Inicializa SDL
|
||||
initSDL();
|
||||
|
||||
// Crea el objeto para dibujar en pantalla (Requiere initSDL)
|
||||
mScreen = new Screen(mWindow, mRenderer, mOptions);
|
||||
|
||||
// Inicializa JailAudio
|
||||
initJailAudio();
|
||||
|
||||
// Aplica las opciones
|
||||
SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
|
||||
SDL_SetWindowSize(mWindow, SCREEN_WIDTH * mOptions->windowSize, SCREEN_HEIGHT * mOptions->windowSize);
|
||||
mLang->setLang(mOptions->language);
|
||||
|
||||
#ifdef __MIPSEL__
|
||||
DIR *dir = opendir("/media/data/local/home/.coffee_crisis");
|
||||
if (dir)
|
||||
{
|
||||
closedir(dir);
|
||||
}
|
||||
else if (ENOENT == errno)
|
||||
{
|
||||
int status = mkdir("/media/data/local/home/.coffee_crisis", 755);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Inicializa el resto de variables
|
||||
init(section);
|
||||
}
|
||||
@@ -73,9 +48,15 @@ Director::~Director()
|
||||
{
|
||||
saveConfigFile();
|
||||
|
||||
delete mAsset;
|
||||
mAsset = nullptr;
|
||||
|
||||
delete mInput;
|
||||
mInput = nullptr;
|
||||
|
||||
delete mScreen;
|
||||
mScreen = nullptr;
|
||||
|
||||
delete mLang;
|
||||
mLang = nullptr;
|
||||
|
||||
@@ -107,15 +88,9 @@ void Director::init(Uint8 name)
|
||||
mInput->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
||||
mInput->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
|
||||
mInput->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
|
||||
#ifdef __MIPSEL__
|
||||
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_LSHIFT);
|
||||
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_SPACE);
|
||||
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_LCTRL);
|
||||
#else
|
||||
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
|
||||
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
|
||||
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
|
||||
#endif
|
||||
mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
|
||||
mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
|
||||
|
||||
@@ -145,8 +120,7 @@ bool Director::initSDL()
|
||||
bool success = true;
|
||||
|
||||
// Inicializa SDL
|
||||
//if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0)
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0)
|
||||
{
|
||||
printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError());
|
||||
success = false;
|
||||
@@ -156,15 +130,15 @@ bool Director::initSDL()
|
||||
// Inicia el generador de numeros aleatorios
|
||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
|
||||
// Establece el filtro de la textura a nearest
|
||||
// Establece el filtro de la textura
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(mOptions->filter).c_str()))
|
||||
{
|
||||
printf("Warning: Nearest texture filtering not enabled!\n");
|
||||
}
|
||||
|
||||
// Crea la ventana
|
||||
mWindow = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, VIEW_WIDTH, VIEW_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
if (mWindow == NULL)
|
||||
mWindow = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, mOptions->screenWidth * mOptions->windowSize, mOptions->screenHeight * mOptions->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
if (mWindow == nullptr)
|
||||
{
|
||||
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
success = false;
|
||||
@@ -177,7 +151,7 @@ bool Director::initSDL()
|
||||
else
|
||||
mRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED);
|
||||
|
||||
if (mRenderer == NULL)
|
||||
if (mRenderer == nullptr)
|
||||
{
|
||||
printf("Renderer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
success = false;
|
||||
@@ -188,7 +162,7 @@ bool Director::initSDL()
|
||||
SDL_SetRenderDrawColor(mRenderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
|
||||
// Establece el tamaño del buffer de renderizado
|
||||
SDL_RenderSetLogicalSize(mRenderer, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
SDL_RenderSetLogicalSize(mRenderer, mOptions->screenWidth, mOptions->screenHeight);
|
||||
|
||||
// Establece el modo de mezcla
|
||||
SDL_SetRenderDrawBlendMode(mRenderer, SDL_BLENDMODE_BLEND);
|
||||
@@ -201,22 +175,88 @@ bool Director::initSDL()
|
||||
}
|
||||
|
||||
// Crea el indice de ficheros
|
||||
void Director::setFileList()
|
||||
bool Director::setFileList()
|
||||
{
|
||||
// Ficheros binarios
|
||||
mAsset->add("data/score.bin", data, false);
|
||||
mAsset->add("data/demo.bin", data);
|
||||
mAsset->add("data/config.bin", data, false);
|
||||
|
||||
// Musicas
|
||||
mAsset->add("media/music/intro.ogg", music);
|
||||
mAsset->add("media/music/playing.ogg", music);
|
||||
mAsset->add("media/music/title.ogg", music);
|
||||
|
||||
// Sonidos
|
||||
mAsset->add("media/sound/balloon.wav", sound);
|
||||
mAsset->add("media/sound/bubble1.wav", sound);
|
||||
mAsset->add("media/sound/bubble2.wav", sound);
|
||||
mAsset->add("media/sound/bubble3.wav", sound);
|
||||
mAsset->add("media/sound/bubble4.wav", sound);
|
||||
mAsset->add("media/sound/bullet.wav", sound);
|
||||
mAsset->add("media/sound/coffeeout.wav", sound);
|
||||
mAsset->add("media/sound/hiscore.wav", sound);
|
||||
mAsset->add("media/sound/itemdrop.wav", sound);
|
||||
mAsset->add("media/sound/itempickup.wav", sound);
|
||||
mAsset->add("media/sound/menu_cancel.wav", sound);
|
||||
mAsset->add("media/sound/menu_move.wav", sound);
|
||||
mAsset->add("media/sound/menu_select.wav", sound);
|
||||
mAsset->add("media/sound/player_collision.wav", sound);
|
||||
mAsset->add("media/sound/stage_change.wav", sound);
|
||||
mAsset->add("media/sound/title.wav", sound);
|
||||
mAsset->add("media/sound/clock.wav", sound);
|
||||
mAsset->add("media/sound/powerball.wav", sound);
|
||||
|
||||
// Texturas
|
||||
mAsset->add("media/gfx/balloon.png", bitmap);
|
||||
mAsset->add("media/gfx/bullet.png", bitmap);
|
||||
mAsset->add("media/gfx/game_bg.png", bitmap);
|
||||
mAsset->add("media/gfx/game_text.png", bitmap);
|
||||
mAsset->add("media/gfx/intro.png", bitmap);
|
||||
mAsset->add("media/gfx/items.png", bitmap);
|
||||
mAsset->add("media/gfx/logo.png", bitmap);
|
||||
mAsset->add("media/gfx/player1_body.png", bitmap);
|
||||
mAsset->add("media/gfx/player1_death.png", bitmap);
|
||||
mAsset->add("media/gfx/player1_legs.png", bitmap);
|
||||
mAsset->add("media/gfx/title.png", bitmap);
|
||||
mAsset->add("media/gfx/player1_head.png", bitmap);
|
||||
mAsset->add("media/gfx/player2_body.png", bitmap);
|
||||
mAsset->add("media/gfx/player2_death.png", bitmap);
|
||||
mAsset->add("media/gfx/player2_legs.png", bitmap);
|
||||
mAsset->add("media/gfx/player2_head.png", bitmap);
|
||||
|
||||
// Fuentes
|
||||
mAsset->add("media/font/8bithud.png", font);
|
||||
mAsset->add("media/font/8bithud.txt", font);
|
||||
mAsset->add("media/font/nokia.png", font);
|
||||
mAsset->add("media/font/nokia_big2.png", font);
|
||||
mAsset->add("media/font/nokia.txt", font);
|
||||
mAsset->add("media/font/nokia2.png", font);
|
||||
mAsset->add("media/font/nokia2.txt", font);
|
||||
mAsset->add("media/font/nokia_big2.txt", font);
|
||||
mAsset->add("media/font/smb2_big.png", font);
|
||||
mAsset->add("media/font/smb2_big.txt", font);
|
||||
mAsset->add("media/font/smb2.png", font);
|
||||
mAsset->add("media/font/smb2.txt", font);
|
||||
|
||||
// Textos
|
||||
mAsset->add("media/lang/es_ES.txt", lang);
|
||||
mAsset->add("media/lang/en_UK.txt", lang);
|
||||
mAsset->add("media/lang/ba_BA.txt", lang);
|
||||
|
||||
// DATA
|
||||
mAsset->add("data/gamecontrollerdb.txt", data);
|
||||
|
||||
return mAsset->check();
|
||||
|
||||
// Inicializa el vector
|
||||
for (int i = 0; i < MAX_FILE_LIST; i++)
|
||||
/*for (int i = 0; i < MAX_FILE_LIST; i++)
|
||||
mFileList[i] = "";
|
||||
|
||||
// Ficheros binarios
|
||||
#ifdef __MIPSEL__
|
||||
mFileList[0] = "/media/data/local/home/.coffee_crisis/score.bin";
|
||||
mFileList[1] = "/media/data/local/home/.coffee_crisis/demo.bin";
|
||||
mFileList[2] = "/media/data/local/home/.coffee_crisis/config.bin";
|
||||
#else
|
||||
// Ficheros binarios
|
||||
mFileList[0] = mExecutablePath + "/" + "../data/score.bin";
|
||||
mFileList[1] = mExecutablePath + "/" + "../data/demo.bin";
|
||||
mFileList[2] = mExecutablePath + "/" + "../data/config.bin";
|
||||
#endif
|
||||
|
||||
// Musicas
|
||||
mFileList[3] = mExecutablePath + "/" + "../media/music/intro.ogg";
|
||||
@@ -282,69 +322,7 @@ void Director::setFileList()
|
||||
|
||||
// DATA
|
||||
mFileList[53] = mExecutablePath + "/" + "../data/gamecontrollerdb.txt";
|
||||
}
|
||||
|
||||
// Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada
|
||||
bool Director::checkFolder(std::string name, std::string path)
|
||||
{
|
||||
bool success = true;
|
||||
std::string p;
|
||||
std::string filename;
|
||||
SDL_RWops *file;
|
||||
|
||||
// Comprueba los ficheros de la carpeta
|
||||
printf("\n>> %s FILES\n", name.c_str());
|
||||
for (int i = 3; i < MAX_FILE_LIST; i++)
|
||||
{
|
||||
if (mFileList[i].find(path.c_str()) != std::string::npos)
|
||||
{
|
||||
p = mFileList[i].c_str();
|
||||
filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
if (file != NULL)
|
||||
{
|
||||
printf("Checking file %-20s [OK]\n", filename.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Checking file %-20s [ERROR]\n", filename.c_str());
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
// Comprueba que todos los ficheros existen
|
||||
bool Director::checkFileList()
|
||||
{
|
||||
bool success = true;
|
||||
printf("Checking files...\n");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("MUSIC", "/media/music/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("SOUND", "/media/sound/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("BITMAP", "/media/gfx/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("FONT", "/media/font/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("LANG", "/media/lang/");
|
||||
|
||||
// Resultado
|
||||
if (success)
|
||||
printf("\n** All files OK.\n\n");
|
||||
else
|
||||
printf("\n** A file is missing. Exiting.\n\n");
|
||||
|
||||
return success;
|
||||
*/
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
@@ -353,28 +331,32 @@ bool Director::loadConfigFile()
|
||||
// Pone unos valores por defecto
|
||||
mOptions->fullScreenMode = 0;
|
||||
mOptions->windowSize = 3;
|
||||
mOptions->language = en_UK;
|
||||
mOptions->language = ba_BA;
|
||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
mOptions->filter = FILTER_NEAREST;
|
||||
mOptions->vSync = true;
|
||||
mOptions->screenWidth = SCREEN_WIDTH;
|
||||
mOptions->screenHeight = SCREEN_HEIGHT;
|
||||
mOptions->integerScale = true;
|
||||
mOptions->keepAspect = true;
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
|
||||
const std::string p = mFileList[2];
|
||||
const std::string p = mAsset->get("config.bin");
|
||||
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
|
||||
// El fichero no existe
|
||||
if (file == NULL)
|
||||
if (file == nullptr)
|
||||
{
|
||||
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||
|
||||
// Crea el fichero para escritura
|
||||
file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
if (file != NULL)
|
||||
if (file != nullptr)
|
||||
{
|
||||
printf("New file (%s) created!\n", filename.c_str());
|
||||
|
||||
@@ -387,6 +369,10 @@ bool Director::loadConfigFile()
|
||||
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||
SDL_RWwrite(file, &mOptions->keepAspect, sizeof(mOptions->keepAspect), 1);
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_RWclose(file);
|
||||
@@ -410,6 +396,10 @@ bool Director::loadConfigFile()
|
||||
SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||
SDL_RWread(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||
SDL_RWread(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||
SDL_RWread(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||
SDL_RWread(file, &mOptions->keepAspect, sizeof(mOptions->keepAspect), 1);
|
||||
|
||||
// Normaliza los valores
|
||||
if (!((mOptions->fullScreenMode == 0) ||
|
||||
@@ -432,10 +422,10 @@ bool Director::loadConfigFile()
|
||||
bool Director::saveConfigFile()
|
||||
{
|
||||
bool success = true;
|
||||
const std::string p = mFileList[2];
|
||||
const std::string p = mAsset->get("config.bin");
|
||||
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
if (file != NULL)
|
||||
if (file != nullptr)
|
||||
{
|
||||
// Guarda los datos
|
||||
SDL_RWwrite(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
||||
@@ -446,6 +436,10 @@ bool Director::saveConfigFile()
|
||||
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||
SDL_RWwrite(file, &mOptions->keepAspect, sizeof(mOptions->keepAspect), 1);
|
||||
|
||||
printf("Writing file %s\n", filename.c_str());
|
||||
|
||||
@@ -459,12 +453,6 @@ bool Director::saveConfigFile()
|
||||
return success;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Director::setExecutablePath(std::string path)
|
||||
{
|
||||
mExecutablePath = path.substr(0, path.find_last_of("\\/"));
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint8 Director::getSubsection()
|
||||
{
|
||||
@@ -485,21 +473,21 @@ void Director::setSection(section_t section)
|
||||
|
||||
void Director::runLogo()
|
||||
{
|
||||
mLogo = new Logo(mRenderer, mFileList);
|
||||
mLogo = new Logo(mRenderer, mScreen, mAsset);
|
||||
setSection(mLogo->run());
|
||||
delete mLogo;
|
||||
}
|
||||
|
||||
void Director::runIntro()
|
||||
{
|
||||
mIntro = new Intro(mRenderer, mFileList, mLang);
|
||||
mIntro = new Intro(mRenderer, mScreen, mAsset, mLang);
|
||||
setSection(mIntro->run());
|
||||
delete mIntro;
|
||||
}
|
||||
|
||||
void Director::runTitle()
|
||||
{
|
||||
mTitle = new Title(mWindow, mRenderer, mInput, mFileList, mOptions, mLang);
|
||||
mTitle = new Title(mWindow, mRenderer, mScreen, mInput, mAsset, mOptions, mLang);
|
||||
setSection(mTitle->run(mSection.subsection));
|
||||
delete mTitle;
|
||||
}
|
||||
@@ -507,9 +495,15 @@ void Director::runTitle()
|
||||
void Director::runGame()
|
||||
{
|
||||
if (mSection.subsection == GAME_SECTION_PLAY_1P)
|
||||
mGame = new Game(1, mRenderer, mFileList, mLang, mInput, false, mOptions);
|
||||
if (mSection.subsection == GAME_SECTION_PLAY_2P)
|
||||
mGame = new Game(2, mRenderer, mFileList, mLang, mInput, false, mOptions);
|
||||
{
|
||||
mGame = new Game(1, 0, mRenderer, mScreen, mAsset, mLang, mInput, false, mOptions);
|
||||
}
|
||||
|
||||
else if (mSection.subsection == GAME_SECTION_PLAY_2P)
|
||||
{
|
||||
mGame = new Game(2, 0, mRenderer, mScreen, mAsset, mLang, mInput, false, mOptions);
|
||||
}
|
||||
|
||||
setSection(mGame->run());
|
||||
delete mGame;
|
||||
}
|
||||
@@ -524,12 +518,15 @@ void Director::run()
|
||||
case PROG_SECTION_LOGO:
|
||||
runLogo();
|
||||
break;
|
||||
|
||||
case PROG_SECTION_INTRO:
|
||||
runIntro();
|
||||
break;
|
||||
|
||||
case PROG_SECTION_TITLE:
|
||||
runTitle();
|
||||
break;
|
||||
|
||||
case PROG_SECTION_GAME:
|
||||
runGame();
|
||||
break;
|
||||
|
||||
@@ -1,49 +1,50 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
#include "sprite.h"
|
||||
#include "movingsprite.h"
|
||||
#include "smartsprite.h"
|
||||
#include "player.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include "balloon.h"
|
||||
#include "bullet.h"
|
||||
#include "coffeedrop.h"
|
||||
#include "item.h"
|
||||
#include "text.h"
|
||||
#include "writer.h"
|
||||
#include "menu.h"
|
||||
#include "const.h"
|
||||
#include "jail_audio.h"
|
||||
#include "utils.h"
|
||||
#include "logo.h"
|
||||
#include "intro.h"
|
||||
#include "title.h"
|
||||
#include "fade.h"
|
||||
#include "game.h"
|
||||
#include "input.h"
|
||||
#include "fade.h"
|
||||
//#include <math.h>
|
||||
#include "intro.h"
|
||||
#include "item.h"
|
||||
#include "jail_audio.h"
|
||||
#include "logo.h"
|
||||
#include "menu.h"
|
||||
#include "movingsprite.h"
|
||||
#include "player.h"
|
||||
#include "screen.h"
|
||||
#include "smartsprite.h"
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "title.h"
|
||||
#include "utils.h"
|
||||
#include "writer.h"
|
||||
|
||||
#ifndef DIRECTOR_H
|
||||
#define DIRECTOR_H
|
||||
|
||||
#define MAX_FILE_LIST 100
|
||||
// Textos
|
||||
#define WINDOW_CAPTION "Coffee Crisis"
|
||||
|
||||
// Director
|
||||
// Clase Director
|
||||
class Director
|
||||
{
|
||||
private:
|
||||
SDL_Window *mWindow; // La ventana donde dibujamos
|
||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||
|
||||
Logo *mLogo; // Objeto para la sección del logo
|
||||
Intro *mIntro; // Objeto para la sección de la intro
|
||||
Title *mTitle; // Objeto para la sección del titulo y el menu de opciones
|
||||
Game *mGame; // Objeto para la sección del juego
|
||||
Input *mInput; // Objeto Input para gestionar las entradas
|
||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
|
||||
std::string mFileList[MAX_FILE_LIST]; // Vector con las rutas a los ficheros de recursos
|
||||
struct options_t *mOptions; // Variable con todas las opciones del programa
|
||||
|
||||
SDL_Window *mWindow; // La ventana donde dibujamos
|
||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
||||
Logo *mLogo; // Objeto para la sección del logo
|
||||
Intro *mIntro; // Objeto para la sección de la intro
|
||||
Title *mTitle; // Objeto para la sección del titulo y el menu de opciones
|
||||
Game *mGame; // Objeto para la sección del juego
|
||||
Input *mInput; // Objeto Input para gestionar las entradas
|
||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||
struct options_t *mOptions; // Variable con todas las opciones del programa
|
||||
std::string mExecutablePath; // Path del ejecutable
|
||||
section_t mSection; // Sección y subsección actual del programa;
|
||||
|
||||
@@ -54,10 +55,7 @@ private:
|
||||
bool initSDL();
|
||||
|
||||
// Crea el indice de ficheros
|
||||
void setFileList();
|
||||
|
||||
// Comprueba que todos los ficheros existen
|
||||
bool checkFileList();
|
||||
bool setFileList();
|
||||
|
||||
// Carga el fichero de configuración
|
||||
bool loadConfigFile();
|
||||
@@ -65,9 +63,6 @@ private:
|
||||
// Guarda el fichero de configuración
|
||||
bool saveConfigFile();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setExecutablePath(std::string path);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint8 getSubsection();
|
||||
|
||||
@@ -89,9 +84,6 @@ private:
|
||||
// Ejecuta la seccion de juego donde se juega
|
||||
void runGame();
|
||||
|
||||
// Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada
|
||||
bool checkFolder(std::string name, std::string path);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Director(std::string path);
|
||||
|
||||
@@ -7,7 +7,7 @@ Fade::Fade(SDL_Renderer *renderer)
|
||||
mRenderer = renderer;
|
||||
|
||||
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
if (mBackbuffer == NULL)
|
||||
if (mBackbuffer == nullptr)
|
||||
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@ void Fade::init(Uint8 r, Uint8 g, Uint8 b)
|
||||
mEnabled = false;
|
||||
mFinished = false;
|
||||
mCounter = 0;
|
||||
//mR = 0x27;
|
||||
//mG = 0x27;
|
||||
//mB = 0x36;
|
||||
mR = r;
|
||||
mG = g;
|
||||
mB = b;
|
||||
@@ -46,10 +43,10 @@ void Fade::render()
|
||||
for (int i = 0; i < 256; i += 4)
|
||||
{
|
||||
// Dibujamos sobre el renderizador
|
||||
SDL_SetRenderTarget(mRenderer, NULL);
|
||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||
|
||||
// Copia el backbuffer con la imagen que había al renderizador
|
||||
SDL_RenderCopy(mRenderer, mBackbuffer, NULL, NULL);
|
||||
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, nullptr);
|
||||
|
||||
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, i);
|
||||
SDL_RenderFillRect(mRenderer, &mRect1);
|
||||
@@ -63,7 +60,7 @@ void Fade::render()
|
||||
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 255);
|
||||
SDL_RenderClear(mRenderer);
|
||||
|
||||
SDL_SetRenderTarget(mRenderer, NULL);
|
||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 255);
|
||||
SDL_RenderClear(mRenderer);
|
||||
break;
|
||||
@@ -106,10 +103,10 @@ void Fade::render()
|
||||
SDL_RenderFillRect(mRenderer, &mRect1);
|
||||
|
||||
// Volvemos a usar el renderizador de forma normal
|
||||
SDL_SetRenderTarget(mRenderer, NULL);
|
||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||
|
||||
// Copiamos el backbuffer al renderizador
|
||||
SDL_RenderCopy(mRenderer, mBackbuffer, NULL, NULL);
|
||||
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, nullptr);
|
||||
|
||||
// Volcamos el renderizador en pantalla
|
||||
SDL_RenderPresent(mRenderer);
|
||||
@@ -121,7 +118,7 @@ void Fade::render()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mFinished)
|
||||
{
|
||||
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 255);
|
||||
@@ -153,16 +150,7 @@ bool Fade::isEnabled()
|
||||
// Comprueba si ha terminado la transicion
|
||||
bool Fade::hasEnded()
|
||||
{
|
||||
if (mFinished)
|
||||
{
|
||||
//mEnabled = false;
|
||||
//mFinished = false;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return mFinished;
|
||||
}
|
||||
|
||||
// Establece el tipo de fade
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "ltexture.h"
|
||||
|
||||
#ifndef FADE_H
|
||||
#define FADE_H
|
||||
|
||||
// Tipos de fundido
|
||||
#define FADE_FULLSCREEN 0
|
||||
#define FADE_CENTER 1
|
||||
#define FADE_RANDOM_SQUARE 2
|
||||
|
||||
// Fade
|
||||
// Clase Fade
|
||||
class Fade
|
||||
{
|
||||
private:
|
||||
|
||||
786
source/game.cpp
786
source/game.cpp
File diff suppressed because it is too large
Load Diff
206
source/game.h
206
source/game.h
@@ -1,28 +1,62 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
#include "const.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "sprite.h"
|
||||
#include "movingsprite.h"
|
||||
#include "smartsprite.h"
|
||||
|
||||
#include "player.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include "balloon.h"
|
||||
#include "bullet.h"
|
||||
#include "item.h"
|
||||
|
||||
#include "text.h"
|
||||
#include "writer.h"
|
||||
#include "menu.h"
|
||||
#include "input.h"
|
||||
#include "const.h"
|
||||
#include "fade.h"
|
||||
#include "input.h"
|
||||
#include "item.h"
|
||||
#include "jail_audio.h"
|
||||
#include "menu.h"
|
||||
#include "movingsprite.h"
|
||||
#include "player.h"
|
||||
#include "screen.h"
|
||||
#include "smartsprite.h"
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "utils.h"
|
||||
#include "writer.h"
|
||||
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
// Game
|
||||
// Cantidad de elementos a escribir en los ficheros de datos
|
||||
#define TOTAL_SCORE_DATA 3
|
||||
#define TOTAL_DEMO_DATA 2000
|
||||
|
||||
// Contadores
|
||||
#define STAGE_COUNTER 200
|
||||
#define SHAKE_COUNTER 10
|
||||
#define HELP_COUNTER 1000
|
||||
|
||||
// Formaciones enemigas
|
||||
#define NUMBER_OF_ENEMY_FORMATIONS 100
|
||||
#define MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION 50
|
||||
|
||||
// Cantidad de elementos del vector de SmartSprites
|
||||
#define MAX_SMART_SPRITES 10
|
||||
|
||||
// Cantidad máxima posible de balas
|
||||
#define MAX_BULLETS 50
|
||||
|
||||
// Porcentaje de aparición de los objetos
|
||||
#define ITEM_POINTS_1_DISK_ODDS 10
|
||||
#define ITEM_POINTS_2_GAVINA_ODDS 6
|
||||
#define ITEM_POINTS_3_PACMAR_ODDS 3
|
||||
#define ITEM_CLOCK_ODDS 5
|
||||
#define ITEM_COFFEE_ODDS 5
|
||||
#define ITEM_POWER_BALL_ODDS 0
|
||||
#define ITEM_COFFEE_MACHINE_ODDS 4
|
||||
|
||||
// Cantidad de objetos simultaneos
|
||||
#define MAX_ITEMS 10
|
||||
|
||||
// Valores para las variables asociadas a los objetos
|
||||
#define TIME_STOPPED_COUNTER 300
|
||||
|
||||
// Clase Game
|
||||
class Game
|
||||
{
|
||||
private:
|
||||
@@ -40,13 +74,11 @@ private:
|
||||
Uint8 numberOfEnemies; // Cantidad de enemigos que forman la formación
|
||||
enemyInits_t init[MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación
|
||||
};
|
||||
enemyFormation_t mEnemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
|
||||
|
||||
struct enemyPool_t
|
||||
{
|
||||
enemyFormation_t *set[10]; // Conjunto de formaciones enemigas
|
||||
};
|
||||
enemyPool_t mEnemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||
|
||||
struct stage_t // Contiene todas las variables relacionadas con una fase
|
||||
{
|
||||
@@ -79,8 +111,26 @@ private:
|
||||
int itemCoffeeMachineOdds; // Probabilidad de aparición del objeto
|
||||
};
|
||||
|
||||
struct demo_t
|
||||
{
|
||||
bool enabled; // Indica si está activo el modo demo
|
||||
bool recording; // Indica si está activado el modo para grabar la demo
|
||||
Uint16 counter; // Contador para el modo demo
|
||||
demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo
|
||||
demoKeys_t dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo
|
||||
};
|
||||
|
||||
struct debug_t
|
||||
{
|
||||
bool enabled; // Indica si se va a mostrar la información de debug
|
||||
Uint8 enemySet; // Escoge el set enemigo a generar
|
||||
Uint8 gradR, gradG, gradB; // Colores RGB para modificar el color del gradiente de fondo
|
||||
float hudW, hudH; // Multiplica el tamaño del hud de debug;
|
||||
};
|
||||
|
||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||
std::string *mFileList; // Lista de ficheros con los recursos
|
||||
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
||||
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
|
||||
int mNumPlayers; // Numero de jugadores
|
||||
@@ -105,17 +155,12 @@ private:
|
||||
LTexture *mTexturePlayer2Body; // Textura para el cuerpo del jugador2
|
||||
LTexture *mTexturePlayer2Death; // Textura para la animación de muerte del jugador2
|
||||
LTexture *mTexturePlayer2Legs; // Textura para las piernas del jugador
|
||||
LTexture *mTextureText; // Textura para el texto del juego
|
||||
LTexture *mTextureTextScoreBoard; // Textura para el texto del marcador
|
||||
LTexture *mTextureTextBig; // Textura para el texto grande
|
||||
LTexture *mTextureTextNokia2; // Textura para la fuente de texto Nokia
|
||||
LTexture *mTextureTextNokiaBig2; // Textura para la fuente de texto Nokia grande
|
||||
|
||||
Text *mText; // Fuente para los textos del juego
|
||||
Text *mTextBig; // Fuente de texto grande
|
||||
Text *mTextScoreBoard; // Fuente para el marcador del juego
|
||||
Text *mTextNokia2; // Otra fuente de texto para mesajes
|
||||
Text *mTextNokiaBig2; // Y la versión en grande
|
||||
Text *mTextNokiaBig2; // Y la versión en grande
|
||||
|
||||
Menu *mMenuGameOver; // Menú de la pantalla de game over
|
||||
Menu *mMenuPause; // Menú de la pantalla de pausa
|
||||
@@ -158,63 +203,47 @@ private:
|
||||
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
|
||||
Uint32 mHiScore; // Puntuación máxima
|
||||
bool mHiScoreAchieved; // Indica si se ha superado la puntuación máxima
|
||||
section_t mSection; // Seccion actual dentro del juego
|
||||
stage_t mStage[10]; // Variable con los datos de cada pantalla
|
||||
Uint8 mCurrentStage; // Indica la fase actual
|
||||
Uint8 mStageBitmapCounter; // Contador para el tiempo visible del texto de Stage
|
||||
float mStageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto
|
||||
float mGetReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
|
||||
Uint16 mDeathCounter; // Contador para la animación de muerte del jugador
|
||||
Uint8 mDeathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador
|
||||
Uint8 mMenaceCurrent; // Nivel de amenaza actual
|
||||
Uint8 mMenaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos
|
||||
bool mTimeStopped; // Indica si el tiempo está detenido
|
||||
Uint16 mTimeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido
|
||||
Uint8 mRemainingExplosions; // Cantidad de explosiones restantes
|
||||
Uint16 mRemainingExplosionsCounter; // Temporizador para la cantidad de explosiones restantes
|
||||
bool mExplosionTime; // Indica si las explosiones estan en marcha
|
||||
Uint32 mCounter; // Contador para el juego
|
||||
Uint32 mScoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos
|
||||
SDL_Rect mGradientRect[4]; // Vector con las coordenadas de los 4 gradientes
|
||||
Uint16 mBalloonsPopped; // Lleva la cuenta de los globos explotados
|
||||
Uint8 mLastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir;
|
||||
Uint8 mEnemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
||||
float mEnemySpeed; // Velocidad a la que se mueven los enemigos
|
||||
float mDefaultEnemySpeed; // Velocidad base de los enemigos, sin incrementar
|
||||
effect_t mEffect; // Variable para gestionar los efectos visuales
|
||||
helper_t mHelper; // Variable para gestionar las ayudas
|
||||
bool mPowerBallEnabled; // Indica si hay una powerball ya activa
|
||||
Uint8 mPowerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
||||
bool mCoffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego
|
||||
Uint8 mPostFade; // Qué hacer al acabar el fade
|
||||
float mSin[360]; // Vector con los valores del seno para 360 grados
|
||||
bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
|
||||
int mGameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
|
||||
Uint8 mDifficulty; // Dificultad del juego
|
||||
float mDifficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
|
||||
struct options_t *mOptions; // Variable con todas las variables de las opciones del programa
|
||||
Uint8 mOnePlayerControl; // Variable para almacenar el valor de las opciones
|
||||
Uint32 mHiScore; // Puntuación máxima
|
||||
bool mHiScoreAchieved; // Indica si se ha superado la puntuación máxima
|
||||
section_t mSection; // Seccion actual dentro del juego
|
||||
stage_t mStage[10]; // Variable con los datos de cada pantalla
|
||||
Uint8 mCurrentStage; // Indica la fase actual
|
||||
Uint8 mStageBitmapCounter; // Contador para el tiempo visible del texto de Stage
|
||||
float mStageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto
|
||||
float mGetReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
|
||||
Uint16 mDeathCounter; // Contador para la animación de muerte del jugador
|
||||
Uint8 mDeathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador
|
||||
Uint8 mMenaceCurrent; // Nivel de amenaza actual
|
||||
Uint8 mMenaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos
|
||||
bool mTimeStopped; // Indica si el tiempo está detenido
|
||||
Uint16 mTimeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido
|
||||
Uint32 mCounter; // Contador para el juego
|
||||
Uint32 mScoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos
|
||||
SDL_Rect mGradientRect[4]; // Vector con las coordenadas de los 4 gradientes
|
||||
Uint16 mBalloonsPopped; // Lleva la cuenta de los globos explotados
|
||||
Uint8 mLastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir;
|
||||
int mEnemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
|
||||
float mEnemySpeed; // Velocidad a la que se mueven los enemigos
|
||||
float mDefaultEnemySpeed; // Velocidad base de los enemigos, sin incrementar
|
||||
effect_t mEffect; // Variable para gestionar los efectos visuales
|
||||
helper_t mHelper; // Variable para gestionar las ayudas
|
||||
bool mPowerBallEnabled; // Indica si hay una powerball ya activa
|
||||
Uint8 mPowerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
||||
bool mCoffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego
|
||||
Uint8 mPostFade; // Qué hacer al acabar el fade
|
||||
float mSin[360]; // Vector con los valores del seno para 360 grados
|
||||
bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
|
||||
int mGameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
|
||||
Uint8 mDifficulty; // Dificultad del juego
|
||||
float mDifficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
|
||||
struct options_t *mOptions; // Variable con todas las variables de las opciones del programa
|
||||
Uint8 mOnePlayerControl; // Variable para almacenar el valor de las opciones
|
||||
enemyFormation_t mEnemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
|
||||
enemyPool_t mEnemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||
Uint8 mLastStageReached; // Contiene el numero de la última pantalla que se ha alcanzado
|
||||
|
||||
struct demo_t
|
||||
{
|
||||
bool enabled; // Indica si está activo el modo demo
|
||||
bool recording; // Indica si está activado el modo para grabar la demo
|
||||
Uint16 counter; // Contador para el modo demo
|
||||
demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo
|
||||
demoKeys_t dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo
|
||||
};
|
||||
demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo
|
||||
|
||||
struct debug_t
|
||||
{
|
||||
bool enabled; // Indica si se va a mostrar la información de debug
|
||||
Uint8 enemySet; // Escoge el set enemigo a generar
|
||||
Uint8 gradR, gradG, gradB; // Colores RGB para modificar el color del gradiente de fondo
|
||||
float hudW, hudH; // Multiplica el tamaño del hud de debug;
|
||||
};
|
||||
debug_t mDebug;
|
||||
demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo
|
||||
debug_t mDebug; // Variable con las opciones de debug
|
||||
|
||||
// Inicializa el vector con los valores del seno
|
||||
void initSin();
|
||||
@@ -426,18 +455,6 @@ private:
|
||||
// Actualiza y comprueba el valor de la variable
|
||||
void updateTimeStoppedCounter();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setExplosionTime(bool value);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool isExplosionTime();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRemainingExplosions(Uint8 value);
|
||||
|
||||
// Actualiza y comprueba el valor de la variable
|
||||
void updateRemainingExplosionsCounter();
|
||||
|
||||
// Gestiona el nivel de amenaza
|
||||
void updateMenace();
|
||||
|
||||
@@ -453,9 +470,6 @@ private:
|
||||
// Dibuja el campo de juego
|
||||
void renderPlayField();
|
||||
|
||||
// Gestiona las entradas desde el mando de juego
|
||||
bool checkGameController(Uint8 state);
|
||||
|
||||
// Gestiona la entrada durante el juego
|
||||
void checkGameInput();
|
||||
|
||||
@@ -500,7 +514,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *lang, Input *input, bool demo, options_t *options);
|
||||
Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang, Input *input, bool demo, options_t *options);
|
||||
|
||||
// Destructor
|
||||
~Game();
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#ifdef _WIN64
|
||||
#include "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\SDL2\SDL.h"
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\SDL2\SDL.h"
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
//#include "/Library/Frameworks/SDL2.framework/Versions/A/Headers/SDL.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#ifdef __MIPSEL__
|
||||
#include "SDL.h"
|
||||
#else
|
||||
#include <SDL2/SDL.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define UNUSED
|
||||
@@ -1,9 +1,6 @@
|
||||
#include "input.h"
|
||||
#include <iostream>
|
||||
|
||||
// Contestar cuantos joystics ha detectado
|
||||
// Preguntarlepor los joystics que ha encontrado para ir poniendolos en la variable de opciones
|
||||
|
||||
// Constructor
|
||||
Input::Input(std::string file)
|
||||
{
|
||||
@@ -53,7 +50,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
|
||||
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
|
||||
{
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -49,11 +50,10 @@ private:
|
||||
};
|
||||
GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
|
||||
//SDL_GameController *mGameController; // Manejador para el mando
|
||||
std::vector<SDL_GameController*> mConnectedControllers;
|
||||
std::vector<std::string> mControllerNames;
|
||||
int mNumGamepads;
|
||||
std::string mDBpath; // Ruta al archivo gamecontrollerdb.txt
|
||||
std::vector<SDL_GameController *> mConnectedControllers; // Vector con todos los mandos conectados
|
||||
std::vector<std::string> mControllerNames; // Vector con los nombres de los mandos
|
||||
int mNumGamepads; // Numero de mandos conectados
|
||||
std::string mDBpath; // Ruta al archivo gamecontrollerdb.txt
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
bool discoverGameController();
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool checkInput(Uint8 input, bool repeat, int device=INPUT_USE_ANY, int index=0);
|
||||
bool checkInput(Uint8 input, bool repeat, int device = INPUT_USE_ANY, int index = 0);
|
||||
|
||||
// Comprueba si hay algun mando conectado
|
||||
bool gameControllerFound();
|
||||
|
||||
@@ -1,43 +1,42 @@
|
||||
#include "instructions.h"
|
||||
#ifdef __MIPSEL__
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
const Uint8 SELF = 0;
|
||||
|
||||
// Constructor
|
||||
Instructions::Instructions(SDL_Renderer *renderer, std::string *fileList, Lang *lang)
|
||||
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang)
|
||||
{
|
||||
// Copia los punteros
|
||||
mRenderer = renderer;
|
||||
mFileList = fileList;
|
||||
mScreen = screen;
|
||||
this->mAsset = mAsset;
|
||||
mLang = lang;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
mEventHandler = new SDL_Event();
|
||||
mItemTexture = new LTexture();
|
||||
mTextTexture = new LTexture();
|
||||
mSprite = new Sprite();
|
||||
mText = new Text(mFileList[48], mTextTexture, mRenderer);
|
||||
mItemTexture = new LTexture(mRenderer);
|
||||
mSprite = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mItemTexture, mRenderer);
|
||||
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
|
||||
|
||||
// Crea un backbuffer para el renderizador
|
||||
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
if (mBackbuffer == NULL)
|
||||
if (mBackbuffer == nullptr)
|
||||
{
|
||||
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Instructions::~Instructions()
|
||||
{
|
||||
mRenderer = nullptr;
|
||||
mScreen = nullptr;
|
||||
mAsset = nullptr;
|
||||
mLang = nullptr;
|
||||
|
||||
mItemTexture->unload();
|
||||
delete mItemTexture;
|
||||
mItemTexture = nullptr;
|
||||
|
||||
mTextTexture->unload();
|
||||
delete mTextTexture;
|
||||
mTextTexture = nullptr;
|
||||
|
||||
delete mSprite;
|
||||
mSprite = nullptr;
|
||||
|
||||
@@ -56,8 +55,7 @@ bool Instructions::loadMedia()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
success &= loadTextureFromFile(mItemTexture, mFileList[34], mRenderer);
|
||||
success &= loadTextureFromFile(mTextTexture, mFileList[30], mRenderer);
|
||||
success &= loadTextureFromFile(mItemTexture, mAsset->get("items.png"), mRenderer);
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -70,7 +68,6 @@ void Instructions::init()
|
||||
|
||||
// Inicializa variables
|
||||
mSection.name = SELF;
|
||||
mSprite->init(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mItemTexture, mRenderer);
|
||||
mTicks = 0;
|
||||
mTicksSpeed = 15;
|
||||
mManualQuit = false;
|
||||
@@ -172,35 +169,35 @@ void Instructions::run(Uint8 mode)
|
||||
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, SCREEN_HEIGHT - 12, mLang->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
||||
|
||||
// Disquito
|
||||
mSprite->init(destRect1, mItemTexture, mRenderer);
|
||||
mSprite->setPos(destRect1);
|
||||
srcRect.x = 0;
|
||||
srcRect.y = 16 * (((mCounter + 12) / 36) % 2);
|
||||
mSprite->setSpriteClip(srcRect);
|
||||
mSprite->render();
|
||||
|
||||
// Gavineixon
|
||||
mSprite->init(destRect2, mItemTexture, mRenderer);
|
||||
mSprite->setPos(destRect2);
|
||||
srcRect.x += srcRect.w;
|
||||
srcRect.y = 16 * (((mCounter + 9) / 36) % 2);
|
||||
mSprite->setSpriteClip(srcRect);
|
||||
mSprite->render();
|
||||
|
||||
// Pacmar
|
||||
mSprite->init(destRect3, mItemTexture, mRenderer);
|
||||
mSprite->setPos(destRect3);
|
||||
srcRect.x += srcRect.w;
|
||||
srcRect.y = 16 * (((mCounter + 6) / 36) % 2);
|
||||
mSprite->setSpriteClip(srcRect);
|
||||
mSprite->render();
|
||||
|
||||
// Time Stopper
|
||||
mSprite->init(destRect4, mItemTexture, mRenderer);
|
||||
mSprite->setPos(destRect4);
|
||||
srcRect.x += srcRect.w;
|
||||
srcRect.y = 16 * (((mCounter + 3) / 36) % 2);
|
||||
mSprite->setSpriteClip(srcRect);
|
||||
mSprite->render();
|
||||
|
||||
// Coffee
|
||||
mSprite->init(destRect5, mItemTexture, mRenderer);
|
||||
mSprite->setPos(destRect5);
|
||||
srcRect.x += (srcRect.w * 2); // Se salta el icono del TNT
|
||||
srcRect.y = 16 * (((mCounter + 0) / 36) % 2);
|
||||
mSprite->setSpriteClip(srcRect);
|
||||
@@ -209,9 +206,11 @@ void Instructions::run(Uint8 mode)
|
||||
// Cambia el destino de renderizado
|
||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||
|
||||
// Limpia el renderizador
|
||||
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(mRenderer);
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
mScreen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
mScreen->clean(bgColor);
|
||||
|
||||
// Establece la ventana del backbuffer
|
||||
if (mode == INSTRUCTIONS_MODE_AUTO)
|
||||
@@ -220,9 +219,9 @@ void Instructions::run(Uint8 mode)
|
||||
window.y = 0;
|
||||
|
||||
// Copia el backbuffer al renderizador
|
||||
SDL_RenderCopy(mRenderer, mBackbuffer, NULL, &window);
|
||||
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, &window);
|
||||
|
||||
// Dibuja el renderizador en pantalla
|
||||
SDL_RenderPresent(mRenderer);
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
mScreen->blit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,35 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
#include "utils.h"
|
||||
#include "const.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include "const.h"
|
||||
#include "jail_audio.h"
|
||||
#include "screen.h"
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "jail_audio.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef INSTRUCTIONS_H
|
||||
#define INSTRUCTIONS_H
|
||||
|
||||
// Instructions
|
||||
// Contadores
|
||||
#define INSTRUCTIONS_COUNTER 600
|
||||
|
||||
// Modo para las instrucciones
|
||||
#define INSTRUCTIONS_MODE_MANUAL 0
|
||||
#define INSTRUCTIONS_MODE_AUTO 1
|
||||
|
||||
// Clase Instructions
|
||||
class Instructions
|
||||
{
|
||||
private:
|
||||
LTexture *mItemTexture; // Textura con los graficos
|
||||
LTexture *mTextTexture; // Textura con los graficos
|
||||
SDL_Event *mEventHandler; // Manejador de eventos
|
||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
||||
LTexture *mItemTexture; // Textura con los graficos
|
||||
SDL_Event *mEventHandler; // Manejador de eventos
|
||||
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
|
||||
Sprite *mSprite; // Sprite con la textura de las instrucciones
|
||||
std::string *mFileList; // Lista de ficheros
|
||||
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
Text *mText; // Objeto para escribir texto
|
||||
Uint16 mCounter; // Contador
|
||||
@@ -43,7 +52,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Instructions(SDL_Renderer *renderer, std::string *fileList, Lang *lang);
|
||||
Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang);
|
||||
|
||||
// Destructor
|
||||
~Instructions();
|
||||
|
||||
@@ -1,33 +1,38 @@
|
||||
#include "intro.h"
|
||||
#ifdef __MIPSEL__
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Intro::Intro(SDL_Renderer *renderer, std::string *fileList, Lang *lang)
|
||||
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang)
|
||||
{
|
||||
// Copia los punteros
|
||||
mRenderer = renderer;
|
||||
mFileList = fileList;
|
||||
mScreen = screen;
|
||||
mLang = lang;
|
||||
this->mAsset = mAsset;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
mEventHandler = new SDL_Event();
|
||||
mBitmapTexture = new LTexture();
|
||||
mTextTexture = new LTexture();
|
||||
mText = new Text(mFileList[52], mTextTexture, mRenderer);
|
||||
mBitmapTexture = new LTexture(mRenderer);
|
||||
mText = new Text(mAsset->get("nokia.png"), mAsset->get("nokia.txt"), mRenderer);
|
||||
|
||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
||||
{
|
||||
mBitmap[i] = new SmartSprite();
|
||||
}
|
||||
|
||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||
{
|
||||
mWriter[i] = new Writer(mText);
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Intro::~Intro()
|
||||
{
|
||||
mRenderer = nullptr;
|
||||
mScreen = nullptr;
|
||||
mAsset = nullptr;
|
||||
mLang = nullptr;
|
||||
|
||||
delete mEventHandler;
|
||||
mEventHandler = nullptr;
|
||||
|
||||
@@ -35,15 +40,12 @@ Intro::~Intro()
|
||||
delete mBitmapTexture;
|
||||
mBitmapTexture = nullptr;
|
||||
|
||||
mTextTexture->unload();
|
||||
delete mTextTexture;
|
||||
mTextTexture = nullptr;
|
||||
|
||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
||||
{
|
||||
delete mBitmap[i];
|
||||
mBitmap[i] = nullptr;
|
||||
}
|
||||
|
||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||
{
|
||||
delete mWriter[i];
|
||||
@@ -181,9 +183,7 @@ void Intro::init()
|
||||
mWriter[8]->setSpeed(20);
|
||||
|
||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||
{
|
||||
mWriter[i]->center(SCREEN_CENTER_X);
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los recursos
|
||||
@@ -192,11 +192,10 @@ bool Intro::loadMedia()
|
||||
bool success = true;
|
||||
|
||||
// Texturas
|
||||
success &= loadTextureFromFile(mBitmapTexture, mFileList[33], mRenderer);
|
||||
success &= loadTextureFromFile(mTextTexture, mFileList[28], mRenderer);
|
||||
success &= loadTextureFromFile(mBitmapTexture, mAsset->get("intro.png"), mRenderer);
|
||||
|
||||
// Musicas
|
||||
mMusic = JA_LoadMusic(mFileList[3].c_str());
|
||||
mMusic = JA_LoadMusic(mAsset->get("intro.ogg").c_str());
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -206,42 +205,46 @@ section_t Intro::run()
|
||||
{
|
||||
init();
|
||||
|
||||
// Si la música no está sonando
|
||||
// Si la música no está sonando la hace sonar
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
{
|
||||
// Reproduce la música
|
||||
JA_PlayMusic(mMusic, 0);
|
||||
}
|
||||
|
||||
while (mSection.name == PROG_SECTION_INTRO)
|
||||
{
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(mEventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (mEventHandler->type == SDL_QUIT)
|
||||
{
|
||||
mSection.name = PROG_SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
{
|
||||
JA_StopMusic();
|
||||
mSection = {PROG_SECTION_TITLE, TITLE_SECTION_1};
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
if (SDL_GetTicks() - mTicks > mTicksSpeed)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
mTicks = SDL_GetTicks();
|
||||
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(mEventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (mEventHandler->type == SDL_QUIT)
|
||||
{
|
||||
mSection.name = PROG_SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
{
|
||||
JA_StopMusic();
|
||||
mSection = {PROG_SECTION_TITLE, TITLE_SECTION_1};
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los objetos
|
||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
||||
{
|
||||
mBitmap[i]->update();
|
||||
}
|
||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||
{
|
||||
mWriter[i]->update();
|
||||
}
|
||||
|
||||
// Guión de eventos
|
||||
// Primera imagen - UPV
|
||||
@@ -356,18 +359,24 @@ section_t Intro::run()
|
||||
}
|
||||
}
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
mScreen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 0xFF);
|
||||
SDL_RenderClear(mRenderer);
|
||||
mScreen->clean(bgColor);
|
||||
|
||||
// Dibuja los objetos
|
||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; ++i)
|
||||
{
|
||||
mBitmap[i]->render();
|
||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||
}
|
||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; ++i)
|
||||
{
|
||||
mWriter[i]->render();
|
||||
}
|
||||
|
||||
// Actualiza la pantalla
|
||||
SDL_RenderPresent(mRenderer);
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
mScreen->blit();
|
||||
}
|
||||
|
||||
return mSection;
|
||||
|
||||
@@ -1,24 +1,48 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
#include "const.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "smartsprite.h"
|
||||
#include "writer.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include "const.h"
|
||||
#include "jail_audio.h"
|
||||
#include "screen.h"
|
||||
#include "smartsprite.h"
|
||||
#include "utils.h"
|
||||
#include "writer.h"
|
||||
|
||||
#ifndef INTRO_H
|
||||
#define INTRO_H
|
||||
|
||||
// Intro
|
||||
// Cantidad de eventos de la intro
|
||||
#define INTRO_TOTAL_BITMAPS 6
|
||||
#define INTRO_TOTAL_TEXTS 9
|
||||
const int INTRO_TOTAL_EVENTS = INTRO_TOTAL_BITMAPS + INTRO_TOTAL_TEXTS;
|
||||
|
||||
// Relaciones de Id con nombres
|
||||
#define BITMAP0 0
|
||||
#define BITMAP1 1
|
||||
#define BITMAP2 2
|
||||
#define BITMAP3 3
|
||||
#define BITMAP4 4
|
||||
#define BITMAP5 5
|
||||
#define TEXT0 6
|
||||
#define TEXT1 7
|
||||
#define TEXT2 8
|
||||
#define TEXT3 9
|
||||
#define TEXT4 10
|
||||
#define TEXT5 11
|
||||
#define TEXT6 12
|
||||
#define TEXT7 13
|
||||
#define TEXT8 14
|
||||
|
||||
// Clase Intro
|
||||
class Intro
|
||||
{
|
||||
private:
|
||||
LTexture *mBitmapTexture; // Textura con los graficos
|
||||
LTexture *mTextTexture; // Textura con los caracteres de texto
|
||||
SDL_Event *mEventHandler; // Manejador de eventos
|
||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||
std::string *mFileList; // Lista de ficheros
|
||||
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
||||
LTexture *mBitmapTexture; // Textura con los graficos
|
||||
SDL_Event *mEventHandler; // Manejador de eventos
|
||||
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
section_t mSection; // Estado del bucle principal para saber si continua o se sale
|
||||
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
|
||||
@@ -29,9 +53,12 @@ private:
|
||||
Uint8 mEvents[INTRO_TOTAL_EVENTS]; // Vector para coordinar los eventos de la intro
|
||||
JA_Music mMusic; // Musica para la intro
|
||||
|
||||
// Carga los recursos
|
||||
bool loadMedia();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Intro(SDL_Renderer *renderer, std::string *fileList, Lang *lang);
|
||||
Intro(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang);
|
||||
|
||||
// Destructor
|
||||
~Intro();
|
||||
@@ -39,9 +66,6 @@ public:
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
|
||||
// Carga los recursos
|
||||
bool loadMedia();
|
||||
|
||||
// Bucle principal
|
||||
section_t run();
|
||||
};
|
||||
|
||||
@@ -1,24 +1,12 @@
|
||||
#include "const.h"
|
||||
#include "item.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// Constructor
|
||||
Item::Item()
|
||||
Item::Item(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
mSprite = new AnimatedSprite();
|
||||
mSprite = new AnimatedSprite(texture, renderer);
|
||||
mClass = NO_KIND;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Item::~Item()
|
||||
{
|
||||
delete mSprite;
|
||||
mSprite = nullptr;
|
||||
}
|
||||
|
||||
// Iniciador
|
||||
void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
mClass = value;
|
||||
mEnabled = true;
|
||||
mTimeToLive = 600;
|
||||
@@ -34,12 +22,10 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *
|
||||
mCollider.r = mWidth / 2;
|
||||
shiftColliders();
|
||||
|
||||
mSprite->init(texture, renderer);
|
||||
mSprite->setAnimationFrames(0, 0, 0, 48, mWidth, mHeight);
|
||||
mSprite->setAnimationFrames(0, 1, 0, 64, mWidth, mHeight);
|
||||
mSprite->setCurrentFrame(0);
|
||||
mSprite->setAnimationCounter(0);
|
||||
mSprite->setAnimationNumFrames(0, 2);
|
||||
mSprite->setAnimationSpeed(0, 10);
|
||||
mSprite->setAnimationLoop(0, true);
|
||||
mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0));
|
||||
@@ -92,7 +78,6 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *
|
||||
mVelX = 0.0f;
|
||||
mVelY = -0.1f;
|
||||
mAccelY = 0.1f;
|
||||
mSprite->setAnimationNumFrames(0, 4);
|
||||
mSprite->setAnimationFrames(0, 0, 32 * 0, 16 * 2, mWidth, mHeight);
|
||||
mSprite->setAnimationFrames(0, 1, 32 * 1, 16 * 2, mWidth, mHeight);
|
||||
mSprite->setAnimationFrames(0, 2, 32 * 2, 16 * 2, mWidth, mHeight);
|
||||
@@ -108,6 +93,13 @@ void Item::init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Item::~Item()
|
||||
{
|
||||
delete mSprite;
|
||||
mSprite = nullptr;
|
||||
}
|
||||
|
||||
// Centra el objeto en la posición X
|
||||
void Item::allignTo(int x)
|
||||
{
|
||||
@@ -203,7 +195,7 @@ void Item::move()
|
||||
// Pone a cero todos los valores del objeto
|
||||
void Item::erase()
|
||||
{
|
||||
init(NO_KIND, 0, 0, nullptr, nullptr);
|
||||
//init(NO_KIND, 0, 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Actualiza el objeto a su posicion, animación y controla los contadores
|
||||
@@ -286,8 +278,6 @@ circle_t &Item::getCollider()
|
||||
// Alinea el circulo de colisión con la posición del objeto
|
||||
void Item::shiftColliders()
|
||||
{
|
||||
//mCollider.x = int(mPosX + mCollider.r);
|
||||
//mCollider.y = int(mPosY + mCollider.r);
|
||||
mCollider.x = int(mPosX + (mWidth / 2));
|
||||
mCollider.y = int(mPosY + (mHeight / 2));
|
||||
}
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "animatedsprite.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef ITEM_H
|
||||
#define ITEM_H
|
||||
|
||||
// Clase AnimatedSprite
|
||||
// Tipos de objetos
|
||||
#define ITEM_POINTS_1_DISK 1
|
||||
#define ITEM_POINTS_2_GAVINA 2
|
||||
#define ITEM_POINTS_3_PACMAR 3
|
||||
#define ITEM_CLOCK 4
|
||||
#define ITEM_COFFEE 5
|
||||
#define ITEM_POWER_BALL 6
|
||||
#define ITEM_COFFEE_MACHINE 7
|
||||
|
||||
// Clase Item
|
||||
class Item
|
||||
{
|
||||
private:
|
||||
float mPosX; // Posición X del objeto
|
||||
float mPosY; // Posición Y del objeto
|
||||
Uint8 mWidth; // Ancho del objeto
|
||||
Uint8 mHeight; // Alto del objeto
|
||||
float mVelX; // Velocidad en el eje X
|
||||
float mVelY; // Velocidad en el eje Y
|
||||
float mAccelX; // Aceleración en el eje X
|
||||
float mAccelY; // Aceleración en el eje Y
|
||||
bool mFloorCollision; // Indica si el objeto colisiona con el suelo
|
||||
float mPosX; // Posición X del objeto
|
||||
float mPosY; // Posición Y del objeto
|
||||
Uint8 mWidth; // Ancho del objeto
|
||||
Uint8 mHeight; // Alto del objeto
|
||||
float mVelX; // Velocidad en el eje X
|
||||
float mVelY; // Velocidad en el eje Y
|
||||
float mAccelX; // Aceleración en el eje X
|
||||
float mAccelY; // Aceleración en el eje Y
|
||||
bool mFloorCollision; // Indica si el objeto colisiona con el suelo
|
||||
|
||||
AnimatedSprite *mSprite; // Sprite con los graficos del objeto
|
||||
|
||||
@@ -30,15 +40,14 @@ private:
|
||||
void shiftColliders();
|
||||
|
||||
public:
|
||||
Uint16 mTimeToLive; // Temporizador con el tiempo que el objeto está presente
|
||||
|
||||
// Constructor
|
||||
Item();
|
||||
Item(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Item();
|
||||
|
||||
// Iniciador
|
||||
void init(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Centra el objeto en la posición X
|
||||
void allignTo(int x);
|
||||
|
||||
@@ -84,9 +93,6 @@ public:
|
||||
// Obtiene el circulo de colisión
|
||||
circle_t &getCollider();
|
||||
|
||||
// Temporizador con el tiempo que el objeto está presente
|
||||
Uint16 mTimeToLive;
|
||||
|
||||
// Informa si el objeto ha colisionado con el suelo
|
||||
bool floorCollision();
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef __MIPSEL__
|
||||
#include "jail_audio.h"
|
||||
#include "stb_vorbis.c"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
||||
|
||||
@@ -30,16 +31,17 @@ JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
||||
int JA_freq {48000};
|
||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
||||
Uint8 JA_channels {2};
|
||||
int JA_volume = 128;
|
||||
|
||||
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
||||
SDL_memset(stream, 0, len);
|
||||
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
|
||||
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
|
||||
SDL_memcpy(stream, current_music->output+current_music->pos, size);
|
||||
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_volume);
|
||||
current_music->pos += size/2;
|
||||
if (size < len) {
|
||||
if (current_music->times != 0) {
|
||||
SDL_memcpy(stream+size, current_music->output, len-size);
|
||||
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_volume);
|
||||
current_music->pos = (len-size)/2;
|
||||
if (current_music->times > 0) current_music->times--;
|
||||
} else {
|
||||
@@ -52,11 +54,11 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
|
||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
||||
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
||||
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, 64);
|
||||
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_volume/2);
|
||||
channels[i].pos += size;
|
||||
if (size < len) {
|
||||
if (channels[i].times != 0) {
|
||||
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, 64);
|
||||
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_volume/2);
|
||||
channels[i].pos = len-size;
|
||||
if (channels[i].times > 0) channels[i].times--;
|
||||
} else {
|
||||
@@ -79,7 +81,19 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
||||
JA_Music JA_LoadMusic(const char* filename) {
|
||||
int chan, samplerate;
|
||||
JA_Music music = new JA_Music_t();
|
||||
music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
||||
|
||||
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
|
||||
FILE *f = fopen(filename, "rb");
|
||||
fseek(f, 0, SEEK_END);
|
||||
long fsize = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
Uint8 *buffer = (Uint8*)malloc(fsize + 1);
|
||||
fread(buffer, fsize, 1, f);
|
||||
fclose(f);
|
||||
music->samples = stb_vorbis_decode_memory(buffer, fsize, &chan, &samplerate, &music->output);
|
||||
free(buffer);
|
||||
// [RZC 28/08/22] Abans el descomprimiem mentre el teniem obert
|
||||
// music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
||||
|
||||
SDL_AudioCVT cvt;
|
||||
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
|
||||
@@ -134,6 +148,13 @@ void JA_DeleteMusic(JA_Music music) {
|
||||
delete music;
|
||||
}
|
||||
|
||||
JA_Sound JA_NewSound(Uint8* buffer, Uint32 length) {
|
||||
JA_Sound sound = new JA_Sound_t();
|
||||
sound->buffer = buffer;
|
||||
sound->length = length;
|
||||
return sound;
|
||||
}
|
||||
|
||||
JA_Sound JA_LoadSound(const char* filename) {
|
||||
JA_Sound sound = new JA_Sound_t();
|
||||
SDL_AudioSpec wavSpec;
|
||||
@@ -210,4 +231,8 @@ JA_Channel_state JA_GetChannelState(const int channel) {
|
||||
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
|
||||
return channels[channel].state;
|
||||
}
|
||||
#endif
|
||||
|
||||
int JA_SetVolume(int volume) {
|
||||
JA_volume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
||||
return JA_volume;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
|
||||
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
|
||||
@@ -17,6 +17,7 @@ void JA_StopMusic();
|
||||
JA_Music_state JA_GetMusicState();
|
||||
void JA_DeleteMusic(JA_Music music);
|
||||
|
||||
JA_Sound JA_NewSound(Uint8* buffer, Uint32 length);
|
||||
JA_Sound JA_LoadSound(const char* filename);
|
||||
int JA_PlaySound(JA_Sound sound, const int loop = 0);
|
||||
void JA_PauseChannel(const int channel);
|
||||
@@ -24,3 +25,5 @@ void JA_ResumeChannel(const int channel);
|
||||
void JA_StopChannel(const int channel);
|
||||
JA_Channel_state JA_GetChannelState(const int channel);
|
||||
void JA_DeleteSound(JA_Sound sound);
|
||||
|
||||
int JA_SetVolume(int volume);
|
||||
@@ -1,106 +0,0 @@
|
||||
#ifdef __MIPSEL__
|
||||
#include "jail_audio.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
struct JA_Sound_t {
|
||||
Mix_Chunk *mix_chunk;
|
||||
};
|
||||
|
||||
struct JA_Music_t {
|
||||
Mix_Music* mix_music;
|
||||
};
|
||||
|
||||
JA_Music current_music{NULL};
|
||||
|
||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
||||
Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
|
||||
Mix_AllocateChannels(8);
|
||||
}
|
||||
|
||||
JA_Music JA_LoadMusic(const char* filename) {
|
||||
int chan, samplerate;
|
||||
JA_Music music = new JA_Music_t();
|
||||
music->mix_music = Mix_LoadMUS(filename);
|
||||
return music;
|
||||
}
|
||||
|
||||
void JA_PlayMusic(JA_Music music, const int loop) {
|
||||
if (current_music == music) return;
|
||||
if (current_music != NULL) {
|
||||
Mix_HaltMusic();
|
||||
}
|
||||
current_music = music;
|
||||
Mix_PlayMusic(music->mix_music, loop);
|
||||
}
|
||||
|
||||
void JA_PauseMusic() {
|
||||
Mix_PauseMusic();
|
||||
}
|
||||
|
||||
void JA_ResumeMusic() {
|
||||
Mix_ResumeMusic();
|
||||
}
|
||||
|
||||
void JA_StopMusic() {
|
||||
Mix_HaltMusic();
|
||||
}
|
||||
|
||||
JA_Music_state JA_GetMusicState() {
|
||||
if (current_music == NULL) return JA_MUSIC_INVALID;
|
||||
if (Mix_PausedMusic()) {
|
||||
return JA_MUSIC_PAUSED;
|
||||
} else if (Mix_PlayingMusic()) {
|
||||
return JA_MUSIC_PLAYING;
|
||||
} else {
|
||||
return JA_MUSIC_STOPPED;
|
||||
}
|
||||
}
|
||||
|
||||
void JA_DeleteMusic(JA_Music music) {
|
||||
if (current_music == music) {
|
||||
Mix_HaltMusic();
|
||||
current_music = NULL;
|
||||
}
|
||||
Mix_FreeMusic(music->mix_music);
|
||||
delete music;
|
||||
}
|
||||
|
||||
JA_Sound JA_LoadSound(const char* filename) {
|
||||
JA_Sound sound = new JA_Sound_t();
|
||||
sound->mix_chunk = Mix_LoadWAV(filename);
|
||||
return sound;
|
||||
}
|
||||
|
||||
int JA_PlaySound(JA_Sound sound, const int loop) {
|
||||
int channel = Mix_PlayChannel(-1, sound->mix_chunk, loop);
|
||||
return channel;
|
||||
}
|
||||
|
||||
void JA_DeleteSound(JA_Sound sound) {
|
||||
Mix_FreeChunk(sound->mix_chunk);
|
||||
delete sound;
|
||||
}
|
||||
|
||||
void JA_PauseChannel(const int channel) {
|
||||
Mix_Pause(channel);
|
||||
}
|
||||
|
||||
void JA_ResumeChannel(const int channel) {
|
||||
Mix_Resume(channel);
|
||||
}
|
||||
|
||||
void JA_StopChannel(const int channel) {
|
||||
Mix_HaltChannel(channel);
|
||||
}
|
||||
|
||||
JA_Channel_state JA_GetChannelState(const int channel) {
|
||||
if (Mix_Paused(channel)) {
|
||||
return JA_CHANNEL_PAUSED;
|
||||
} else if (Mix_Playing(channel)) {
|
||||
return JA_CHANNEL_PLAYING;
|
||||
} else {
|
||||
return JA_CHANNEL_FREE;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3,9 +3,9 @@
|
||||
#include <fstream>
|
||||
|
||||
// Constructor
|
||||
Lang::Lang(std::string *fileList)
|
||||
Lang::Lang(Asset *mAsset)
|
||||
{
|
||||
mFileList = fileList;
|
||||
this->mAsset = mAsset;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -21,19 +21,19 @@ bool Lang::setLang(Uint8 lang)
|
||||
switch (lang)
|
||||
{
|
||||
case es_ES:
|
||||
file = mFileList[49];
|
||||
file = mAsset->get("es_ES.txt");
|
||||
break;
|
||||
|
||||
case en_UK:
|
||||
file = mFileList[50];
|
||||
file = mAsset->get("en_UK.txt");
|
||||
break;
|
||||
|
||||
case ba_BA:
|
||||
file = mFileList[51];
|
||||
file = mAsset->get("ba_BA.txt");
|
||||
break;
|
||||
|
||||
default:
|
||||
file = mFileList[50];
|
||||
file = mAsset->get("en_UK.txt");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include <string>
|
||||
|
||||
#ifndef LANG_H
|
||||
#define LANG_H
|
||||
|
||||
// Lang codes
|
||||
// Códigos de idioma
|
||||
#define es_ES 0
|
||||
#define ba_BA 1
|
||||
#define en_UK 2
|
||||
@@ -18,15 +20,15 @@
|
||||
class Lang
|
||||
{
|
||||
private:
|
||||
std::string *mFileList; // Lista de ficheros con los recursos
|
||||
std::string mTextStrings[MAX_TEXT_STRINGS];
|
||||
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||
std::string mTextStrings[MAX_TEXT_STRINGS]; // Vector con los textos
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Lang(std::string *fileList);
|
||||
// Constructor
|
||||
Lang(Asset *mAsset);
|
||||
|
||||
// Destructor
|
||||
~Lang();
|
||||
// Destructor
|
||||
~Lang();
|
||||
|
||||
// Inicializa los textos del juego en el idioma seleccionado
|
||||
bool setLang(Uint8 lang);
|
||||
|
||||
233
source/logo.cpp
233
source/logo.cpp
@@ -1,146 +1,157 @@
|
||||
#include "logo.h"
|
||||
#ifdef __MIPSEL__
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
# define INIT_FADE 100
|
||||
# define END_LOGO 200
|
||||
#define INIT_FADE 100
|
||||
#define END_LOGO 200
|
||||
|
||||
// Constructor
|
||||
Logo::Logo(SDL_Renderer *renderer, std::string *fileList)
|
||||
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
{
|
||||
// Copia la dirección del renderizador
|
||||
mRenderer = renderer;
|
||||
|
||||
// Copia la dirección del la lista de ficheros
|
||||
mFileList = fileList;
|
||||
// Copia la dirección de los objetos
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
mEventHandler = new SDL_Event();
|
||||
mTexture = new LTexture();
|
||||
mSprite = new Sprite();
|
||||
eventHandler = new SDL_Event();
|
||||
texture = new LTexture(renderer,asset->get("logo.png");
|
||||
sprite = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, texture, renderer);
|
||||
|
||||
// Crea un backbuffer para el renderizador
|
||||
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
if (mBackbuffer == NULL)
|
||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
if (backbuffer == nullptr)
|
||||
{
|
||||
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
counter = 0;
|
||||
section.name = PROG_SECTION_LOGO;
|
||||
section.subsection = 0;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Logo::~Logo()
|
||||
{
|
||||
mTexture->unload();
|
||||
delete mTexture;
|
||||
mTexture = nullptr;
|
||||
SDL_DestroyTexture(backbuffer);
|
||||
|
||||
delete mSprite;
|
||||
mSprite = nullptr;
|
||||
texture->unload();
|
||||
delete texture;
|
||||
|
||||
delete mEventHandler;
|
||||
mEventHandler = nullptr;
|
||||
|
||||
SDL_DestroyTexture(mBackbuffer);
|
||||
mBackbuffer = nullptr;
|
||||
delete sprite;
|
||||
delete eventHandler;
|
||||
}
|
||||
|
||||
// Inicializa las variables necesarias para la sección 'Logo'
|
||||
void Logo::init()
|
||||
// Comprueba si ha terminado el logo
|
||||
void Logo::checkLogoEnd()
|
||||
{
|
||||
// Carga los recursos
|
||||
loadMedia();
|
||||
if (counter == 0)
|
||||
{
|
||||
if (JA_GetMusicState() == JA_MUSIC_PLAYING)
|
||||
{
|
||||
JA_StopMusic();
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
mCounter = 0;
|
||||
mSection.name = PROG_SECTION_LOGO;
|
||||
mSection.subsection = 0;
|
||||
mSprite->init(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mTexture, mRenderer);
|
||||
mTicks = 0;
|
||||
mTicksSpeed = 15;
|
||||
if (counter == END_LOGO + 20)
|
||||
{
|
||||
counter = 0;
|
||||
section.name = PROG_SECTION_INTRO;
|
||||
section.subsection = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los recursos necesarios para la sección 'Logo'
|
||||
bool Logo::loadMedia()
|
||||
// Comprueba los eventos
|
||||
void Logo::checkEventHandler()
|
||||
{
|
||||
bool success = true;
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
{
|
||||
section.name = PROG_SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
success &= loadTextureFromFile(mTexture, mFileList[35], mRenderer);
|
||||
// Cualquier tecla pulsada
|
||||
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
{
|
||||
section.name = PROG_SECTION_TITLE;
|
||||
section.subsection = TITLE_SECTION_1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
// Dibuja el fade
|
||||
void Logo::renderFade()
|
||||
{
|
||||
const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||
const int fadeLenght = END_LOGO - INIT_FADE;
|
||||
|
||||
// Dibuja el fade
|
||||
if (counter >= INIT_FADE)
|
||||
{
|
||||
const Uint16 alpha = (255 * (counter - INIT_FADE)) / fadeLenght;
|
||||
if (alpha < 256)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
}
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void Logo::update()
|
||||
{
|
||||
checkEventHandler();
|
||||
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
// Comprueba si ha terminado el logo
|
||||
checkLogoEnd();
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el objeto en pantalla
|
||||
void Logo::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(bgColor);
|
||||
|
||||
// Dibuja los objetos
|
||||
sprite->render();
|
||||
|
||||
// Dibuja el fade
|
||||
renderFade();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
section_t Logo::run()
|
||||
{
|
||||
init();
|
||||
const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||
const int fadeLenght = END_LOGO - INIT_FADE;
|
||||
|
||||
while (mSection.name == PROG_SECTION_LOGO)
|
||||
while (section.name == PROG_SECTION_LOGO)
|
||||
{
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(mEventHandler) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (mEventHandler->type == SDL_QUIT)
|
||||
{
|
||||
mSection.name = PROG_SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
// Cualquier tecla pulsada
|
||||
if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
{
|
||||
mSection.name = PROG_SECTION_TITLE;
|
||||
mSection.subsection = TITLE_SECTION_1;
|
||||
}
|
||||
}
|
||||
|
||||
// Limpia el destino
|
||||
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(mRenderer);
|
||||
|
||||
// Dibuja los objetos
|
||||
mSprite->render();
|
||||
|
||||
// Dibuja el fade
|
||||
if (mCounter >= INIT_FADE)
|
||||
{
|
||||
Uint16 alpha = (255 * (mCounter - INIT_FADE)) / fadeLenght;
|
||||
if (alpha < 256)
|
||||
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, alpha);
|
||||
else
|
||||
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderFillRect(mRenderer, &rect);
|
||||
}
|
||||
|
||||
// Actualiza la pantalla
|
||||
SDL_RenderPresent(mRenderer);
|
||||
|
||||
// Comprueba si ha terminado el logo
|
||||
if (SDL_GetTicks() - mTicks > mTicksSpeed)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
mTicks = SDL_GetTicks();
|
||||
|
||||
if (mCounter == 0)
|
||||
{
|
||||
if (JA_GetMusicState() == JA_MUSIC_PLAYING)
|
||||
JA_StopMusic();
|
||||
}
|
||||
|
||||
if (mCounter == END_LOGO + 20)
|
||||
{
|
||||
mCounter = 0;
|
||||
mSection.name = PROG_SECTION_INTRO;
|
||||
mSection.subsection = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mCounter++;
|
||||
}
|
||||
}
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
return mSection;
|
||||
return section;
|
||||
}
|
||||
|
||||
@@ -1,42 +1,54 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
#include "const.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "sprite.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include "const.h"
|
||||
#include "jail_audio.h"
|
||||
#include "screen.h"
|
||||
#include "sprite.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef LOGO_H
|
||||
#define LOGO_H
|
||||
|
||||
// Logo
|
||||
// Clase Logo
|
||||
class Logo
|
||||
{
|
||||
private:
|
||||
LTexture *mTexture; // Textura con los graficos
|
||||
SDL_Event *mEventHandler; // Manejador de eventos
|
||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
|
||||
Sprite *mSprite; // Sprite con la textura del logo
|
||||
std::string *mFileList; // Lista de ficheros
|
||||
Uint16 mCounter; // Contador
|
||||
section_t mSection; // Estado del bucle principal para saber si continua o se sale
|
||||
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
LTexture *texture; // Textura con los graficos
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||
Sprite *sprite; // Sprite con la textura del logo
|
||||
int counter; // Contador
|
||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update();
|
||||
|
||||
// Dibuja el objeto en pantalla
|
||||
void render();
|
||||
|
||||
// Comprueba si ha terminado el logo
|
||||
void checkLogoEnd();
|
||||
|
||||
// Comprueba los eventos
|
||||
void checkEventHandler();
|
||||
|
||||
// Dibuja el fade
|
||||
void renderFade();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Logo(SDL_Renderer *renderer, std::string *fileList);
|
||||
Logo(SDL_Renderer *renderer, Screen *screen, Asset *mAsset);
|
||||
|
||||
// Destructor
|
||||
~Logo();
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
|
||||
// Carga los recursos
|
||||
bool loadMedia();
|
||||
|
||||
// Bucle principal
|
||||
section_t run();
|
||||
};
|
||||
|
||||
@@ -1,28 +1,41 @@
|
||||
#include "const.h"
|
||||
|
||||
#include "ltexture.h"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
LTexture::LTexture()
|
||||
// Constructor
|
||||
LTexture::LTexture(SDL_Renderer *renderer, std::string path)
|
||||
{
|
||||
// Initialize
|
||||
mTexture = NULL;
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
// Copia punteros
|
||||
this->renderer = renderer;
|
||||
this->path = path;
|
||||
|
||||
// Inicializa
|
||||
texture = nullptr;
|
||||
width = 0;
|
||||
height = 0;
|
||||
|
||||
// Carga el fichero en la textura
|
||||
if (path != "")
|
||||
{
|
||||
loadFromFile(path, renderer);
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
LTexture::~LTexture()
|
||||
{
|
||||
// Deallocate
|
||||
// Libera memoria
|
||||
unload();
|
||||
}
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
{
|
||||
int req_format = STBI_rgb_alpha;
|
||||
int width, height, orig_format;
|
||||
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
||||
if (data == NULL)
|
||||
if (data == nullptr)
|
||||
{
|
||||
SDL_Log("Loading image failed: %s", stbi_failure_reason());
|
||||
exit(1);
|
||||
@@ -33,7 +46,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
if (req_format == STBI_rgb)
|
||||
{
|
||||
depth = 24;
|
||||
pitch = 3 * width; // 3 bytes per pixel * pixels per row
|
||||
pitch = 3 * width; // 3 bytes por pixel * pixels per linea
|
||||
pixel_format = SDL_PIXELFORMAT_RGB24;
|
||||
}
|
||||
else
|
||||
@@ -43,100 +56,99 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
pixel_format = SDL_PIXELFORMAT_RGBA32;
|
||||
}
|
||||
|
||||
// Get rid of preexisting texture
|
||||
// Limpia
|
||||
unload();
|
||||
|
||||
// The final texture
|
||||
SDL_Texture *newTexture = NULL;
|
||||
// La textura final
|
||||
SDL_Texture *newTexture = nullptr;
|
||||
|
||||
// Load image at specified path
|
||||
//SDL_Surface *loadedSurface = IMG_Load(path.c_str());
|
||||
// Carga la imagen desde una ruta específica
|
||||
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
||||
if (loadedSurface == NULL)
|
||||
if (loadedSurface == nullptr)
|
||||
{
|
||||
printf("Unable to load image %s!\n", path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Color key image
|
||||
//SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B));
|
||||
|
||||
// Create texture from surface pixels
|
||||
// Crea la textura desde los pixels de la surface
|
||||
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
||||
if (newTexture == NULL)
|
||||
if (newTexture == nullptr)
|
||||
{
|
||||
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get image dimensions
|
||||
mWidth = loadedSurface->w;
|
||||
mHeight = loadedSurface->h;
|
||||
// Obtiene las dimensiones de la imagen
|
||||
this->width = loadedSurface->w;
|
||||
this->height = loadedSurface->h;
|
||||
}
|
||||
|
||||
// Get rid of old loaded surface
|
||||
// Elimina la textura cargada
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
}
|
||||
|
||||
// Return success
|
||||
mTexture = newTexture;
|
||||
return mTexture != NULL;
|
||||
texture = newTexture;
|
||||
return texture != nullptr;
|
||||
}
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess access)
|
||||
{
|
||||
// Create uninitialized texture
|
||||
mTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||
if (mTexture == NULL)
|
||||
// Crea una textura sin inicializar
|
||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||
if (texture == nullptr)
|
||||
{
|
||||
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
return mTexture != NULL;
|
||||
return texture != nullptr;
|
||||
}
|
||||
|
||||
// Libera la memoria de la textura
|
||||
void LTexture::unload()
|
||||
{
|
||||
// Free texture if it exists
|
||||
if (mTexture != NULL)
|
||||
// Libera la textura si existe
|
||||
if (texture != nullptr)
|
||||
{
|
||||
SDL_DestroyTexture(mTexture);
|
||||
mTexture = NULL;
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
SDL_DestroyTexture(texture);
|
||||
texture = nullptr;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el color para la modulacion
|
||||
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
// Modulate texture rgb
|
||||
SDL_SetTextureColorMod(mTexture, red, green, blue);
|
||||
SDL_SetTextureColorMod(texture, red, green, blue);
|
||||
}
|
||||
|
||||
// Establece el blending
|
||||
void LTexture::setBlendMode(SDL_BlendMode blending)
|
||||
{
|
||||
// Set blending function
|
||||
SDL_SetTextureBlendMode(mTexture, blending);
|
||||
SDL_SetTextureBlendMode(texture, blending);
|
||||
}
|
||||
|
||||
// Establece el alpha para la modulación
|
||||
void LTexture::setAlpha(Uint8 alpha)
|
||||
{
|
||||
// Modulate texture alpha
|
||||
SDL_SetTextureAlphaMod(mTexture, alpha);
|
||||
SDL_SetTextureAlphaMod(texture, alpha);
|
||||
}
|
||||
|
||||
// Renderiza la textura en un punto específico
|
||||
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||
{
|
||||
// Set rendering space and render to screen
|
||||
SDL_Rect renderQuad = {x, y, mWidth, mHeight};
|
||||
// Establece el destini de renderizado en la pantalla
|
||||
SDL_Rect renderQuad = {x, y, width, height};
|
||||
|
||||
// Set clip rendering dimensions
|
||||
if (clip != NULL)
|
||||
// Obtiene las dimesiones del clip de renderizado
|
||||
if (clip != nullptr)
|
||||
{
|
||||
renderQuad.w = clip->w;
|
||||
renderQuad.h = clip->h;
|
||||
@@ -145,22 +157,30 @@ void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, floa
|
||||
renderQuad.w = renderQuad.w * zoomW;
|
||||
renderQuad.h = renderQuad.h * zoomH;
|
||||
|
||||
// Render to screen
|
||||
SDL_RenderCopyEx(renderer, mTexture, clip, &renderQuad, angle, center, flip);
|
||||
// Renderiza a pantalla
|
||||
SDL_RenderCopyEx(renderer, texture, clip, &renderQuad, angle, center, flip);
|
||||
}
|
||||
|
||||
// Establece la textura como objetivo de renderizado
|
||||
void LTexture::setAsRenderTarget(SDL_Renderer *renderer)
|
||||
{
|
||||
// Make self render target
|
||||
SDL_SetRenderTarget(renderer, mTexture);
|
||||
SDL_SetRenderTarget(renderer, texture);
|
||||
}
|
||||
|
||||
// Obtiene el ancho de la imagen
|
||||
int LTexture::getWidth()
|
||||
{
|
||||
return mWidth;
|
||||
return width;
|
||||
}
|
||||
|
||||
// Obtiene el alto de la imagen
|
||||
int LTexture::getHeight()
|
||||
{
|
||||
return mHeight;
|
||||
return height;
|
||||
}
|
||||
|
||||
// Recarga la textura
|
||||
bool LTexture::reLoad()
|
||||
{
|
||||
return loadFromFile(path, renderer);
|
||||
}
|
||||
@@ -1,66 +1,61 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#ifndef LTEXTURE_H
|
||||
#define LTEXTURE_H
|
||||
|
||||
// Texture wrapper class
|
||||
// Clase LTexture
|
||||
class LTexture
|
||||
{
|
||||
public:
|
||||
// Initializes variables
|
||||
LTexture();
|
||||
private:
|
||||
SDL_Texture *texture; // La textura
|
||||
SDL_Renderer *renderer; // Renderizador donde dibujar la textura
|
||||
int width; // Ancho de la imagen
|
||||
int height; // Alto de la imagen
|
||||
std::string path; // Ruta de la imagen de la textura
|
||||
|
||||
// Deallocates memory
|
||||
public:
|
||||
// Constructor
|
||||
LTexture(SDL_Renderer *renderer, std::string path = "");
|
||||
|
||||
// Destructor
|
||||
~LTexture();
|
||||
|
||||
// Loads image at specified path
|
||||
// Carga una imagen desde un fichero
|
||||
bool loadFromFile(std::string path, SDL_Renderer *renderer);
|
||||
|
||||
// Creates blank texture
|
||||
// Crea una textura en blanco
|
||||
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||
|
||||
// Deallocates texture
|
||||
// Libera la memoria de la textura
|
||||
void unload();
|
||||
|
||||
// Set color modulation
|
||||
// Establece el color para la modulacion
|
||||
void setColor(Uint8 red, Uint8 green, Uint8 blue);
|
||||
|
||||
// Set blending
|
||||
// Establece el blending
|
||||
void setBlendMode(SDL_BlendMode blending);
|
||||
|
||||
// Set alpha modulation
|
||||
// Establece el alpha para la modulación
|
||||
void setAlpha(Uint8 alpha);
|
||||
|
||||
// Renders texture at given point
|
||||
void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = NULL, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE);
|
||||
// Renderiza la textura en un punto específico
|
||||
void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = nullptr, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = nullptr, SDL_RendererFlip flip = SDL_FLIP_NONE);
|
||||
|
||||
// Set self as render target
|
||||
// Establece la textura como objetivo de renderizado
|
||||
void setAsRenderTarget(SDL_Renderer *renderer);
|
||||
|
||||
// Gets image dimensions
|
||||
// Obtiene el ancho de la imagen
|
||||
int getWidth();
|
||||
|
||||
// Obtiene el alto de la imagen
|
||||
int getHeight();
|
||||
|
||||
// Pixel manipulators
|
||||
bool lockTexture();
|
||||
bool unlockTexture();
|
||||
void *getPixels();
|
||||
void copyPixels(void *pixels);
|
||||
int getPitch();
|
||||
Uint32 getPixel32(unsigned int x, unsigned int y);
|
||||
|
||||
private:
|
||||
// The actual hardware texture
|
||||
SDL_Texture *mTexture;
|
||||
void *mPixels;
|
||||
int mPitch;
|
||||
|
||||
// Image dimensions
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
// Recarga la textura
|
||||
bool reLoad();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
936
source/menu.cpp
936
source/menu.cpp
File diff suppressed because it is too large
Load Diff
199
source/menu.h
199
source/menu.h
@@ -1,95 +1,112 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <vector>
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "asset.h"
|
||||
#include "input.h"
|
||||
#include "utils.h"
|
||||
#include "jail_audio.h"
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#ifndef MENU_H
|
||||
#define MENU_H
|
||||
|
||||
#define MENU_MAX_ITEMS 50
|
||||
// Tipos de fondos para el menu
|
||||
#define MENU_BACKGROUND_TRANSPARENT 0
|
||||
#define MENU_BACKGROUND_SOLID 1
|
||||
|
||||
// Clase menu
|
||||
// Tipos de archivos de audio
|
||||
#define SOUND_ACCEPT 0
|
||||
#define SOUND_MOVE 1
|
||||
#define SOUND_CANCEL 2
|
||||
|
||||
// Opciones de menu
|
||||
#define MENU_NO_OPTION -1
|
||||
|
||||
// Clase Menu
|
||||
class Menu
|
||||
{
|
||||
private:
|
||||
std::string mName; // Nombre del menu
|
||||
int mPosX; // Posición en el eje X de la primera letra del primer elemento
|
||||
int mPosY; // Posición en el eje Y de la primera letra del primer elemento
|
||||
Uint16 mHeight; // Altura del menu
|
||||
Uint16 mWidth; // Anchura del menu
|
||||
Uint8 mTotalItems; // Numero total de items del menu
|
||||
int mItemSelected; // Índice del item del menu que ha sido seleccionado
|
||||
Uint8 mDefaultActionWhenCancel; // Indice del item del menu que se selecciona cuando se cancela el menu
|
||||
Uint8 mBackgroundType; // Tipo de fondo para el menu
|
||||
bool mIsCenteredOnX; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje X
|
||||
bool mIsCenteredOnY; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y
|
||||
int mCenterX; // Centro del menu en el eje X
|
||||
int mCenterY; // Centro del menu en el eje Y
|
||||
bool mAreElementsCenteredOnX; // Variable para saber si los elementos van centrados en el eje X
|
||||
Uint16 mWidestItem; // Anchura del elemento más ancho
|
||||
JA_Sound mSoundAccept; // Sonido al aceptar o elegir una opción del menu
|
||||
JA_Sound mSoundCancel; // Sonido al cancelar el menu
|
||||
JA_Sound mSoundMove; // Sonido al mover el selector
|
||||
SDL_Renderer *mRenderer; // Puntero al renderizador de la ventana
|
||||
std::string *mFileList; // Lista de ficheros
|
||||
Text *mText; // Texto para poder escribir los items del menu
|
||||
Input *mInput; // Gestor de eventos de entrada de teclado o gamepad
|
||||
color_t mColorGreyed; // Color para los elementos agrisados
|
||||
|
||||
struct rectangle
|
||||
struct rectangle_t
|
||||
{
|
||||
SDL_Rect rect; // Rectangulo
|
||||
Uint8 r; // Rojo
|
||||
Uint8 g; // Verde
|
||||
Uint8 b; // Azul
|
||||
Uint8 a; // Transparencia
|
||||
color_t color; // Color
|
||||
int a; // Transparencia
|
||||
};
|
||||
rectangle mRectBG; // Rectangulo de fondo del menu
|
||||
|
||||
struct item
|
||||
struct item_t
|
||||
{
|
||||
std::string label; // Texto
|
||||
SDL_Rect rect; // Rectangulo que delimita el elemento
|
||||
Uint8 hPaddingDown; // Espaciado bajo el elemento
|
||||
bool selectable; // Indica si se puede seleccionar
|
||||
bool greyed; // Indica si ha de aparecer con otro color mas oscuro
|
||||
bool linkedDown; // Indica si el elemento actual y el siguiente se tratan como uno solo. Afecta al selector
|
||||
bool linkedUp; // Indica si el elemento actual y el anterior se tratan como uno solo. Afecta al selector
|
||||
std::string label; // Texto
|
||||
SDL_Rect rect; // Rectangulo que delimita el elemento
|
||||
int hPaddingDown; // Espaciado bajo el elemento
|
||||
bool selectable; // Indica si se puede seleccionar
|
||||
bool greyed; // Indica si ha de aparecer con otro color mas oscuro
|
||||
bool linkedDown; // Indica si el elemento actual y el siguiente se tratan como uno solo. Afecta al selector
|
||||
bool linkedUp; // Indica si el elemento actual y el anterior se tratan como uno solo. Afecta al selector
|
||||
};
|
||||
item mItem[MENU_MAX_ITEMS]; // Estructura para cada elemento del menu
|
||||
|
||||
struct selector
|
||||
struct selector_t
|
||||
{
|
||||
float originY; // Coordenada de origen
|
||||
float targetY; // Coordenada de destino
|
||||
float despY; // Cantidad de pixeles que se desplaza el selector en cada salto: (target - origin) / numJumps
|
||||
bool moving; // Indica si el selector está avanzando hacia el destino
|
||||
float originH; // Altura de origen
|
||||
float targetH; // Altura de destino
|
||||
float incH; // Cantidad de pixels que debe incrementar o decrementar el selector en cada salto
|
||||
bool resizing; // Indica si el selector está cambiando de tamaño
|
||||
float y; // Coordenada actual, usado para el desplazamiento
|
||||
float h; // Altura actual, usado para el cambio de tamaño
|
||||
Uint8 numJumps; // Numero de pasos preestablecido para llegar al destino
|
||||
Uint8 index; // Elemento del menu que tiene el foco
|
||||
SDL_Rect rect; // Rectangulo del selector
|
||||
Uint8 r; // Cantidad de color rojo para el rectangulo del selector
|
||||
Uint8 g; // Cantidad de color verde para el rectangulo del selector
|
||||
Uint8 b; // Cantidad de color azul para el rectangulo del selector
|
||||
Uint8 a; // Cantidad de transparencia para el rectangulo del selector
|
||||
Uint8 itemR; // Cantidad de color rojo para el texto del elemento seleccionado
|
||||
Uint8 itemG; // Cantidad de color verde para el texto del elemento seleccionado
|
||||
Uint8 itemB; // Cantidad de color azul para el texto del elemento seleccionado
|
||||
float originY; // Coordenada de origen
|
||||
float targetY; // Coordenada de destino
|
||||
float despY; // Cantidad de pixeles que se desplaza el selector en cada salto: (target - origin) / numJumps
|
||||
bool moving; // Indica si el selector está avanzando hacia el destino
|
||||
float originH; // Altura de origen
|
||||
float targetH; // Altura de destino
|
||||
float incH; // Cantidad de pixels que debe incrementar o decrementar el selector en cada salto
|
||||
bool resizing; // Indica si el selector está cambiando de tamaño
|
||||
float y; // Coordenada actual, usado para el desplazamiento
|
||||
float h; // Altura actual, usado para el cambio de tamaño
|
||||
int numJumps; // Numero de pasos preestablecido para llegar al destino
|
||||
int index; // Elemento del menu que tiene el foco
|
||||
SDL_Rect rect; // Rectangulo del selector
|
||||
color_t color; // Color del selector
|
||||
color_t itemColor; // Color del item
|
||||
int a; // Cantidad de transparencia para el rectangulo del selector
|
||||
};
|
||||
selector mSelector; // Variables para pintar el selector del menu
|
||||
|
||||
// Carga los recursos necesarios para la sección 'Title'
|
||||
bool loadMedia();
|
||||
std::string name; // Nombre del menu
|
||||
int x; // Posición en el eje X de la primera letra del primer elemento
|
||||
int y; // Posición en el eje Y de la primera letra del primer elemento
|
||||
int h; // Altura del menu
|
||||
int w; // Anchura del menu
|
||||
int itemSelected; // Índice del item del menu que ha sido seleccionado
|
||||
int defaultActionWhenCancel; // Indice del item del menu que se selecciona cuando se cancela el menu
|
||||
int backgroundType; // Tipo de fondo para el menu
|
||||
int centerX; // Centro del menu en el eje X
|
||||
int centerY; // Centro del menu en el eje Y
|
||||
bool isCenteredOnX; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje X
|
||||
bool isCenteredOnY; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y
|
||||
bool areElementsCenteredOnX; // Variable para saber si los elementos van centrados en el eje X
|
||||
int widestItem; // Anchura del elemento más ancho
|
||||
JA_Sound soundAccept; // Sonido al aceptar o elegir una opción del menu
|
||||
JA_Sound soundCancel; // Sonido al cancelar el menu
|
||||
JA_Sound soundMove; // Sonido al mover el selector
|
||||
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
||||
Text *text; // Texto para poder escribir los items del menu
|
||||
Input *input; // Gestor de eventos de entrada de teclado o gamepad
|
||||
Asset *asset; // Objeto para gestionar los ficheros de recursos
|
||||
color_t colorGreyed; // Color para los elementos agrisados
|
||||
rectangle_t rectBG; // Rectangulo de fondo del menu
|
||||
std::vector<item_t> item; // Estructura para cada elemento del menu
|
||||
selector_t selector; // Variables para pintar el selector del menu
|
||||
std::string font_png;
|
||||
std::string font_txt;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setTotalItems(int num);
|
||||
// Carga la configuración del menu desde un archivo de texto
|
||||
bool load(std::string file_path);
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setVars(std::string var, std::string value);
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setItem(item_t *item, std::string var, std::string value);
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
|
||||
// Establece el rectangulo de fondo del menu
|
||||
void setRectSize();
|
||||
@@ -107,16 +124,16 @@ private:
|
||||
void updateSelector();
|
||||
|
||||
// Obtiene la anchura del elemento más ancho del menu
|
||||
Uint16 getWidestItem();
|
||||
int getWidestItem();
|
||||
|
||||
// Gestiona la entrada de teclado y mando durante el menu
|
||||
void checkMenuInput(Menu *menu);
|
||||
|
||||
// Calcula el ancho del menu
|
||||
Uint16 findWidth();
|
||||
int findWidth();
|
||||
|
||||
// Calcula el alto del menu
|
||||
Uint16 findHeight();
|
||||
int findHeight();
|
||||
|
||||
// Recoloca los elementos del menu en el eje Y
|
||||
void replaceElementsOnY();
|
||||
@@ -126,19 +143,19 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Menu(SDL_Renderer *renderer, Text *text, Input *input, std::string *fileList);
|
||||
Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file="");
|
||||
|
||||
// Destructor
|
||||
~Menu();
|
||||
|
||||
// Inicializador
|
||||
void init(std::string name, int x, int y, int backgroundType);
|
||||
// Carga los ficheros de audio
|
||||
void loadAudioFile(std::string file, int sound);
|
||||
|
||||
// Obtiene el nombre del menu
|
||||
std::string getName();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint8 getItemSelected();
|
||||
int getItemSelected();
|
||||
|
||||
// Deja el menu apuntando al primer elemento
|
||||
void reset();
|
||||
@@ -153,13 +170,13 @@ public:
|
||||
void render();
|
||||
|
||||
// Establece el color del rectangulo de fondo
|
||||
void setBackgroundColor(int r, int g, int b, int alpha);
|
||||
void setBackgroundColor(color_t color, int alpha);
|
||||
|
||||
// Establece el color del rectangulo del selector
|
||||
void setSelectorColor(int r, int g, int b, int alpha);
|
||||
void setSelectorColor(color_t color, int alpha);
|
||||
|
||||
// Establece el color del texto del selector
|
||||
void setSelectorTextColor(int r, int g, int b);
|
||||
void setSelectorTextColor(color_t color);
|
||||
|
||||
// Centra el menu respecto a un punto en el eje X
|
||||
void centerMenuOnX(int value);
|
||||
@@ -171,25 +188,37 @@ public:
|
||||
void centerMenuElementsOnX();
|
||||
|
||||
// Añade un item al menu
|
||||
void addItem(std::string text, Uint8 hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false);
|
||||
void addItem(std::string text, int hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false);
|
||||
|
||||
// Cambia el texto de un item
|
||||
void setItemCaption(Uint8 index, std::string text);
|
||||
void setItemCaption(int index, std::string text);
|
||||
|
||||
// Establece el indice del item que se usará por defecto al cancelar el menu
|
||||
void setDefaultActionWhenCancel(Uint8 item);
|
||||
void setDefaultActionWhenCancel(int item);
|
||||
|
||||
// Coloca el selector en una posición específica
|
||||
void setSelectorPos(Uint8 index);
|
||||
void setSelectorPos(int index);
|
||||
|
||||
// Establece el estado seleccionable de un item
|
||||
void setSelectable(Uint8 index, bool value);
|
||||
void setSelectable(int index, bool value);
|
||||
|
||||
// Establece el estado agrisado de un item
|
||||
void setGreyed(Uint8 index, bool value);
|
||||
void setGreyed(int index, bool value);
|
||||
|
||||
// Establece el estado de enlace de un item
|
||||
void setLinkedDown(Uint8 index, bool value);
|
||||
void setLinkedDown(int index, bool value);
|
||||
|
||||
// Establece el nombre del menu
|
||||
void setName(std::string name);
|
||||
|
||||
// Establece la posición del menu
|
||||
void setPos(int x, int y);
|
||||
|
||||
// Establece el tipo de fondo del menu
|
||||
void setBackgroundType(int value);
|
||||
|
||||
|
||||
// hacer procedimientos para establecer el titulo, la x, la y, la tipografia y el tipo de fondo
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,244 +2,256 @@
|
||||
#include "movingsprite.h"
|
||||
|
||||
// Constructor
|
||||
MovingSprite::MovingSprite()
|
||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
// Copia los punteros
|
||||
this->texture = texture;
|
||||
this->renderer = renderer;
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
// Establece la posición X,Y del sprite
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
xPrev = x;
|
||||
yPrev = y;
|
||||
|
||||
// Establece la velocidad X,Y del sprite
|
||||
vx = velx;
|
||||
vy = vely;
|
||||
|
||||
// Establece la aceleración X,Y del sprite
|
||||
ax = accelx;
|
||||
ay = accely;
|
||||
|
||||
// Establece el zoom W,H del sprite
|
||||
zoomW = 1;
|
||||
zoomH = 1;
|
||||
|
||||
// Establece el angulo con el que se dibujará
|
||||
angle = (double)0;
|
||||
|
||||
// Establece los valores de rotacion
|
||||
rotateEnabled = false;
|
||||
rotateSpeed = 0;
|
||||
rotateAmount = (double)0;
|
||||
|
||||
// Contador interno
|
||||
counter = 0;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip = {0, 0, w, h};
|
||||
|
||||
// Establece el centro de rotación
|
||||
center = {0, 0};
|
||||
|
||||
// Establece el tipo de volteado
|
||||
currentFlip = SDL_FLIP_NONE;
|
||||
};
|
||||
|
||||
// Destructor
|
||||
MovingSprite::~MovingSprite()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
// Reinicia todas las variables
|
||||
void MovingSprite::clear()
|
||||
{
|
||||
mPosX = 0.0f; // Posición en el eje X
|
||||
mPosY = 0.0f; // Posición en el eje Y
|
||||
x = 0.0f; // Posición en el eje X
|
||||
y = 0.0f; // Posición en el eje Y
|
||||
|
||||
mVelX = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
mVelY = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
vx = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
vy = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
|
||||
mAccelX = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
||||
mAccelY = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
||||
ax = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
||||
ay = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
mZoomW = 1.0f; // Zoom aplicado a la anchura
|
||||
mZoomH = 1.0f; // Zoom aplicado a la altura
|
||||
zoomW = 1.0f; // Zoom aplicado a la anchura
|
||||
zoomH = 1.0f; // Zoom aplicado a la altura
|
||||
|
||||
mAngle = 0.0; // Angulo para dibujarlo
|
||||
mRotate = false; // Indica si ha de rotar
|
||||
mRotateSpeed = 0; // Velocidad de giro
|
||||
mRotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
||||
mCounter = 0; // Contador interno
|
||||
}
|
||||
angle = 0.0; // Angulo para dibujarlo
|
||||
rotateEnabled = false; // Indica si ha de rotar
|
||||
center = {0, 0}; // Centro de rotación
|
||||
rotateSpeed = 0; // Velocidad de giro
|
||||
rotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
||||
counter = 0; // Contador interno
|
||||
|
||||
// Iniciador
|
||||
void MovingSprite::init(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece el alto y el ancho del sprite
|
||||
setWidth(w);
|
||||
setHeight(h);
|
||||
|
||||
// Establece la posición X,Y del sprite
|
||||
setPosX(x);
|
||||
setPosY(y);
|
||||
|
||||
// Establece la velocidad X,Y del sprite
|
||||
setVelX(velx);
|
||||
setVelY(vely);
|
||||
|
||||
// Establece la aceleración X,Y del sprite
|
||||
setAccelX(accelx);
|
||||
setAccelY(accely);
|
||||
|
||||
// Establece el zoom W,H del sprite
|
||||
setZoomW(1);
|
||||
setZoomH(1);
|
||||
|
||||
// Establece el angulo con el que se dibujará
|
||||
setAngle(0.0);
|
||||
|
||||
// Establece los valores de rotacion
|
||||
setRotate(false);
|
||||
setRotateSpeed(0);
|
||||
setRotateAmount(0.0);
|
||||
|
||||
// Contador interno
|
||||
mCounter = 0;
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
setTexture(texture);
|
||||
|
||||
// Establece el renderizador
|
||||
setRenderer(renderer);
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
setSpriteClip(0, 0, w, h);
|
||||
currentFlip = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||
}
|
||||
|
||||
// Mueve el sprite
|
||||
void MovingSprite::move()
|
||||
{
|
||||
if (mEnabled)
|
||||
if (enabled)
|
||||
{
|
||||
mPosX += mVelX;
|
||||
mPosY += mVelY;
|
||||
xPrev = x;
|
||||
yPrev = y;
|
||||
|
||||
mVelX += mAccelX;
|
||||
mVelY += mAccelY;
|
||||
x += vx;
|
||||
y += vy;
|
||||
|
||||
vx += ax;
|
||||
vy += ay;
|
||||
}
|
||||
}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void MovingSprite::render()
|
||||
{
|
||||
if (mEnabled)
|
||||
mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip, mZoomW, mZoomH, mAngle);
|
||||
if (enabled)
|
||||
texture->render(renderer, (int)x, (int)y, &spriteClip, zoomW, zoomH, angle, ¢er, currentFlip);
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getPosX()
|
||||
{
|
||||
return mPosX;
|
||||
return x;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getPosY()
|
||||
{
|
||||
return mPosY;
|
||||
return y;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getVelX()
|
||||
{
|
||||
return mVelX;
|
||||
return vx;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getVelY()
|
||||
{
|
||||
return mVelY;
|
||||
return vy;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getAccelX()
|
||||
{
|
||||
return mAccelX;
|
||||
return ax;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getAccelY()
|
||||
{
|
||||
return mAccelY;
|
||||
return ay;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getZoomW()
|
||||
{
|
||||
return mZoomW;
|
||||
return zoomW;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getZoomH()
|
||||
{
|
||||
return mZoomH;
|
||||
return zoomH;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
double MovingSprite::getAngle()
|
||||
{
|
||||
return mAngle;
|
||||
return angle;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void MovingSprite::setPos(SDL_Rect rect)
|
||||
{
|
||||
x = (float)rect.x;
|
||||
y = (float)rect.y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosX(float x)
|
||||
void MovingSprite::setPosX(float value)
|
||||
{
|
||||
mPosX = x;
|
||||
x = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosY(float y)
|
||||
void MovingSprite::setPosY(float value)
|
||||
{
|
||||
mPosY = y;
|
||||
y = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setVelX(float x)
|
||||
void MovingSprite::setVelX(float value)
|
||||
{
|
||||
mVelX = x;
|
||||
vx = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setVelY(float y)
|
||||
void MovingSprite::setVelY(float value)
|
||||
{
|
||||
mVelY = y;
|
||||
vy = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAccelX(float x)
|
||||
void MovingSprite::setAccelX(float value)
|
||||
{
|
||||
mAccelX = x;
|
||||
ax = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAccelY(float y)
|
||||
void MovingSprite::setAccelY(float value)
|
||||
{
|
||||
mAccelY = y;
|
||||
ay = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomW(float w)
|
||||
void MovingSprite::setZoomW(float value)
|
||||
{
|
||||
mZoomW = w;
|
||||
zoomW = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomH(float h)
|
||||
void MovingSprite::setZoomH(float value)
|
||||
{
|
||||
mZoomH = h;
|
||||
zoomH = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAngle(double a)
|
||||
void MovingSprite::setAngle(double value)
|
||||
{
|
||||
mAngle = a;
|
||||
angle = value;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void MovingSprite::incAngle(double inc)
|
||||
void MovingSprite::incAngle(double value)
|
||||
{
|
||||
mAngle += inc;
|
||||
angle += value;
|
||||
}
|
||||
|
||||
// Decrementa el valor de la variable
|
||||
void MovingSprite::decAngle(double dec)
|
||||
void MovingSprite::decAngle(double value)
|
||||
{
|
||||
mAngle -= dec;
|
||||
angle -= value;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool MovingSprite::getRotate()
|
||||
{
|
||||
return mRotate;
|
||||
return rotateEnabled;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 MovingSprite::getRotateSpeed()
|
||||
{
|
||||
return mRotateSpeed;
|
||||
return rotateSpeed;
|
||||
}
|
||||
|
||||
// Establece la rotacion
|
||||
void MovingSprite::rotate()
|
||||
{
|
||||
if (mEnabled)
|
||||
if (mRotate)
|
||||
if (enabled)
|
||||
if (rotateEnabled)
|
||||
{
|
||||
if (mCounter % mRotateSpeed == 0)
|
||||
if (counter % rotateSpeed == 0)
|
||||
{
|
||||
incAngle(mRotateAmount);
|
||||
incAngle(rotateAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,26 +259,26 @@ void MovingSprite::rotate()
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotate(bool value)
|
||||
{
|
||||
mRotate = value;
|
||||
rotateEnabled = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateSpeed(Uint16 value)
|
||||
void MovingSprite::setRotateSpeed(int value)
|
||||
{
|
||||
mRotateSpeed = value;
|
||||
rotateSpeed = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateAmount(double value)
|
||||
{
|
||||
mRotateAmount = value;
|
||||
rotateAmount = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::disableRotate()
|
||||
{
|
||||
mRotate = false;
|
||||
mAngle = 0;
|
||||
rotateEnabled = false;
|
||||
angle = (double)0;
|
||||
}
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
@@ -275,12 +287,79 @@ void MovingSprite::update()
|
||||
move();
|
||||
rotate();
|
||||
|
||||
if (mEnabled)
|
||||
++mCounter %= 60000;
|
||||
if (enabled)
|
||||
{
|
||||
++counter %= 60000;
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void MovingSprite::switchRotate()
|
||||
{
|
||||
mRotateAmount *= -1;
|
||||
rotateAmount *= -1;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setFlip(SDL_RendererFlip flip)
|
||||
{
|
||||
currentFlip = flip;
|
||||
}
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void MovingSprite::flip()
|
||||
{
|
||||
currentFlip = (currentFlip == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip MovingSprite::getFlip()
|
||||
{
|
||||
return currentFlip;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect MovingSprite::getRect()
|
||||
{
|
||||
const SDL_Rect rect = {(int)x, (int)y, w, h};
|
||||
return rect;
|
||||
}
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void MovingSprite::setRect(SDL_Rect rect)
|
||||
{
|
||||
x = (float)rect.x;
|
||||
y = (float)rect.y;
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
}
|
||||
|
||||
// Deshace el último movimiento
|
||||
void MovingSprite::undoMove()
|
||||
{
|
||||
x = xPrev;
|
||||
y = yPrev;
|
||||
}
|
||||
|
||||
// Deshace el último movimiento en el eje X
|
||||
void MovingSprite::undoMoveX()
|
||||
{
|
||||
x = xPrev;
|
||||
}
|
||||
|
||||
// Deshace el último movimiento en el eje Y
|
||||
void MovingSprite::undoMoveY()
|
||||
{
|
||||
y = yPrev;
|
||||
}
|
||||
|
||||
// Pone a cero las velocidades de desplacamiento
|
||||
void MovingSprite::clearVel()
|
||||
{
|
||||
vx = vy = 0.0f;
|
||||
}
|
||||
|
||||
// Devuelve el incremento en el eje X en pixels
|
||||
int MovingSprite::getIncX()
|
||||
{
|
||||
return (int)x - (int)xPrev;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "sprite.h"
|
||||
|
||||
#ifndef MOVINGSPRITE_H
|
||||
@@ -9,34 +10,36 @@
|
||||
class MovingSprite : public Sprite
|
||||
{
|
||||
protected:
|
||||
float mPosX; // Posición en el eje X
|
||||
float mPosY; // Posición en el eje Y
|
||||
float x; // Posición en el eje X
|
||||
float y; // Posición en el eje Y
|
||||
|
||||
float mVelX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
float mVelY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
float xPrev; // Posición anterior en el eje X
|
||||
float yPrev; // Posición anterior en el eje Y
|
||||
|
||||
float mAccelX; // Aceleración en el eje X. Variación de la velocidad
|
||||
float mAccelY; // Aceleración en el eje Y. Variación de la velocidad
|
||||
float vx; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
float vy; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
|
||||
float mZoomW; // Zoom aplicado a la anchura
|
||||
float mZoomH; // Zoom aplicado a la altura
|
||||
float ax; // Aceleración en el eje X. Variación de la velocidad
|
||||
float ay; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
double mAngle; // Angulo para dibujarlo
|
||||
bool mRotate; // Indica si ha de rotar
|
||||
Uint16 mRotateSpeed; // Velocidad de giro
|
||||
double mRotateAmount; // Cantidad de grados a girar en cada iteración
|
||||
Uint16 mCounter; // Contador interno
|
||||
float zoomW; // Zoom aplicado a la anchura
|
||||
float zoomH; // Zoom aplicado a la altura
|
||||
|
||||
double angle; // Angulo para dibujarlo
|
||||
bool rotateEnabled; // Indica si ha de rotar
|
||||
int rotateSpeed; // Velocidad de giro
|
||||
double rotateAmount; // Cantidad de grados a girar en cada iteración
|
||||
int counter; // Contador interno
|
||||
SDL_Point center; // Centro de rotación
|
||||
SDL_RendererFlip currentFlip; // Indica como se voltea el sprite
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
MovingSprite();
|
||||
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
|
||||
// Destructor
|
||||
~MovingSprite();
|
||||
|
||||
// Iniciador
|
||||
void init(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
|
||||
@@ -85,44 +88,47 @@ public:
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 getRotateSpeed();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float x);
|
||||
// Establece la posición del objeto
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(float y);
|
||||
void setPosX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelX(float x);
|
||||
void setPosY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelY(float y);
|
||||
void setVelX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelX(float x);
|
||||
void setVelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelY(float y);
|
||||
void setAccelX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomW(float w);
|
||||
void setAccelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomH(float h);
|
||||
void setZoomW(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAngle(double a);
|
||||
void setZoomH(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAngle(double vaue);
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void incAngle(double inc);
|
||||
void incAngle(double value);
|
||||
|
||||
// Decrementa el valor de la variable
|
||||
void decAngle(double dec);
|
||||
void decAngle(double value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotate(bool value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateSpeed(Uint16 value);
|
||||
void setRotateSpeed(int value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateAmount(double value);
|
||||
@@ -132,6 +138,36 @@ public:
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void switchRotate();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setFlip(SDL_RendererFlip flip);
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void flip();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip getFlip();
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
|
||||
// Deshace el último movimiento
|
||||
void undoMove();
|
||||
|
||||
// Deshace el último movimiento en el eje X
|
||||
void undoMoveX();
|
||||
|
||||
// Deshace el último movimiento en el eje Y
|
||||
void undoMoveY();
|
||||
|
||||
// Pone a cero las velocidades de desplacamiento
|
||||
void clearVel();
|
||||
|
||||
// Devuelve el incremento en el eje X en pixels
|
||||
int getIncX();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -74,7 +74,7 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
||||
mCooldown = 10;
|
||||
|
||||
// Inicia el sprite
|
||||
mSpriteLegs->init(textureLegs, renderer);
|
||||
mSpriteLegs->init();
|
||||
mSpriteBody->init(textureBody, renderer);
|
||||
mSpriteHead->init(textureHead, renderer);
|
||||
|
||||
@@ -262,15 +262,15 @@ void Player::setInput(Uint8 input)
|
||||
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
|
||||
break;
|
||||
|
||||
case INPUT_FIRE_UP:
|
||||
case INPUT_BUTTON_2:
|
||||
setFiringStatus(PLAYER_STATUS_FIRING_UP);
|
||||
break;
|
||||
|
||||
case INPUT_FIRE_LEFT:
|
||||
case INPUT_BUTTON_1:
|
||||
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
|
||||
break;
|
||||
|
||||
case INPUT_FIRE_RIGHT:
|
||||
case INPUT_BUTTON_3:
|
||||
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
|
||||
break;
|
||||
|
||||
@@ -291,10 +291,7 @@ void Player::move()
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales
|
||||
if ((mPosX < PLAY_AREA_LEFT - 5) || (mPosX + mWidth > PLAY_AREA_RIGHT + 5))
|
||||
{
|
||||
// Restaura su posición
|
||||
mPosX -= mVelX;
|
||||
}
|
||||
mPosX -= mVelX; // Restaura su posición
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
mSpriteLegs->setPosX(getPosX());
|
||||
@@ -509,13 +506,9 @@ bool Player::canFire()
|
||||
{
|
||||
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
|
||||
if (mCooldown > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "input.h"
|
||||
#include "animatedsprite.h"
|
||||
@@ -6,7 +8,42 @@
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
// The player
|
||||
// Contadores
|
||||
#define DEATH_COUNTER 350
|
||||
|
||||
// Estados del jugador
|
||||
#define PLAYER_STATUS_WALKING_LEFT 0
|
||||
#define PLAYER_STATUS_WALKING_RIGHT 1
|
||||
#define PLAYER_STATUS_WALKING_STOP 2
|
||||
|
||||
#define PLAYER_STATUS_FIRING_UP 0
|
||||
#define PLAYER_STATUS_FIRING_LEFT 1
|
||||
#define PLAYER_STATUS_FIRING_RIGHT 2
|
||||
#define PLAYER_STATUS_FIRING_NO 3
|
||||
|
||||
#define PLAYER_ANIMATION_LEGS_WALKING_RIGHT 1
|
||||
#define PLAYER_ANIMATION_LEGS_WALKING_STOP 2
|
||||
|
||||
#define PLAYER_ANIMATION_BODY_WALKING_LEFT 0
|
||||
#define PLAYER_ANIMATION_BODY_FIRING_LEFT 1
|
||||
#define PLAYER_ANIMATION_BODY_WALKING_RIGHT 2
|
||||
#define PLAYER_ANIMATION_BODY_FIRING_RIGHT 3
|
||||
#define PLAYER_ANIMATION_BODY_WALKING_STOP 4
|
||||
#define PLAYER_ANIMATION_BODY_FIRING_UP 5
|
||||
|
||||
#define PLAYER_ANIMATION_HEAD_WALKING_LEFT 0
|
||||
#define PLAYER_ANIMATION_HEAD_FIRING_LEFT 1
|
||||
#define PLAYER_ANIMATION_HEAD_WALKING_RIGHT 2
|
||||
#define PLAYER_ANIMATION_HEAD_FIRING_RIGHT 3
|
||||
#define PLAYER_ANIMATION_HEAD_WALKING_STOP 4
|
||||
#define PLAYER_ANIMATION_HEAD_FIRING_UP 5
|
||||
#define PLAYER_ANIMATION_LEGS_WALKING_LEFT 0
|
||||
|
||||
// Variables del jugador
|
||||
#define PLAYER_INVULNERABLE_COUNTER 200
|
||||
#define PLAYER_POWERUP_COUNTER 1500
|
||||
|
||||
// Clase Player
|
||||
class Player
|
||||
{
|
||||
private:
|
||||
|
||||
133
source/screen.cpp
Normal file
133
source/screen.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
#include "screen.h"
|
||||
#include "const.h"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
||||
{
|
||||
// Inicializa variables
|
||||
mWindow = window;
|
||||
mRenderer = renderer;
|
||||
mOptions = options;
|
||||
|
||||
mGameCanvasWidth = SCREEN_WIDTH;
|
||||
mGameCanvasHeight = SCREEN_HEIGHT;
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(mOptions->fullScreenMode);
|
||||
|
||||
// Define el color del borde para el modo de pantalla completa
|
||||
mBorderColor = {0x27, 0x27, 0x36};
|
||||
mBorderColor = {0x00, 0x00, 0x00};
|
||||
|
||||
// Crea la textura donde se dibujan los graficos del juego
|
||||
mGameCanvas = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, mGameCanvasWidth, mGameCanvasHeight);
|
||||
if (mGameCanvas == nullptr)
|
||||
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
mRenderer = nullptr;
|
||||
}
|
||||
|
||||
// Limpia la pantalla
|
||||
void Screen::clean(color_t color)
|
||||
{
|
||||
SDL_SetRenderDrawColor(mRenderer, color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(mRenderer);
|
||||
}
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
void Screen::start()
|
||||
{
|
||||
SDL_SetRenderTarget(mRenderer, mGameCanvas);
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
void Screen::blit()
|
||||
{
|
||||
// Vuelve a dejar el renderizador en modo normal
|
||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||
|
||||
// Borra el contenido previo
|
||||
SDL_SetRenderDrawColor(mRenderer, mBorderColor.r, mBorderColor.g, mBorderColor.b, 0xFF);
|
||||
SDL_RenderClear(mRenderer);
|
||||
|
||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||
SDL_RenderCopy(mRenderer, mGameCanvas, nullptr, &mDest);
|
||||
|
||||
// Muestra por pantalla el renderizador
|
||||
SDL_RenderPresent(mRenderer);
|
||||
}
|
||||
|
||||
// Establece el modo de video
|
||||
void Screen::setVideoMode(int fullScreenMode)
|
||||
{
|
||||
// Aplica el modo de video
|
||||
SDL_SetWindowFullscreen(mWindow, fullScreenMode);
|
||||
|
||||
// Si está activo el modo ventana quita el borde
|
||||
if (fullScreenMode == 0)
|
||||
{
|
||||
mScreenWidth = mGameCanvasWidth;
|
||||
mScreenHeight = mGameCanvasHeight;
|
||||
mDest = {0, 0, mGameCanvasWidth, mGameCanvasHeight};
|
||||
|
||||
// Modifica el tamaño del renderizador y de la ventana
|
||||
SDL_RenderSetLogicalSize(mRenderer, mScreenWidth, mScreenHeight);
|
||||
SDL_SetWindowSize(mWindow, mScreenWidth * mOptions->windowSize, mScreenHeight * mOptions->windowSize);
|
||||
}
|
||||
|
||||
// Si está activo el modo de pantalla completa añade el borde
|
||||
if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||
{
|
||||
// Obten el alto y el ancho de la ventana
|
||||
SDL_GetWindowSize(mWindow, &mScreenWidth, &mScreenHeight);
|
||||
|
||||
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
||||
if (mOptions->integerScale)
|
||||
{
|
||||
// Calcula el tamaño de la escala máxima
|
||||
int scale = 0;
|
||||
while (((mGameCanvasWidth * (scale + 1)) <= mScreenWidth) && ((mGameCanvasHeight * (scale + 1)) <= mScreenHeight))
|
||||
{
|
||||
scale++;
|
||||
}
|
||||
|
||||
mDest.w = mGameCanvasWidth * scale;
|
||||
mDest.h = mGameCanvasHeight * scale;
|
||||
mDest.x = (mScreenWidth - mDest.w) / 2;
|
||||
mDest.y = (mScreenHeight - mDest.h) / 2;
|
||||
}
|
||||
else if (mOptions->keepAspect)
|
||||
{
|
||||
float ratio = (float)mGameCanvasWidth / (float)mGameCanvasHeight;
|
||||
if ((mScreenWidth - mGameCanvasWidth) >= (mScreenHeight - mGameCanvasHeight))
|
||||
{
|
||||
mDest.h = mScreenHeight;
|
||||
mDest.w = (int)((mScreenHeight * ratio) + 0.5f);
|
||||
mDest.x = (mScreenWidth - mDest.w) / 2;
|
||||
mDest.y = (mScreenHeight - mDest.h) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
mDest.w = mScreenWidth;
|
||||
mDest.h = (int)((mScreenWidth / ratio) + 0.5f);
|
||||
mDest.x = (mScreenWidth - mDest.w) / 2;
|
||||
mDest.y = (mScreenHeight - mDest.h) / 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mDest.w = mScreenWidth;
|
||||
mDest.h = mScreenHeight;
|
||||
mDest.x = mDest.y = 0;
|
||||
}
|
||||
|
||||
// Modifica el tamaño del renderizador
|
||||
SDL_RenderSetLogicalSize(mRenderer, mScreenWidth, mScreenHeight);
|
||||
}
|
||||
}
|
||||
45
source/screen.h
Normal file
45
source/screen.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef SCREEN_H
|
||||
#define SCREEN_H
|
||||
|
||||
// Clase Screen
|
||||
class Screen
|
||||
{
|
||||
private:
|
||||
SDL_Window *mWindow; // Ventana de la aplicación
|
||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||
SDL_Texture *mGameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||
options_t *mOptions; // Variable con todas las opciones del programa
|
||||
|
||||
int mScreenWidth; // Ancho de la pantalla
|
||||
int mScreenHeight; // Alto de la pantalla
|
||||
int mGameCanvasWidth; // Ancho de la textura donde se dibuja el juego
|
||||
int mGameCanvasHeight; // Alto de la textura donde se dibuja el juego
|
||||
SDL_Rect mDest; // Coordenadas donde se va a dibujar la textura del juego
|
||||
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options);
|
||||
|
||||
// Destructor
|
||||
~Screen();
|
||||
|
||||
// Limpia la pantalla
|
||||
void clean(color_t color);
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
void start();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
void blit();
|
||||
|
||||
// Establece el modo de video
|
||||
void setVideoMode(int fullScreenMode);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -4,13 +4,11 @@
|
||||
// Constructor
|
||||
SmartSprite::SmartSprite()
|
||||
{
|
||||
//init(nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
SmartSprite::~SmartSprite()
|
||||
{
|
||||
//init(nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Inicializador
|
||||
@@ -114,7 +112,7 @@ bool SmartSprite::update()
|
||||
// Comprueba si se desplaza en el eje X hacia la derecha
|
||||
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
|
||||
{
|
||||
// Comprueba si hemos llegado al destino
|
||||
// Comprueba si ha llegado al destino
|
||||
if (getPosX() > mDestX)
|
||||
{
|
||||
// Lo coloca en posición
|
||||
@@ -128,7 +126,7 @@ bool SmartSprite::update()
|
||||
// Comprueba si se desplaza en el eje X hacia la izquierda
|
||||
else if ((getAccelX() < 0) || ((getAccelX() == 0) && (getVelX() < 0)))
|
||||
{
|
||||
// Comprueba si hemos llegado al destino
|
||||
// Comprueba si ha llegado al destino
|
||||
if (getPosX() < mDestX)
|
||||
{
|
||||
// Lo coloca en posición
|
||||
@@ -143,7 +141,7 @@ bool SmartSprite::update()
|
||||
// Comprueba si se desplaza en el eje Y hacia abajo
|
||||
if ((getAccelY() > 0) || ((getAccelY() == 0) && (getVelY() > 0)))
|
||||
{
|
||||
// Comprueba si hemos llegado al destino
|
||||
// Comprueba si ha llegado al destino
|
||||
if (getPosY() > mDestY)
|
||||
{
|
||||
// Lo coloca en posición
|
||||
@@ -157,7 +155,7 @@ bool SmartSprite::update()
|
||||
// Comprueba si se desplaza en el eje Y hacia arriba
|
||||
else if ((getAccelY() < 0) || ((getAccelY() == 0) && (getVelY() < 0)))
|
||||
{
|
||||
// Comprueba si hemos llegado al destino
|
||||
// Comprueba si ha llegado al destino
|
||||
if (getPosY() < mDestY)
|
||||
{
|
||||
// Lo coloca en posición
|
||||
@@ -171,13 +169,9 @@ bool SmartSprite::update()
|
||||
|
||||
// Comprueba si ha llegado a su destino
|
||||
if ((getPosX() == mDestX) && (getPosY() == mDestY))
|
||||
{
|
||||
mIsOnDestination = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mIsOnDestination = false;
|
||||
}
|
||||
|
||||
// Si esta en el destino comprueba su contador
|
||||
if (mIsOnDestination)
|
||||
@@ -185,7 +179,7 @@ bool SmartSprite::update()
|
||||
// Si el contador es mayor que cero, lo decrementa
|
||||
if (mEnabledCounter > 0)
|
||||
{
|
||||
--mEnabledCounter;
|
||||
mEnabledCounter--;
|
||||
}
|
||||
// Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id
|
||||
else if (mEnabledCounter == 0)
|
||||
@@ -215,9 +209,7 @@ bool SmartSprite::isOnDestination()
|
||||
void SmartSprite::render()
|
||||
{
|
||||
if (mEnabled)
|
||||
{
|
||||
MovingSprite::render();
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "animatedsprite.h"
|
||||
|
||||
|
||||
@@ -1,165 +1,183 @@
|
||||
#include "sprite.h"
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite()
|
||||
Sprite::Sprite(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
init(0, 0, 0, 0, nullptr, nullptr);
|
||||
// Establece la posición X,Y del sprite
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
// Establece el puntero al renderizador de la ventana
|
||||
this->renderer = renderer;
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
this->texture = texture;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip = {x, y, w, h};
|
||||
|
||||
// Inicializa variables
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
Sprite::Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece la posición X,Y del sprite
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
|
||||
// Establece el puntero al renderizador de la ventana
|
||||
this->renderer = renderer;
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
this->texture = texture;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip = {x, y, w, h};
|
||||
|
||||
// Inicializa variables
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Sprite::~Sprite()
|
||||
{
|
||||
mTexture = nullptr;
|
||||
mRenderer = nullptr;
|
||||
}
|
||||
|
||||
// Inicializador
|
||||
void Sprite::init(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece la posición X,Y del sprite
|
||||
setPosX(x);
|
||||
setPosY(y);
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
setWidth(w);
|
||||
setHeight(h);
|
||||
|
||||
// Establece el puntero al renderizador de la ventana
|
||||
setRenderer(renderer);
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
setTexture(texture);
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
setSpriteClip(0, 0, w, h);
|
||||
|
||||
// Habilita el objeto
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
// Inicializador
|
||||
void Sprite::init(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece el alto y el ancho del sprite
|
||||
mWidth = rect.w;
|
||||
mHeight = rect.h;
|
||||
|
||||
// Establece la posición X,Y del sprite
|
||||
mPosX = rect.x;
|
||||
mPosY = rect.y;
|
||||
|
||||
// Establece el puntero al renderizador de la ventana
|
||||
setRenderer(renderer);
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
setTexture(texture);
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
setSpriteClip(rect);
|
||||
texture = nullptr;
|
||||
renderer = nullptr;
|
||||
}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void Sprite::render()
|
||||
{
|
||||
if (mEnabled)
|
||||
mTexture->render(mRenderer, mPosX, mPosY, &mSpriteClip);
|
||||
if (enabled)
|
||||
{
|
||||
texture->render(renderer, x, y, &spriteClip);
|
||||
}
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosX()
|
||||
{
|
||||
return mPosX;
|
||||
return x;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosY()
|
||||
{
|
||||
return mPosY;
|
||||
return y;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getWidth()
|
||||
{
|
||||
return mWidth;
|
||||
return w;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getHeight()
|
||||
{
|
||||
return mHeight;
|
||||
return h;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPos(SDL_Rect rect)
|
||||
{
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setPosX(int x)
|
||||
{
|
||||
mPosX = x;
|
||||
this->x = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setPosY(int y)
|
||||
{
|
||||
mPosY = y;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setWidth(int w)
|
||||
{
|
||||
mWidth = w;
|
||||
this->w = w;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setHeight(int h)
|
||||
{
|
||||
mHeight = h;
|
||||
this->h = h;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect Sprite::getSpriteClip()
|
||||
{
|
||||
return mSpriteClip;
|
||||
return spriteClip;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(SDL_Rect rect)
|
||||
{
|
||||
mSpriteClip = rect;
|
||||
spriteClip = rect;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(int x, int y, int w, int h)
|
||||
{
|
||||
mSpriteClip.x = x;
|
||||
mSpriteClip.y = y;
|
||||
mSpriteClip.w = w;
|
||||
mSpriteClip.h = h;
|
||||
spriteClip = {x, y, w, h};
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
LTexture *Sprite::getTexture()
|
||||
{
|
||||
return mTexture;
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setTexture(LTexture *texture)
|
||||
{
|
||||
mTexture = texture;
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
mRenderer = renderer;
|
||||
this->renderer = renderer;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setEnabled(bool value)
|
||||
{
|
||||
mEnabled = value;
|
||||
enabled = value;
|
||||
}
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool Sprite::isEnabled()
|
||||
{
|
||||
return mEnabled;
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect Sprite::getRect()
|
||||
{
|
||||
SDL_Rect rect = {x, y, w, h};
|
||||
return rect;
|
||||
}
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void Sprite::setRect(SDL_Rect rect)
|
||||
{
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "ltexture.h"
|
||||
|
||||
#ifndef SPRITE_H
|
||||
@@ -9,28 +10,25 @@
|
||||
class Sprite
|
||||
{
|
||||
protected:
|
||||
int mPosX; // Posición en el eje X donde dibujar el sprite
|
||||
int mPosY; // Posición en el eje Y donde dibujar el sprite
|
||||
Uint16 mWidth; // Ancho del sprite
|
||||
Uint16 mHeight; // Alto del sprite
|
||||
int x; // Posición en el eje X donde dibujar el sprite
|
||||
int y; // Posición en el eje Y donde dibujar el sprite
|
||||
int w; // Ancho del sprite
|
||||
int h; // Alto del sprite
|
||||
|
||||
SDL_Renderer *mRenderer; // Puntero al renderizador de la ventana
|
||||
LTexture *mTexture; // Textura donde estan todos los dibujos del sprite
|
||||
SDL_Rect mSpriteClip; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
||||
LTexture *texture; // Textura donde estan todos los dibujos del sprite
|
||||
SDL_Rect spriteClip; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
|
||||
bool mEnabled; // Indica si el sprite esta habilitado
|
||||
bool enabled; // Indica si el sprite esta habilitado
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Sprite();
|
||||
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Sprite();
|
||||
|
||||
// Inicializador
|
||||
void init(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *renderer);
|
||||
void init(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render();
|
||||
|
||||
@@ -46,6 +44,9 @@ public:
|
||||
// Obten el valor de la variable
|
||||
int getHeight();
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(int x);
|
||||
|
||||
@@ -81,6 +82,12 @@ public:
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool isEnabled();
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
105
source/text.cpp
105
source/text.cpp
@@ -1,15 +1,16 @@
|
||||
#include "const.h"
|
||||
|
||||
#include "text.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
// Constructor
|
||||
Text::Text(std::string file, LTexture *texture, SDL_Renderer *renderer)
|
||||
Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
||||
{
|
||||
mSprite = new Sprite();
|
||||
mSprite->setTexture(texture);
|
||||
mSprite->setRenderer(renderer);
|
||||
mFile = file;
|
||||
texture = new LTexture(renderer, bitmapFile);
|
||||
sprite = new Sprite({0, 0, 0, 0}, texture, renderer);
|
||||
sprite->setTexture(texture);
|
||||
sprite->setRenderer(renderer);
|
||||
file = textFile;
|
||||
|
||||
init();
|
||||
}
|
||||
@@ -17,71 +18,71 @@ Text::Text(std::string file, LTexture *texture, SDL_Renderer *renderer)
|
||||
// Destructor
|
||||
Text::~Text()
|
||||
{
|
||||
delete mSprite;
|
||||
mSprite = nullptr;
|
||||
delete texture;
|
||||
delete sprite;
|
||||
}
|
||||
|
||||
// Inicializador
|
||||
void Text::init()
|
||||
{
|
||||
// Inicializa a cero el vector con las coordenadas
|
||||
for (int i = 0; i < 128; i++)
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
mOffset[i].x = 0;
|
||||
mOffset[i].y = 0;
|
||||
mOffset[i].w = 0;
|
||||
offset[i].x = 0;
|
||||
offset[i].y = 0;
|
||||
offset[i].w = 0;
|
||||
}
|
||||
|
||||
// Carga los offsets desde el fichero
|
||||
initOffsetFromFile();
|
||||
|
||||
// Inicia los valores del sprite que dibuja las letras
|
||||
mSprite->setWidth(mBoxWidth);
|
||||
mSprite->setHeight(mBoxHeight);
|
||||
mSprite->setPosX(0);
|
||||
mSprite->setPosY(0);
|
||||
mSprite->setSpriteClip(0, 0, mSprite->getWidth(), mSprite->getHeight());
|
||||
sprite->setWidth(boxWidth);
|
||||
sprite->setHeight(boxHeight);
|
||||
sprite->setPosX(0);
|
||||
sprite->setPosY(0);
|
||||
sprite->setSpriteClip(0, 0, sprite->getWidth(), sprite->getHeight());
|
||||
|
||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||
for (int i = 32; i < 128; i++)
|
||||
for (int i = 32; i < 128; ++i)
|
||||
{
|
||||
mOffset[i].x = ((i - 32) % 15) * mBoxWidth;
|
||||
mOffset[i].y = ((i - 32) / 15) * mBoxHeight;
|
||||
offset[i].x = ((i - 32) % 15) * boxWidth;
|
||||
offset[i].y = ((i - 32) / 15) * boxHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
{
|
||||
Uint16 shift = 0;
|
||||
int shift = 0;
|
||||
|
||||
if (lenght == -1)
|
||||
lenght = text.length();
|
||||
|
||||
for (int i = 0; i < lenght; ++i)
|
||||
{
|
||||
mSprite->setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
||||
mSprite->setPosX(x + shift);
|
||||
mSprite->setPosY(y);
|
||||
mSprite->render();
|
||||
shift += (mOffset[int(text[i])].w + kerning);
|
||||
sprite->setSpriteClip(offset[int(text[i])].x, offset[int(text[i])].y, sprite->getWidth(), sprite->getHeight());
|
||||
sprite->setPosX(x + shift);
|
||||
sprite->setPosY(y);
|
||||
sprite->render();
|
||||
shift += (offset[int(text[i])].w + kerning);
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe el texto con colores
|
||||
void Text::writeColored(int x, int y, std::string text, color_t color, int kerning, int lenght)
|
||||
{
|
||||
mSprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
sprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
write(x, y, text, kerning, lenght);
|
||||
mSprite->getTexture()->setColor(255, 255, 255);
|
||||
sprite->getTexture()->setColor(255, 255, 255);
|
||||
}
|
||||
|
||||
// Escribe el texto con sombra
|
||||
void Text::writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance, int kerning, int lenght)
|
||||
{
|
||||
mSprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
sprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
write(x + shadowDistance, y + shadowDistance, text, kerning, lenght);
|
||||
mSprite->getTexture()->setColor(255, 255, 255);
|
||||
sprite->getTexture()->setColor(255, 255, 255);
|
||||
write(x, y, text, kerning, lenght);
|
||||
}
|
||||
|
||||
@@ -112,7 +113,7 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, col
|
||||
writeColored(x - shadowDistance, y + shadowDistance, text, shadowColor, kerning, lenght);
|
||||
writeColored(x + shadowDistance, y - shadowDistance, text, shadowColor, kerning, lenght);
|
||||
writeColored(x - shadowDistance, y - shadowDistance, text, shadowColor, kerning, lenght);
|
||||
|
||||
|
||||
writeColored(x, y + shadowDistance, text, shadowColor, kerning, lenght);
|
||||
writeColored(x, y - shadowDistance, text, shadowColor, kerning, lenght);
|
||||
writeColored(x + shadowDistance, y, text, shadowColor, kerning, lenght);
|
||||
@@ -126,33 +127,35 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, col
|
||||
}
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
Uint16 Text::lenght(std::string text, int kerning)
|
||||
int Text::lenght(std::string text, int kerning)
|
||||
{
|
||||
Uint16 shift = 0;
|
||||
int shift = 0;
|
||||
|
||||
for (int i = 0; i < (int)text.length(); ++i)
|
||||
shift += (mOffset[int(text[i])].w + kerning);
|
||||
shift += (offset[int(text[i])].w + kerning);
|
||||
|
||||
return shift;
|
||||
// Descuenta el kerning del último caracter
|
||||
return shift - kerning;
|
||||
}
|
||||
|
||||
// Inicializa el vector de offsets desde un fichero
|
||||
void Text::initOffsetFromFile()
|
||||
{
|
||||
std::ifstream rfile(mFile);
|
||||
std::ifstream rfile(file);
|
||||
printf("Reading file %s\n", file.c_str());
|
||||
|
||||
if (rfile.is_open() && rfile.good())
|
||||
{
|
||||
std::string buffer;
|
||||
//printf("Reading %s file\n", mFile.c_str());
|
||||
|
||||
// Lee los dos primeros valores del fichero
|
||||
std::getline(rfile, buffer);
|
||||
std::getline(rfile, buffer);
|
||||
mBoxWidth = std::stoi(buffer);
|
||||
boxWidth = std::stoi(buffer);
|
||||
|
||||
std::getline(rfile, buffer);
|
||||
std::getline(rfile, buffer);
|
||||
mBoxHeight = std::stoi(buffer);
|
||||
boxHeight = std::stoi(buffer);
|
||||
|
||||
// lee el resto de datos del fichero
|
||||
int index = 32;
|
||||
@@ -161,17 +164,33 @@ void Text::initOffsetFromFile()
|
||||
{
|
||||
// Almacena solo las lineas impares
|
||||
if (line_read % 2 == 1)
|
||||
mOffset[index++].w = std::stoi(buffer);
|
||||
|
||||
offset[index++].w = std::stoi(buffer);
|
||||
|
||||
// Limpia el buffer
|
||||
buffer.clear();
|
||||
line_read++;
|
||||
};
|
||||
|
||||
// Cierra el fichero
|
||||
printf("Closing file %s\n\n", file.c_str());
|
||||
rfile.close();
|
||||
}
|
||||
|
||||
// El fichero no se puede abrir
|
||||
else
|
||||
{
|
||||
printf("Warning: Unable to open %s file\n", file.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
Uint8 Text::getCharacterWidth()
|
||||
int Text::getCharacterSize()
|
||||
{
|
||||
return mBoxWidth;
|
||||
return boxWidth;
|
||||
}
|
||||
|
||||
// Recarga la textura
|
||||
void Text::reLoadTexture()
|
||||
{
|
||||
texture->reLoad();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "sprite.h"
|
||||
#include "utils.h"
|
||||
|
||||
@@ -14,33 +15,34 @@
|
||||
class Text
|
||||
{
|
||||
private:
|
||||
Sprite *mSprite; // Objeto con los graficos para el texto
|
||||
Sprite *sprite; // Objeto con los graficos para el texto
|
||||
|
||||
struct Offset
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
Uint8 w;
|
||||
int w;
|
||||
};
|
||||
Offset mOffset[128]; // Vector con las posiciones y ancho de cada letra
|
||||
Offset offset[128]; // Vector con las posiciones y ancho de cada letra
|
||||
|
||||
Uint8 mBoxWidth; // Anchura de la caja de cada caracter en el png
|
||||
Uint8 mBoxHeight; // Altura de la caja de cada caracter en el png
|
||||
std::string mFile; // Fichero con los descriptores de la fuente
|
||||
int boxWidth; // Anchura de la caja de cada caracter en el png
|
||||
int boxHeight; // Altura de la caja de cada caracter en el png
|
||||
std::string file; // Fichero con los descriptores de la fuente
|
||||
LTexture *texture; // Textura con los bitmaps del texto
|
||||
|
||||
// Inicializador
|
||||
void init();
|
||||
|
||||
// Inicializa el vector de offsets desde un fichero
|
||||
void initOffsetFromFile();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Text(std::string file, LTexture *texture, SDL_Renderer *renderer);
|
||||
Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Text();
|
||||
|
||||
// Inicializador
|
||||
void init();
|
||||
|
||||
// Escribe el texto en pantalla
|
||||
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||
|
||||
@@ -50,17 +52,20 @@ public:
|
||||
// Escribe el texto con sombra
|
||||
void writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto centrado en un punto x y con kerning
|
||||
// Escribe el texto centrado en un punto x
|
||||
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe texto con extras
|
||||
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = {255, 255, 255}, Uint8 shadowDistance = 1, color_t shadowColor = {0, 0, 0}, int lenght = -1);
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
Uint16 lenght(std::string text, int kerning = 1);
|
||||
int lenght(std::string text, int kerning = 1);
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
Uint8 getCharacterWidth();
|
||||
int getCharacterSize();
|
||||
|
||||
// Recarga la textura
|
||||
void reLoadTexture();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
151
source/title.cpp
151
source/title.cpp
@@ -1,41 +1,41 @@
|
||||
#include "title.h"
|
||||
#ifdef __MIPSEL__
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Title::Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::string *fileList, options_t *options, Lang *lang)
|
||||
Title::Title(SDL_Window *window, SDL_Renderer *renderer, Screen *screen, Input *input, Asset *mAsset, options_t *options, Lang *lang)
|
||||
{
|
||||
// Copia las direcciones de los punteros
|
||||
mWindow = window;
|
||||
mRenderer = renderer;
|
||||
mScreen = screen;
|
||||
mInput = input;
|
||||
mFileList = fileList;
|
||||
this->mAsset = mAsset;
|
||||
mOptions = options;
|
||||
mLang = lang;
|
||||
|
||||
// Reserva memoria para los punteros propios
|
||||
mEventHandler = new SDL_Event();
|
||||
mFade = new Fade(renderer);
|
||||
mTitleTexture = new LTexture();
|
||||
mItemsTexture = new LTexture();
|
||||
mTextTexture = new LTexture();
|
||||
mTextTexture2 = new LTexture();
|
||||
mTitleTexture = new LTexture(mRenderer);
|
||||
mItemsTexture = new LTexture(mRenderer);
|
||||
mTextTexture = new LTexture(mRenderer);
|
||||
mTextTexture2 = new LTexture(mRenderer);
|
||||
mCoffeeBitmap = new SmartSprite();
|
||||
mCrisisBitmap = new SmartSprite();
|
||||
mDustBitmapL = new AnimatedSprite();
|
||||
mDustBitmapR = new AnimatedSprite();
|
||||
mTile = new Sprite();
|
||||
mGradient = new Sprite();
|
||||
mText = new Text(mFileList[48], mTextTexture, mRenderer);
|
||||
mText2 = new Text(mFileList[46], mTextTexture2, mRenderer);
|
||||
mMenu.title = new Menu(mRenderer, mText, mInput, mFileList);
|
||||
mMenu.options = new Menu(mRenderer, mText, mInput, mFileList);
|
||||
mText = new Text(mAsset->get("smb2.txt"), mTextTexture, mRenderer);
|
||||
mText2 = new Text(mAsset->get("8bithud.txt"), mTextTexture2, mRenderer);
|
||||
mMenu.title = new Menu(mRenderer, mText, mInput, mAsset);
|
||||
mMenu.options = new Menu(mRenderer, mText, mInput, mAsset);
|
||||
|
||||
// Crea la textura para el mosaico de fondo
|
||||
mBackground = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2);
|
||||
if (mBackground == NULL)
|
||||
if (mBackground == nullptr)
|
||||
{
|
||||
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -43,8 +43,9 @@ Title::~Title()
|
||||
{
|
||||
mWindow = nullptr;
|
||||
mRenderer = nullptr;
|
||||
mScreen = nullptr;
|
||||
mInput = nullptr;
|
||||
mFileList = nullptr;
|
||||
mAsset = nullptr;
|
||||
mOptions = nullptr;
|
||||
mLang = nullptr;
|
||||
|
||||
@@ -107,12 +108,6 @@ Title::~Title()
|
||||
|
||||
SDL_DestroyTexture(mBackground);
|
||||
mBackground = nullptr;
|
||||
|
||||
mWindow = nullptr;
|
||||
mRenderer = nullptr;
|
||||
mInput = nullptr;
|
||||
mFileList = nullptr;
|
||||
mOptions = nullptr;
|
||||
}
|
||||
|
||||
// Inicializa las variables necesarias para la sección 'Title'
|
||||
@@ -136,22 +131,23 @@ void Title::init(bool demo, Uint8 subsection)
|
||||
mFade->init(0x17, 0x17, 0x26);
|
||||
mDemo = demo;
|
||||
|
||||
//if (!mInput->gameControllerFound())
|
||||
{
|
||||
mOptions->input[0].id = 0;
|
||||
mOptions->input[0].name = "KEYBOARD";
|
||||
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||
// Pone valores por defecto a las opciones de control
|
||||
mOptions->input[0].id = 0;
|
||||
mOptions->input[0].name = "KEYBOARD";
|
||||
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||
|
||||
mOptions->input[1].id = 0;
|
||||
mOptions->input[1].name = "GAME CONTROLLER";
|
||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
}
|
||||
mOptions->input[1].id = 0;
|
||||
mOptions->input[1].name = "GAME CONTROLLER";
|
||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
|
||||
// Comprueba si hay mandos conectados
|
||||
checkInputDevices();
|
||||
|
||||
mDeviceIndex[0] = mAvailableInputDevices.size() - 1;
|
||||
mDeviceIndex[1] = 0;
|
||||
// Pone valores por defecto
|
||||
mDeviceIndex[0] = mAvailableInputDevices.size() - 1; // El último dispositivo encontrado es el teclado
|
||||
mDeviceIndex[1] = 0; // El primer mando encontrado. Si no ha encontrado ninguno es el teclado
|
||||
|
||||
// Si ha encontrado un mando se lo asigna al segundo jugador
|
||||
if (mInput->gameControllerFound())
|
||||
{
|
||||
mOptions->input[1].id = mAvailableInputDevices[mDeviceIndex[1]].id;
|
||||
@@ -244,6 +240,7 @@ void Title::init(bool demo, Uint8 subsection)
|
||||
// Crea el mosaico de fondo del titulo
|
||||
createTiledBackground();
|
||||
|
||||
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida con el mosaico que hay pintado en el titulo al iniciar
|
||||
mBackgroundWindow.x = 128;
|
||||
mBackgroundWindow.y = 96;
|
||||
mBackgroundWindow.w = SCREEN_WIDTH;
|
||||
@@ -251,9 +248,7 @@ void Title::init(bool demo, Uint8 subsection)
|
||||
|
||||
// Inicializa los valores del vector con los valores del seno
|
||||
for (int i = 0; i < 360; i++)
|
||||
{
|
||||
mSin[i] = SDL_sinf((float)i * 3.14f / 180.0f);
|
||||
}
|
||||
|
||||
// Inicializa los objetos de menu
|
||||
mMenu.title->init("TITLE", 0, (14 * BLOCK) + 4, MENU_BACKGROUND_TRANSPARENT);
|
||||
@@ -301,16 +296,16 @@ bool Title::loadMedia()
|
||||
bool success = true;
|
||||
|
||||
// Texturas
|
||||
success &= loadTextureFromFile(mTitleTexture, mFileList[40], mRenderer);
|
||||
success &= loadTextureFromFile(mItemsTexture, mFileList[34], mRenderer);
|
||||
success &= loadTextureFromFile(mTextTexture, mFileList[30], mRenderer);
|
||||
success &= loadTextureFromFile(mTextTexture2, mFileList[27], mRenderer);
|
||||
success &= loadTextureFromFile(mTitleTexture, mAsset->get("title.png"), mRenderer);
|
||||
success &= loadTextureFromFile(mItemsTexture, mAsset->get("items.png"), mRenderer);
|
||||
success &= loadTextureFromFile(mTextTexture, mAsset->get("smb2.png"), mRenderer);
|
||||
success &= loadTextureFromFile(mTextTexture2, mAsset->get("8bithud.png"), mRenderer);
|
||||
|
||||
// Sonidos
|
||||
mSound = JA_LoadSound(mFileList[21].c_str());
|
||||
mSound = JA_LoadSound(mAsset->get("title.wav").c_str());
|
||||
|
||||
// Musicas
|
||||
mMusic = JA_LoadMusic(mFileList[5].c_str());
|
||||
mMusic = JA_LoadMusic(mAsset->get("title.ogg").c_str());
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -380,7 +375,6 @@ void Title::updateMenuLabels()
|
||||
else
|
||||
{
|
||||
mMenu.options->setGreyed(i, false);
|
||||
//mMenu.options->setItemCaption(i, mInput->getControllerName(0));
|
||||
mMenu.options->setItemCaption(i, mOptions->input[0].name);
|
||||
}
|
||||
break;
|
||||
@@ -410,7 +404,6 @@ void Title::updateMenuLabels()
|
||||
else
|
||||
{
|
||||
mMenu.options->setGreyed(i, false);
|
||||
//mMenu.options->setItemCaption(i, mInput->getControllerName(0));
|
||||
mMenu.options->setItemCaption(i, mOptions->input[1].name);
|
||||
}
|
||||
break;
|
||||
@@ -496,15 +489,18 @@ void Title::updateMenuLabels()
|
||||
// CANCEL
|
||||
mMenu.options->setItemCaption(i, mLang->getText(10)); // CANCEL
|
||||
|
||||
// Recoloca el menu de opciones
|
||||
mMenu.options->centerMenuOnX(SCREEN_CENTER_X);
|
||||
mMenu.options->centerMenuOnY(SCREEN_CENTER_Y);
|
||||
mMenu.options->centerMenuElementsOnX();
|
||||
|
||||
// Establece las etiquetas del menu de titulo
|
||||
mMenu.title->setItemCaption(0, mLang->getText(51)); // 1 PLAYER
|
||||
mMenu.title->setItemCaption(1, mLang->getText(52)); // 2 PLAYERS
|
||||
mMenu.title->setItemCaption(2, mLang->getText(1)); // OPTIONS
|
||||
mMenu.title->setItemCaption(3, mLang->getText(3)); // QUIT
|
||||
|
||||
// Recoloca el menu de titulo
|
||||
mMenu.title->centerMenuOnX(SCREEN_CENTER_X);
|
||||
mMenu.title->centerMenuElementsOnX();
|
||||
}
|
||||
@@ -512,8 +508,8 @@ void Title::updateMenuLabels()
|
||||
// Aplica las opciones de menu seleccionadas
|
||||
void Title::applyOptions()
|
||||
{
|
||||
SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
|
||||
SDL_SetWindowSize(mWindow, SCREEN_WIDTH * mOptions->windowSize, SCREEN_HEIGHT * mOptions->windowSize);
|
||||
mScreen->setVideoMode(mOptions->fullScreenMode);
|
||||
|
||||
mLang->setLang(mOptions->language);
|
||||
|
||||
updateMenuLabels();
|
||||
@@ -552,12 +548,14 @@ section_t Title::run(Uint8 subsection)
|
||||
mCrisisBitmap->update();
|
||||
}
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
mScreen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(mRenderer);
|
||||
mScreen->clean(bgColor);
|
||||
|
||||
// Dibuja el tileado de fondo
|
||||
SDL_RenderCopy(mRenderer, mBackground, &mBackgroundWindow, NULL);
|
||||
SDL_RenderCopy(mRenderer, mBackground, &mBackgroundWindow, nullptr);
|
||||
|
||||
// Dibuja el degradado
|
||||
mGradient->render();
|
||||
@@ -566,8 +564,8 @@ section_t Title::run(Uint8 subsection)
|
||||
mCoffeeBitmap->render();
|
||||
mCrisisBitmap->render();
|
||||
|
||||
// Actualiza la pantalla
|
||||
SDL_RenderPresent(mRenderer);
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
mScreen->blit();
|
||||
|
||||
// Si los objetos han llegado a su destino, cambiamos de Sección
|
||||
if ((mEvents[0] == EVENT_COMPLETED) && (mEvents[0] == EVENT_COMPLETED))
|
||||
@@ -604,12 +602,14 @@ section_t Title::run(Uint8 subsection)
|
||||
int b = mCrisisBitmap->getPosX();
|
||||
for (int n = 0; n < 11 * 3; n++)
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
mScreen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(mRenderer);
|
||||
mScreen->clean(bgColor);
|
||||
|
||||
// Dibuja el tileado de fondo
|
||||
SDL_RenderCopy(mRenderer, mBackground, &mBackgroundWindow, NULL);
|
||||
SDL_RenderCopy(mRenderer, mBackground, &mBackgroundWindow, nullptr);
|
||||
|
||||
// Dibuja el degradado
|
||||
mGradient->render();
|
||||
@@ -624,8 +624,8 @@ section_t Title::run(Uint8 subsection)
|
||||
mDustBitmapR->render();
|
||||
mDustBitmapL->render();
|
||||
|
||||
// Actualiza la pantalla
|
||||
SDL_RenderPresent(mRenderer);
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
mScreen->blit();
|
||||
}
|
||||
|
||||
mSection.subsection = TITLE_SECTION_3;
|
||||
@@ -655,10 +655,7 @@ section_t Title::run(Uint8 subsection)
|
||||
|
||||
// Si la música no está sonando
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
{
|
||||
// Reproduce la música
|
||||
JA_PlayMusic(mMusic);
|
||||
}
|
||||
JA_PlayMusic(mMusic); // Reproduce la música
|
||||
|
||||
// Calcula la lógica de los objetos
|
||||
if (SDL_GetTicks() - mTicks > mTicksSpeed)
|
||||
@@ -842,17 +839,17 @@ section_t Title::run(Uint8 subsection)
|
||||
}
|
||||
|
||||
if (mMenu.active->getName() == "TITLE")
|
||||
{
|
||||
mCounter--;
|
||||
}
|
||||
}
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
mScreen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(mRenderer);
|
||||
mScreen->clean(bgColor);
|
||||
|
||||
// Dibuja el tileado de fondo
|
||||
SDL_RenderCopy(mRenderer, mBackground, &mBackgroundWindow, NULL);
|
||||
SDL_RenderCopy(mRenderer, mBackground, &mBackgroundWindow, nullptr);
|
||||
|
||||
// Dibuja el degradado
|
||||
mGradient->render();
|
||||
@@ -869,7 +866,9 @@ section_t Title::run(Uint8 subsection)
|
||||
}
|
||||
|
||||
if (mMenuVisible == true)
|
||||
{
|
||||
mMenu.active->render();
|
||||
}
|
||||
|
||||
mDustBitmapR->animate(0);
|
||||
mDustBitmapL->animate(0);
|
||||
@@ -878,13 +877,15 @@ section_t Title::run(Uint8 subsection)
|
||||
|
||||
// PRESS ANY KEY!
|
||||
if ((mCounter % 50 > 14) && (mMenuVisible == false))
|
||||
{
|
||||
mText->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, PLAY_AREA_THIRD_QUARTER_Y + BLOCK, mLang->getText(23), 1, noColor, 1, shdwTxtColor);
|
||||
}
|
||||
|
||||
// Fade
|
||||
mFade->render();
|
||||
|
||||
// Actualiza la pantalla
|
||||
SDL_RenderPresent(mRenderer);
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
mScreen->blit();
|
||||
}
|
||||
else if (mCounter == 0)
|
||||
{
|
||||
@@ -913,7 +914,7 @@ section_t Title::run(Uint8 subsection)
|
||||
// Ejecuta la parte donde se muestran las instrucciones
|
||||
void Title::runInstructions(Uint8 mode)
|
||||
{
|
||||
mInstructions = new Instructions(mRenderer, mFileList, mLang);
|
||||
mInstructions = new Instructions(mRenderer, mScreen, mAsset, mLang);
|
||||
mInstructions->run(mode);
|
||||
delete mInstructions;
|
||||
}
|
||||
@@ -921,7 +922,7 @@ void Title::runInstructions(Uint8 mode)
|
||||
// Ejecuta el juego en modo demo
|
||||
void Title::runDemoGame()
|
||||
{
|
||||
mDemoGame = new Game(1, mRenderer, mFileList, mLang, mInput, true, mOptions);
|
||||
mDemoGame = new Game(1, 0, mRenderer, mScreen, mAsset, mLang, mInput, true, mOptions);
|
||||
mDemoGame->run();
|
||||
delete mDemoGame;
|
||||
}
|
||||
@@ -949,29 +950,23 @@ bool Title::updatePlayerInputs(int numPlayer)
|
||||
}
|
||||
else // Si hay mas de un dispositivo, se recorre el vector
|
||||
{
|
||||
printf("numplayer:%i\n",numPlayer);
|
||||
printf("deviceindex:%i\n",mDeviceIndex[numPlayer]);
|
||||
printf("numplayer:%i\n", numPlayer);
|
||||
printf("deviceindex:%i\n", mDeviceIndex[numPlayer]);
|
||||
|
||||
// Incrementa el indice
|
||||
if (mDeviceIndex[numPlayer] < numDevices - 1)
|
||||
mDeviceIndex[numPlayer]++;
|
||||
else
|
||||
mDeviceIndex[numPlayer] = 0;
|
||||
printf("deviceindex:%i\n",mDeviceIndex[numPlayer]);
|
||||
printf("deviceindex:%i\n", mDeviceIndex[numPlayer]);
|
||||
|
||||
// Si coincide con el del otro jugador, se lo intercambian
|
||||
if (mDeviceIndex[0] == mDeviceIndex[1])
|
||||
{
|
||||
printf("%i:%i\n",mDeviceIndex[0],mDeviceIndex[1]);
|
||||
|
||||
//const int temp = mDeviceIndex[0];
|
||||
//mDeviceIndex[0] = mDeviceIndex[1];
|
||||
//mDeviceIndex[1] = temp;
|
||||
const int theOtherPlayer = (numPlayer + 1) % 2;
|
||||
mDeviceIndex[theOtherPlayer]--;
|
||||
if (mDeviceIndex[theOtherPlayer] < 0)
|
||||
mDeviceIndex[theOtherPlayer]=numDevices-1;
|
||||
printf("%i:%i\n",mDeviceIndex[0],mDeviceIndex[1]);
|
||||
mDeviceIndex[theOtherPlayer] = numDevices - 1;
|
||||
}
|
||||
|
||||
// Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador
|
||||
|
||||
@@ -1,29 +1,41 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include "const.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "sprite.h"
|
||||
#include "movingsprite.h"
|
||||
#include "smartsprite.h"
|
||||
|
||||
#include "item.h"
|
||||
#include "text.h"
|
||||
#include "menu.h"
|
||||
#include "fade.h"
|
||||
#include "game.h"
|
||||
#include "input.h"
|
||||
#include "instructions.h"
|
||||
#include "game.h"
|
||||
#include "item.h"
|
||||
#include "jail_audio.h"
|
||||
#include "menu.h"
|
||||
#include "movingsprite.h"
|
||||
#include "screen.h"
|
||||
#include "smartsprite.h"
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef TITLE_H
|
||||
#define TITLE_H
|
||||
|
||||
// Title
|
||||
// Textos
|
||||
#define TEXT_COPYRIGHT "@2020,2022 JailDesigner (v2.1)"
|
||||
|
||||
// Contadores
|
||||
#define TITLE_COUNTER 800
|
||||
|
||||
// Cantidad de eventos de la pantalla de titulo
|
||||
#define TITLE_TOTAL_EVENTS 2
|
||||
|
||||
// Clase Title
|
||||
class Title
|
||||
{
|
||||
private:
|
||||
SDL_Window *mWindow; // Ventana de la aplicación
|
||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
||||
AnimatedSprite *mDustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||
AnimatedSprite *mDustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||
bool mMenuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente
|
||||
@@ -36,13 +48,12 @@ private:
|
||||
LTexture *mTextTexture2; // Textura con los gráficos para el texto
|
||||
SDL_Event *mEventHandler; // Manejador de eventos
|
||||
SDL_Rect mBackgroundWindow; // Ventana visible para la textura de fondo del titulo
|
||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||
SDL_Texture *mBackground; // Textura dibujar el fondo del titulo
|
||||
SmartSprite *mCoffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo
|
||||
SmartSprite *mCrisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo
|
||||
Sprite *mTile; // Sprite para dibujar el fondo de pantalla del título
|
||||
Sprite *mGradient; // Sprite para dibujar el degradado del titulo
|
||||
std::string *mFileList; // Lista de ficheros
|
||||
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
Uint16 mBackgroundCounter; // Temporizador para el fondo de tiles de la pantalla de titulo
|
||||
Uint16 mCounter; // Temporizador para la pantalla de titulo
|
||||
@@ -70,10 +81,10 @@ private:
|
||||
};
|
||||
menu_t mMenu; // Variable con todos los objetos menus y sus variables
|
||||
|
||||
struct options_t *mOptions; // Variable con todas las variables de las opciones del programa
|
||||
options_t mOptionsPrevious; // Variable de respaldo para las opciones
|
||||
struct options_t *mOptions; // Variable con todas las variables de las opciones del programa
|
||||
options_t mOptionsPrevious; // Variable de respaldo para las opciones
|
||||
std::vector<input_t> mAvailableInputDevices; // Vector con todos los metodos de control disponibles
|
||||
int mDeviceIndex[2]; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
|
||||
int mDeviceIndex[2]; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
|
||||
|
||||
// Carga los recursos necesarios para la sección 'Title'
|
||||
bool loadMedia();
|
||||
@@ -104,7 +115,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::string *fileList, options_t *options, Lang *lang);
|
||||
Title(SDL_Window *window, SDL_Renderer *renderer, Screen *screen, Input *input, Asset *mAsset, options_t *options, Lang *lang);
|
||||
|
||||
// Destructor
|
||||
~Title();
|
||||
|
||||
@@ -17,10 +17,7 @@ bool checkCollision(circle_t &a, circle_t &b)
|
||||
|
||||
// Si la distancia entre el centro de los circulos es inferior a la suma de sus radios
|
||||
if (distanceSquared(a.x, a.y, b.x, b.y) < (totalRadiusSquared))
|
||||
{
|
||||
// Los circulos han colisionado
|
||||
return true;
|
||||
}
|
||||
return true; // Los circulos han colisionado
|
||||
|
||||
// En caso contrario
|
||||
return false;
|
||||
@@ -114,11 +111,11 @@ bool checkCollision(SDL_Rect &a, SDL_Rect &b)
|
||||
// Carga un archivo de imagen en una textura
|
||||
bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer)
|
||||
{
|
||||
bool success = true;
|
||||
if (!texture->loadFromFile(path, renderer))
|
||||
{
|
||||
printf("Failed to load %s texture!\n", path.c_str());
|
||||
success = false;
|
||||
}
|
||||
return success;
|
||||
bool success = true;
|
||||
if (!texture->loadFromFile(path, renderer))
|
||||
{
|
||||
printf("Failed to load %s texture!\n", path.c_str());
|
||||
success = false;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -1,11 +1,21 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "ltexture.h"
|
||||
#include <string>
|
||||
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
// Dificultad del juego
|
||||
#define DIFFICULTY_EASY 0
|
||||
#define DIFFICULTY_NORMAL 1
|
||||
#define DIFFICULTY_HARD 2
|
||||
|
||||
// Tipo de filtro
|
||||
#define FILTER_NEAREST 0
|
||||
#define FILTER_LINEAL 1
|
||||
|
||||
// Estructura para definir un circulo
|
||||
struct circle_t
|
||||
{
|
||||
@@ -55,9 +65,13 @@ struct options_t
|
||||
input_t input[2]; // Modo de control (teclado o mando)
|
||||
Uint8 language; // Idioma usado en el juego
|
||||
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
|
||||
Uint8 windowSize; // Contiene el valor del tamaño de la ventana
|
||||
Uint8 windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
||||
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||
bool vSync; // Indica si se quiere usar vsync o no
|
||||
int screenWidth; // Ancho de la pantalla/ventana
|
||||
int screenHeight; // Alto de la pantalla/ventana
|
||||
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
||||
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||
};
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
|
||||
@@ -134,9 +134,7 @@ void Writer::update()
|
||||
void Writer::render()
|
||||
{
|
||||
if (mEnabled)
|
||||
{
|
||||
mText->write(mPosX, mPosY, mCaption, mKerning, mIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Centra la cadena de texto a un punto X
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
|
||||
#ifndef WRITER_H
|
||||
#define WRITER_H
|
||||
|
||||
// Clase texto. Pinta texto en pantalla a partir de un bitmap
|
||||
// Clase Writer. Pinta texto en pantalla a partir de una cadena y un bitmap
|
||||
class Writer
|
||||
{
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user