Reorganizados los .cpp i .h en la carpeta common
This commit is contained in:
12
Makefile
12
Makefile
@@ -1,17 +1,15 @@
|
|||||||
executable = volcano_2022
|
executable = volcano_2022
|
||||||
|
source = source/*.cpp source/common/*.cpp
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
@echo off
|
@echo off
|
||||||
if not exist bin\ (mkdir bin)
|
if not exist bin\ (mkdir bin)
|
||||||
g++ -std=c++11 -Wall -O2 source/*.cpp -lmingw32 -lSDL2main -lSDL2 -o bin/$(executable).exe
|
g++ $(source) -std=c++11 -Wall -O2 -lmingw32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o bin/$(executable).exe
|
||||||
|
strip -s -R .comment -R .gnu.version bin/$(executable).exe --strip-unneeded
|
||||||
macos:
|
macos:
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
g++ source/*.cpp -std=c++11 -Wall -O2 -lSDL2 -o bin/$(executable)_macos
|
g++ $(source) -std=c++11 -Wall -O2 -lSDL2 -ffunction-sections -fdata-sections -o bin/$(executable)_macos
|
||||||
linux:
|
linux:
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
g++ source/*.cpp -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o bin/$(executable)_linux
|
g++ $(source) -std=c++11 -Wall -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,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "common/animatedsprite.h"
|
||||||
#include "asset.h"
|
#include "common/asset.h"
|
||||||
#include "animatedsprite.h"
|
#include "common/utils.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifndef ACTOR_H
|
#ifndef ACTOR_H
|
||||||
|
|||||||
@@ -1,287 +0,0 @@
|
|||||||
|
|
||||||
#include "animatedsprite.h"
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::string file)
|
|
||||||
{
|
|
||||||
// Copia los punteros
|
|
||||||
setTexture(texture);
|
|
||||||
setRenderer(renderer);
|
|
||||||
|
|
||||||
// Carga las animaciones
|
|
||||||
load(file);
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
currentAnimation = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
AnimatedSprite::~AnimatedSprite()
|
|
||||||
{
|
|
||||||
for (auto &a : animation)
|
|
||||||
{
|
|
||||||
a.frames.clear();
|
|
||||||
}
|
|
||||||
animation.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el indice de la animación a partir del nombre
|
|
||||||
int AnimatedSprite::getIndex(std::string name)
|
|
||||||
{
|
|
||||||
int index = -1;
|
|
||||||
|
|
||||||
for (auto a : animation)
|
|
||||||
{
|
|
||||||
index++;
|
|
||||||
if (a.name == name)
|
|
||||||
{
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("** Warning: could not find \"%s\" animation\n", name.c_str());
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula el frame correspondiente a la animación
|
|
||||||
void AnimatedSprite::animate()
|
|
||||||
{
|
|
||||||
if (!enabled || animation[currentAnimation].speed == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // 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(int 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(std::string name, int 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 si la animación se reproduce en bucle
|
|
||||||
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
|
||||||
{
|
|
||||||
animation[getIndex(name)].loop = loop;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
|
||||||
{
|
|
||||||
animation[getIndex(name)].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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
|
||||||
void AnimatedSprite::update()
|
|
||||||
{
|
|
||||||
animate();
|
|
||||||
MovingSprite::update();
|
|
||||||
}
|
|
||||||
504
source/common/animatedsprite.cpp
Normal file
504
source/common/animatedsprite.cpp
Normal file
@@ -0,0 +1,504 @@
|
|||||||
|
#include "animatedsprite.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer)
|
||||||
|
{
|
||||||
|
// Copia los punteros
|
||||||
|
setTexture(texture);
|
||||||
|
setRenderer(renderer);
|
||||||
|
|
||||||
|
// Carga las animaciones
|
||||||
|
if (file != "")
|
||||||
|
{
|
||||||
|
loadFromFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (buffer)
|
||||||
|
{
|
||||||
|
loadFromVector(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
currentAnimation = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
AnimatedSprite::~AnimatedSprite()
|
||||||
|
{
|
||||||
|
for (auto &a : animation)
|
||||||
|
{
|
||||||
|
a.frames.clear();
|
||||||
|
}
|
||||||
|
animation.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el indice de la animación a partir del nombre
|
||||||
|
int AnimatedSprite::getIndex(std::string name)
|
||||||
|
{
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
|
for (auto a : animation)
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
if (a.name == name)
|
||||||
|
{
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("** Warning: could not find \"%s\" animation\n", name.c_str());
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcula el frame correspondiente a la animación
|
||||||
|
void AnimatedSprite::animate()
|
||||||
|
{
|
||||||
|
if (!enabled || animation.at(currentAnimation).speed == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcula el frame actual a partir del contador
|
||||||
|
animation.at(currentAnimation).currentFrame = animation.at(currentAnimation).counter / animation.at(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.at(currentAnimation).currentFrame >= (int)animation.at(currentAnimation).frames.size())
|
||||||
|
{
|
||||||
|
if (animation.at(currentAnimation).loop == -1)
|
||||||
|
{ // Si no hay loop, deja el último frame
|
||||||
|
animation.at(currentAnimation).currentFrame = animation.at(currentAnimation).frames.size();
|
||||||
|
animation.at(currentAnimation).completed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Si hay loop, vuelve al frame indicado
|
||||||
|
animation.at(currentAnimation).counter = 0;
|
||||||
|
animation.at(currentAnimation).currentFrame = animation.at(currentAnimation).loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// En caso contrario
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Escoge el frame correspondiente de la animación
|
||||||
|
setSpriteClip(animation.at(currentAnimation).frames.at(animation.at(currentAnimation).currentFrame));
|
||||||
|
|
||||||
|
// Incrementa el contador de la animacion
|
||||||
|
animation.at(currentAnimation).counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el frame actual de la animación
|
||||||
|
void AnimatedSprite::setCurrentFrame(int num)
|
||||||
|
{
|
||||||
|
// Descarta valores fuera de rango
|
||||||
|
if (num >= (int)animation.at(currentAnimation).frames.size())
|
||||||
|
{
|
||||||
|
num = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el valor de la variable
|
||||||
|
animation.at(currentAnimation).counter = animation.at(currentAnimation).speed * num;
|
||||||
|
|
||||||
|
// Escoge el frame correspondiente de la animación
|
||||||
|
setSpriteClip(animation.at(currentAnimation).frames.at(animation.at(currentAnimation).currentFrame));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor del contador
|
||||||
|
void AnimatedSprite::setAnimationCounter(std::string name, int num)
|
||||||
|
{
|
||||||
|
animation.at(getIndex(name)).counter = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la velocidad de una animación
|
||||||
|
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
|
||||||
|
{
|
||||||
|
animation.at(getIndex(name)).counter = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la velocidad de una animación
|
||||||
|
void AnimatedSprite::setAnimationSpeed(int index, int speed)
|
||||||
|
{
|
||||||
|
animation.at(index).counter = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece si la animación se reproduce en bucle
|
||||||
|
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
||||||
|
{
|
||||||
|
animation.at(getIndex(name)).loop = loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece si la animación se reproduce en bucle
|
||||||
|
void AnimatedSprite::setAnimationLoop(int index, int loop)
|
||||||
|
{
|
||||||
|
animation.at(index).loop = loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
||||||
|
{
|
||||||
|
animation.at(getIndex(name)).completed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD - Establece el valor de la variable
|
||||||
|
void AnimatedSprite::setAnimationCompleted(int index, bool value)
|
||||||
|
{
|
||||||
|
animation.at(index).completed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha terminado la animación
|
||||||
|
bool AnimatedSprite::animationIsCompleted()
|
||||||
|
{
|
||||||
|
return animation.at(currentAnimation).completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
|
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
|
||||||
|
{
|
||||||
|
return animation.at(getIndex(name)).frames.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
|
SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
||||||
|
{
|
||||||
|
return animation.at(indexA).frames.at(indexF);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga la animación desde un fichero
|
||||||
|
bool AnimatedSprite::loadFromFile(std::string filePath)
|
||||||
|
{
|
||||||
|
int framesPerRow = 0;
|
||||||
|
int frameWidth = 0;
|
||||||
|
int frameHeight = 0;
|
||||||
|
int maxTiles = 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
|
||||||
|
std::cout << "Loading animation from file: " << filePath.c_str() << std::endl;
|
||||||
|
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, frameWidth, frameHeight};
|
||||||
|
while (getline(ss, tmp, ','))
|
||||||
|
{
|
||||||
|
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||||
|
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
|
||||||
|
rect.x = (numTile % framesPerRow) * frameWidth;
|
||||||
|
rect.y = (numTile / framesPerRow) * frameHeight;
|
||||||
|
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) == "framesPerRow")
|
||||||
|
{
|
||||||
|
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "frameWidth")
|
||||||
|
{
|
||||||
|
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "frameHeight")
|
||||||
|
{
|
||||||
|
frameHeight = 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normaliza valores
|
||||||
|
if (framesPerRow == 0 && frameWidth > 0)
|
||||||
|
{
|
||||||
|
framesPerRow = texture->getWidth() / frameWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxTiles == 0 && frameWidth > 0 && frameHeight > 0)
|
||||||
|
{
|
||||||
|
const int w = texture->getWidth() / frameWidth;
|
||||||
|
const int h = texture->getHeight() / frameHeight;
|
||||||
|
maxTiles = w * h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
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, frameWidth, frameHeight});
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga la animación desde un vector
|
||||||
|
bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||||
|
{
|
||||||
|
// Inicializa variables
|
||||||
|
int framesPerRow = 0;
|
||||||
|
int frameWidth = 0;
|
||||||
|
int frameHeight = 0;
|
||||||
|
int maxTiles = 0;
|
||||||
|
|
||||||
|
// Indicador de éxito en el proceso
|
||||||
|
bool success = true;
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
// Recorre todo el vector
|
||||||
|
int index = 0;
|
||||||
|
while (index < (int)source->size())
|
||||||
|
{
|
||||||
|
// Lee desde el vector
|
||||||
|
line = source->at(index);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
{
|
||||||
|
// Aumenta el indice para leer la siguiente linea
|
||||||
|
index++;
|
||||||
|
line = source->at(index);
|
||||||
|
|
||||||
|
// 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, frameWidth, frameHeight};
|
||||||
|
while (getline(ss, tmp, ','))
|
||||||
|
{
|
||||||
|
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||||
|
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
|
||||||
|
rect.x = (numTile % framesPerRow) * frameWidth;
|
||||||
|
rect.y = (numTile / framesPerRow) * frameHeight;
|
||||||
|
buffer.frames.push_back(rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||||
|
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) == "framesPerRow")
|
||||||
|
{
|
||||||
|
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "frameWidth")
|
||||||
|
{
|
||||||
|
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line.substr(0, pos) == "frameHeight")
|
||||||
|
{
|
||||||
|
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normaliza valores
|
||||||
|
if (framesPerRow == 0 && frameWidth > 0)
|
||||||
|
{
|
||||||
|
framesPerRow = texture->getWidth() / frameWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxTiles == 0 && frameWidth > 0 && frameHeight > 0)
|
||||||
|
{
|
||||||
|
const int w = texture->getWidth() / frameWidth;
|
||||||
|
const int h = texture->getHeight() / frameHeight;
|
||||||
|
maxTiles = w * h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Una vez procesada la linea, aumenta el indice para pasar a la siguiente
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pone un valor por defecto
|
||||||
|
setPos({0, 0, frameWidth, frameHeight});
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la animacion actual
|
||||||
|
void AnimatedSprite::setCurrentAnimation(std::string name)
|
||||||
|
{
|
||||||
|
const int newAnimation = getIndex(name);
|
||||||
|
if (currentAnimation != newAnimation)
|
||||||
|
{
|
||||||
|
currentAnimation = newAnimation;
|
||||||
|
animation.at(currentAnimation).currentFrame = 0;
|
||||||
|
animation.at(currentAnimation).counter = 0;
|
||||||
|
animation.at(currentAnimation).completed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la animacion actual
|
||||||
|
void AnimatedSprite::setCurrentAnimation(int index)
|
||||||
|
{
|
||||||
|
const int newAnimation = index;
|
||||||
|
if (currentAnimation != newAnimation)
|
||||||
|
{
|
||||||
|
currentAnimation = newAnimation;
|
||||||
|
animation.at(currentAnimation).currentFrame = 0;
|
||||||
|
animation.at(currentAnimation).counter = 0;
|
||||||
|
animation.at(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)
|
||||||
|
{
|
||||||
|
animation.at(index_animation).frames.push_back({x, y, w, h});
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD - Establece el contador para todas las animaciones
|
||||||
|
void AnimatedSprite::setAnimationCounter(int value)
|
||||||
|
{
|
||||||
|
for (auto &a : animation)
|
||||||
|
{
|
||||||
|
a.counter = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reinicia la animación
|
||||||
|
void AnimatedSprite::resetAnimation()
|
||||||
|
{
|
||||||
|
animation.at(currentAnimation).currentFrame = 0;
|
||||||
|
animation.at(currentAnimation).counter = 0;
|
||||||
|
animation.at(currentAnimation).completed = false;
|
||||||
|
}
|
||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "movingsprite.h"
|
#include "movingsprite.h"
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifndef ANIMATEDSPRITE_H
|
#ifndef ANIMATEDSPRITE_H
|
||||||
#define ANIMATEDSPRITE_H
|
#define ANIMATEDSPRITE_H
|
||||||
@@ -29,7 +30,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "");
|
AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~AnimatedSprite();
|
~AnimatedSprite();
|
||||||
@@ -45,30 +46,47 @@ public:
|
|||||||
|
|
||||||
// Establece la velocidad de una animación
|
// Establece la velocidad de una animación
|
||||||
void setAnimationSpeed(std::string name, int speed);
|
void setAnimationSpeed(std::string name, int speed);
|
||||||
|
void setAnimationSpeed(int index, int speed);
|
||||||
|
|
||||||
// Establece el frame al que vuelve la animación al finalizar
|
// Establece el frame al que vuelve la animación al finalizar
|
||||||
void setAnimationLoop(std::string name, int loop);
|
void setAnimationLoop(std::string name, int loop);
|
||||||
|
void setAnimationLoop(int index, int loop);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setAnimationCompleted(std::string name, bool value);
|
void setAnimationCompleted(std::string name, bool value);
|
||||||
|
void setAnimationCompleted(int index, bool value);
|
||||||
|
|
||||||
// Comprueba si ha terminado la animación
|
// Comprueba si ha terminado la animación
|
||||||
bool animationIsCompleted();
|
bool animationIsCompleted();
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
SDL_Rect getAnimationClip(std::string name, Uint8 index);
|
SDL_Rect getAnimationClip(std::string name, Uint8 index);
|
||||||
|
SDL_Rect getAnimationClip(int indexA, Uint8 indexF);
|
||||||
|
|
||||||
// Obtiene el indice de la animación a partir del nombre
|
// Obtiene el indice de la animación a partir del nombre
|
||||||
int getIndex(std::string name);
|
int getIndex(std::string name);
|
||||||
|
|
||||||
// Carga la animación desde un fichero
|
// Carga la animación desde un fichero
|
||||||
bool load(std::string filePath);
|
bool loadFromFile(std::string filePath);
|
||||||
|
|
||||||
|
// Carga la animación desde un vector
|
||||||
|
bool loadFromVector(std::vector<std::string> *source);
|
||||||
|
|
||||||
// Establece la animacion actual
|
// Establece la animacion actual
|
||||||
void setCurrentAnimation(std::string name = "default");
|
void setCurrentAnimation(std::string name = "default");
|
||||||
|
void setCurrentAnimation(int index = 0);
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void update();
|
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);
|
||||||
|
|
||||||
|
// Reinicia la animación
|
||||||
|
void resetAnimation();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
Asset::Asset(std::string path)
|
Asset::Asset(std::string path)
|
||||||
{
|
{
|
||||||
executablePath = path;
|
executablePath = path;
|
||||||
longest_name = 0;
|
longestName = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -16,13 +16,13 @@ Asset::~Asset()
|
|||||||
void Asset::add(std::string file, enum assetType type, bool required)
|
void Asset::add(std::string file, enum assetType type, bool required)
|
||||||
{
|
{
|
||||||
item_t temp;
|
item_t temp;
|
||||||
temp.file = executablePath + "/.." + file;
|
temp.file = executablePath + file;
|
||||||
temp.type = type;
|
temp.type = type;
|
||||||
temp.required = required;
|
temp.required = required;
|
||||||
fileList.push_back(temp);
|
fileList.push_back(temp);
|
||||||
|
|
||||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
||||||
longest_name = SDL_max(longest_name, filename.size());
|
longestName = SDL_max(longestName, filename.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
||||||
@@ -48,7 +48,7 @@ bool Asset::check()
|
|||||||
printf("\n** Checking files.\n");
|
printf("\n** Checking files.\n");
|
||||||
|
|
||||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||||
for (int type = 0; type < maxAssetType; ++type)
|
for (int type = 0; type < t_maxAssetType; ++type)
|
||||||
{
|
{
|
||||||
// Comprueba si hay ficheros de ese tipo
|
// Comprueba si hay ficheros de ese tipo
|
||||||
bool any = false;
|
bool any = false;
|
||||||
@@ -106,7 +106,7 @@ bool Asset::checkFile(std::string path)
|
|||||||
SDL_RWclose(file);
|
SDL_RWclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string s = "Checking file %-" + std::to_string(longest_name) + "s [" + result + "]\n";
|
const std::string s = "Checking file %-" + std::to_string(longestName) + "s [" + result + "]\n";
|
||||||
printf(s.c_str(), filename.c_str());
|
printf(s.c_str(), filename.c_str());
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
@@ -117,39 +117,39 @@ std::string Asset::getTypeName(int type)
|
|||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case bitmap:
|
case t_bitmap:
|
||||||
return "BITMAP";
|
return "BITMAP";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case music:
|
case t_music:
|
||||||
return "MUSIC";
|
return "MUSIC";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sound:
|
case t_sound:
|
||||||
return "SOUND";
|
return "SOUND";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case font:
|
case t_font:
|
||||||
return "FONT";
|
return "FONT";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lang:
|
case t_lang:
|
||||||
return "LANG";
|
return "LANG";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case data:
|
case t_data:
|
||||||
return "DATA";
|
return "DATA";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case room:
|
case t_room:
|
||||||
return "ROOM";
|
return "ROOM";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case enemy:
|
case t_enemy:
|
||||||
return "ENEMY";
|
return "ENEMY";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case item:
|
case t_item:
|
||||||
return "ITEM";
|
return "ITEM";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -9,16 +9,16 @@
|
|||||||
|
|
||||||
enum assetType
|
enum assetType
|
||||||
{
|
{
|
||||||
bitmap,
|
t_bitmap,
|
||||||
music,
|
t_music,
|
||||||
sound,
|
t_sound,
|
||||||
font,
|
t_font,
|
||||||
lang,
|
t_lang,
|
||||||
data,
|
t_data,
|
||||||
room,
|
t_room,
|
||||||
enemy,
|
t_enemy,
|
||||||
item,
|
t_item,
|
||||||
maxAssetType
|
t_maxAssetType
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clase Asset
|
// Clase Asset
|
||||||
@@ -33,7 +33,7 @@ private:
|
|||||||
bool required; // Indica si es un fichero que debe de existir
|
bool required; // Indica si es un fichero que debe de existir
|
||||||
};
|
};
|
||||||
|
|
||||||
int longest_name; // Contiene la longitud del nombre de fichero mas largo
|
int longestName; // Contiene la longitud del nombre de fichero mas largo
|
||||||
|
|
||||||
std::vector<item_t> fileList;
|
std::vector<item_t> fileList;
|
||||||
std::string executablePath;
|
std::string executablePath;
|
||||||
@@ -5,16 +5,11 @@
|
|||||||
#ifndef CONST_H
|
#ifndef CONST_H
|
||||||
#define CONST_H
|
#define CONST_H
|
||||||
|
|
||||||
// Textos
|
|
||||||
#define WINDOW_CAPTION "Volcano"
|
|
||||||
#define TEXT_COPYRIGHT "2016,2022 JAILDESIGNER & JAILBROTHER"
|
|
||||||
#define VERSION "0.6"
|
|
||||||
|
|
||||||
// Tamaño de bloque
|
// Tamaño de bloque
|
||||||
#define BLOCK 8
|
#define BLOCK 8
|
||||||
#define HALF_BLOCK 4
|
#define HALF_BLOCK 4
|
||||||
|
|
||||||
// Tamaño de la pantalla virtual
|
// Tamaño de la pantalla de juego
|
||||||
#define GAMECANVAS_WIDTH 320
|
#define GAMECANVAS_WIDTH 320
|
||||||
#define GAMECANVAS_HEIGHT 240
|
#define GAMECANVAS_HEIGHT 240
|
||||||
|
|
||||||
@@ -60,15 +55,6 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
|||||||
#define SECTION_PROG_GAME 4
|
#define SECTION_PROG_GAME 4
|
||||||
#define SECTION_PROG_QUIT 5
|
#define SECTION_PROG_QUIT 5
|
||||||
|
|
||||||
// Subsecciones
|
|
||||||
#define SUBSECTION_GAME_PLAY 0
|
|
||||||
#define SUBSECTION_GAME_PAUSE 1
|
|
||||||
#define SUBSECTION_GAME_GAMEOVER 2
|
|
||||||
#define SUBSECTION_TITLE_1 3
|
|
||||||
#define SUBSECTION_TITLE_2 4
|
|
||||||
#define SUBSECTION_TITLE_3 5
|
|
||||||
#define SUBSECTION_TITLE_INSTRUCTIONS 6
|
|
||||||
|
|
||||||
// Colores
|
// Colores
|
||||||
const color_t borderColor = {0x27, 0x27, 0x36};
|
const color_t borderColor = {0x27, 0x27, 0x36};
|
||||||
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "const.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "screen.h"
|
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "screen.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include <vector>
|
#include "utils.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifndef DEBUG_H
|
#ifndef DEBUG_H
|
||||||
#define DEBUG_H
|
#define DEBUG_H
|
||||||
@@ -8,35 +8,35 @@ Input::Input(std::string file)
|
|||||||
dbPath = file;
|
dbPath = file;
|
||||||
|
|
||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
for (int i = 0; i < 17; ++i)
|
keyBindings_t kb;
|
||||||
{
|
kb.scancode = 0;
|
||||||
keyBindings[i].scancode = 0;
|
kb.active = false;
|
||||||
keyBindings[i].active = false;
|
keyBindings.resize(17, kb);
|
||||||
|
|
||||||
gameControllerBindings[i].button = SDL_CONTROLLER_BUTTON_INVALID;
|
GameControllerBindings_t gcb;
|
||||||
gameControllerBindings[i].active = false;
|
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
||||||
}
|
gcb.active = false;
|
||||||
|
gameControllerBindings.resize(17, gcb);
|
||||||
|
|
||||||
|
// Comprueba si hay un mando conectado
|
||||||
discoverGameController();
|
discoverGameController();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Input::~Input()
|
Input::~Input()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numGamepads; ++i)
|
|
||||||
connectedControllers[i] = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna uno de los posibles inputs a una tecla del teclado
|
// Asigna uno de los posibles inputs a una tecla del teclado
|
||||||
void Input::bindKey(Uint8 input, SDL_Scancode code)
|
void Input::bindKey(Uint8 input, SDL_Scancode code)
|
||||||
{
|
{
|
||||||
keyBindings[input].scancode = code;
|
keyBindings.at(input).scancode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna uno de los posibles inputs a un botón del mando
|
// Asigna uno de los posibles inputs a un botón del mando
|
||||||
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
||||||
{
|
{
|
||||||
gameControllerBindings[input].button = button;
|
gameControllerBindings.at(input).button = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
// Comprueba si un input esta activo
|
||||||
@@ -48,24 +48,14 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
if (device == INPUT_USE_ANY)
|
if (device == INPUT_USE_ANY)
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
||||||
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
|
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||||
{
|
{
|
||||||
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
|
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
||||||
|
|
||||||
if (repeat)
|
if (repeat)
|
||||||
{
|
{
|
||||||
if (mKeystates[keyBindings[input].scancode] != 0)
|
if (keyStates[keyBindings.at(input).scancode] != 0)
|
||||||
successKeyboard = true;
|
|
||||||
else
|
|
||||||
successKeyboard = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (!keyBindings[input].active)
|
|
||||||
{
|
|
||||||
if (mKeystates[keyBindings[input].scancode] != 0)
|
|
||||||
{
|
|
||||||
keyBindings[input].active = true;
|
|
||||||
successKeyboard = true;
|
successKeyboard = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -75,9 +65,23 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mKeystates[keyBindings[input].scancode] == 0)
|
if (!keyBindings.at(input).active)
|
||||||
{
|
{
|
||||||
keyBindings[input].active = false;
|
if (keyStates[keyBindings.at(input).scancode] != 0)
|
||||||
|
{
|
||||||
|
keyBindings.at(input).active = true;
|
||||||
|
successKeyboard = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
successKeyboard = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (keyStates[keyBindings.at(input).scancode] == 0)
|
||||||
|
{
|
||||||
|
keyBindings.at(input).active = false;
|
||||||
successKeyboard = false;
|
successKeyboard = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -93,18 +97,8 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
{
|
{
|
||||||
if (repeat)
|
if (repeat)
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
|
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(input).button) != 0)
|
||||||
successGameController = true;
|
|
||||||
else
|
|
||||||
successGameController = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (!gameControllerBindings[input].active)
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
|
|
||||||
{
|
|
||||||
gameControllerBindings[input].active = true;
|
|
||||||
successGameController = true;
|
successGameController = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -114,9 +108,23 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) == 0)
|
if (!gameControllerBindings.at(input).active)
|
||||||
{
|
{
|
||||||
gameControllerBindings[input].active = false;
|
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(input).button) != 0)
|
||||||
|
{
|
||||||
|
gameControllerBindings.at(input).active = true;
|
||||||
|
successGameController = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
successGameController = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(input).button) == 0)
|
||||||
|
{
|
||||||
|
gameControllerBindings.at(input).active = false;
|
||||||
successGameController = false;
|
successGameController = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -133,38 +141,39 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
// Comprueba si hay almenos un input activo
|
// Comprueba si hay almenos un input activo
|
||||||
bool Input::checkAnyInput(int device, int index)
|
bool Input::checkAnyInput(int device, int index)
|
||||||
{
|
{
|
||||||
bool successKeyboard = false;
|
|
||||||
bool successGameController = false;
|
|
||||||
|
|
||||||
if (device == INPUT_USE_ANY)
|
if (device == INPUT_USE_ANY)
|
||||||
|
{
|
||||||
index = 0;
|
index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
|
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||||
{
|
{
|
||||||
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
|
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||||
|
|
||||||
for (int i = 0; i < 17; ++i)
|
for (int i = 0; i < (int)keyBindings.size(); ++i)
|
||||||
{
|
{
|
||||||
if (mKeystates[keyBindings[i].scancode] != 0)
|
if (mKeystates[keyBindings.at(i).scancode] != 0)
|
||||||
{
|
{
|
||||||
successKeyboard |= true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameControllerFound())
|
if (gameControllerFound())
|
||||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 17; ++i)
|
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY)
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[i].button) != 0)
|
for (int i = 0; i < (int)gameControllerBindings.size(); ++i)
|
||||||
{
|
{
|
||||||
successGameController |= true;
|
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(i).button) != 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (successKeyboard || successGameController);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si hay un mando conectado
|
// Comprueba si hay un mando conectado
|
||||||
@@ -173,34 +182,42 @@ bool Input::discoverGameController()
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||||
|
{
|
||||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||||
|
}
|
||||||
|
|
||||||
if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0)
|
if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0)
|
||||||
|
{
|
||||||
printf("Error, could not load %s file: %s\n", dbPath.c_str(), SDL_GetError());
|
printf("Error, could not load %s file: %s\n", dbPath.c_str(), SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
int nJoysticks = SDL_NumJoysticks();
|
const int nJoysticks = SDL_NumJoysticks();
|
||||||
numGamepads = 0;
|
numGamepads = 0;
|
||||||
|
|
||||||
// Cuenta el numero de mandos
|
// Cuenta el numero de mandos
|
||||||
for (int i = 0; i < nJoysticks; ++i)
|
for (int i = 0; i < nJoysticks; ++i)
|
||||||
|
{
|
||||||
if (SDL_IsGameController(i))
|
if (SDL_IsGameController(i))
|
||||||
|
{
|
||||||
numGamepads++;
|
numGamepads++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
printf("** Checking for game controllers ...\n");
|
printf("\nChecking for game controllers...\n");
|
||||||
printf("%i joysticks found, %i are gamepads\n\n", nJoysticks, numGamepads);
|
printf("%i joysticks found, %i are gamepads\n", nJoysticks, numGamepads);
|
||||||
|
|
||||||
if (numGamepads > 0)
|
if (numGamepads > 0)
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
|
|
||||||
for (int i = 0; i < numGamepads; ++i)
|
for (int i = 0; i < numGamepads; i++)
|
||||||
{
|
{
|
||||||
// Abre el mando y lo añade a la lista
|
// Abre el mando y lo añade a la lista
|
||||||
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
||||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||||
{
|
{
|
||||||
connectedControllers.push_back(pad);
|
connectedControllers.push_back(pad);
|
||||||
std::string separator(" #");
|
const std::string separator(" #");
|
||||||
std::string name = SDL_GameControllerNameForIndex(i);
|
std::string name = SDL_GameControllerNameForIndex(i);
|
||||||
name.resize(25);
|
name.resize(25);
|
||||||
name = name + separator + std::to_string(i);
|
name = name + separator + std::to_string(i);
|
||||||
@@ -208,10 +225,11 @@ bool Input::discoverGameController()
|
|||||||
controllerNames.push_back(name);
|
controllerNames.push_back(name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// mGameController = connectedControllers[0];
|
|
||||||
SDL_GameControllerEventState(SDL_ENABLE);
|
SDL_GameControllerEventState(SDL_ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,18 +240,26 @@ bool Input::discoverGameController()
|
|||||||
bool Input::gameControllerFound()
|
bool Input::gameControllerFound()
|
||||||
{
|
{
|
||||||
if (numGamepads > 0)
|
if (numGamepads > 0)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obten el nombre de un mando de juego
|
// Obten el nombre de un mando de juego
|
||||||
std::string Input::getControllerName(int index)
|
std::string Input::getControllerName(int index)
|
||||||
{
|
{
|
||||||
if (numGamepads > 0)
|
if (numGamepads > 0)
|
||||||
return controllerNames[index];
|
{
|
||||||
|
return controllerNames.at(index);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obten el numero de mandos conectados
|
// Obten el numero de mandos conectados
|
||||||
@@ -41,15 +41,15 @@ private:
|
|||||||
Uint8 scancode; // Scancode asociado
|
Uint8 scancode; // Scancode asociado
|
||||||
bool active; // Indica si está activo
|
bool active; // Indica si está activo
|
||||||
};
|
};
|
||||||
keyBindings_t keyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
|
||||||
|
|
||||||
struct GameControllerBindings_t
|
struct GameControllerBindings_t
|
||||||
{
|
{
|
||||||
SDL_GameControllerButton button; // GameControllerButton asociado
|
SDL_GameControllerButton button; // GameControllerButton asociado
|
||||||
bool active; // Indica si está activo
|
bool active; // Indica si está activo
|
||||||
};
|
};
|
||||||
GameControllerBindings_t gameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
|
||||||
|
|
||||||
|
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
|
std::vector<GameControllerBindings_t> gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
||||||
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
||||||
int numGamepads; // Numero de mandos conectados
|
int numGamepads; // Numero de mandos conectados
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
|
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
|
||||||
@@ -11,7 +11,7 @@ LTexture::LTexture(SDL_Renderer *renderer, std::string path)
|
|||||||
this->path = path;
|
this->path = path;
|
||||||
|
|
||||||
// Inicializa
|
// Inicializa
|
||||||
texture = NULL;
|
texture = nullptr;
|
||||||
width = 0;
|
width = 0;
|
||||||
height = 0;
|
height = 0;
|
||||||
|
|
||||||
@@ -32,14 +32,19 @@ LTexture::~LTexture()
|
|||||||
// Carga una imagen desde un fichero
|
// Carga una imagen desde un fichero
|
||||||
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
|
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||||
int req_format = STBI_rgb_alpha;
|
int req_format = STBI_rgb_alpha;
|
||||||
int width, height, orig_format;
|
int width, height, orig_format;
|
||||||
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_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());
|
SDL_Log("Loading image failed: %s", stbi_failure_reason());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Image loaded: %s\n", filename.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
int depth, pitch;
|
int depth, pitch;
|
||||||
Uint32 pixel_format;
|
Uint32 pixel_format;
|
||||||
@@ -60,11 +65,11 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
|||||||
unload();
|
unload();
|
||||||
|
|
||||||
// La textura final
|
// La textura final
|
||||||
SDL_Texture *newTexture = NULL;
|
SDL_Texture *newTexture = nullptr;
|
||||||
|
|
||||||
// Carga la imagen desde una ruta específica
|
// Carga la imagen desde una ruta específica
|
||||||
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
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());
|
printf("Unable to load image %s!\n", path.c_str());
|
||||||
}
|
}
|
||||||
@@ -72,7 +77,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
|||||||
{
|
{
|
||||||
// Crea la textura desde los pixels de la surface
|
// Crea la textura desde los pixels de la surface
|
||||||
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
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());
|
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
||||||
}
|
}
|
||||||
@@ -89,7 +94,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
|||||||
|
|
||||||
// Return success
|
// Return success
|
||||||
texture = newTexture;
|
texture = newTexture;
|
||||||
return texture != NULL;
|
return texture != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea una textura en blanco
|
// Crea una textura en blanco
|
||||||
@@ -97,7 +102,7 @@ bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Te
|
|||||||
{
|
{
|
||||||
// Crea una textura sin inicializar
|
// Crea una textura sin inicializar
|
||||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||||
if (texture == NULL)
|
if (texture == nullptr)
|
||||||
{
|
{
|
||||||
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
@@ -107,17 +112,17 @@ bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Te
|
|||||||
this->height = height;
|
this->height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
return texture != NULL;
|
return texture != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera la memoria de la textura
|
// Libera la memoria de la textura
|
||||||
void LTexture::unload()
|
void LTexture::unload()
|
||||||
{
|
{
|
||||||
// Libera la textura si existe
|
// Libera la textura si existe
|
||||||
if (texture != NULL)
|
if (texture != nullptr)
|
||||||
{
|
{
|
||||||
SDL_DestroyTexture(texture);
|
SDL_DestroyTexture(texture);
|
||||||
texture = NULL;
|
texture = nullptr;
|
||||||
width = 0;
|
width = 0;
|
||||||
height = 0;
|
height = 0;
|
||||||
}
|
}
|
||||||
@@ -144,11 +149,11 @@ void LTexture::setAlpha(Uint8 alpha)
|
|||||||
// Renderiza la textura en un punto específico
|
// 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)
|
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)
|
||||||
{
|
{
|
||||||
// Establece el destini de renderizado en la pantalla
|
// Establece el destino de renderizado en la pantalla
|
||||||
SDL_Rect renderQuad = {x, y, width, height};
|
SDL_Rect renderQuad = {x, y, width, height};
|
||||||
|
|
||||||
// Obtiene las dimesiones del clip de renderizado
|
// Obtiene las dimesiones del clip de renderizado
|
||||||
if (clip != NULL)
|
if (clip != nullptr)
|
||||||
{
|
{
|
||||||
renderQuad.w = clip->w;
|
renderQuad.w = clip->w;
|
||||||
renderQuad.h = clip->h;
|
renderQuad.h = clip->h;
|
||||||
@@ -43,7 +43,7 @@ public:
|
|||||||
void setAlpha(Uint8 alpha);
|
void setAlpha(Uint8 alpha);
|
||||||
|
|
||||||
// Renderiza la textura en un punto específico
|
// Renderiza la textura en un punto específico
|
||||||
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);
|
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);
|
||||||
|
|
||||||
// Establece la textura como objetivo de renderizado
|
// Establece la textura como objetivo de renderizado
|
||||||
void setAsRenderTarget(SDL_Renderer *renderer);
|
void setAsRenderTarget(SDL_Renderer *renderer);
|
||||||
@@ -4,20 +4,63 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file)
|
Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file)
|
||||||
{
|
{
|
||||||
|
// Copia punteros
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
this->input = input;
|
this->input = input;
|
||||||
|
|
||||||
|
// Inicializa punteros
|
||||||
soundMove = nullptr;
|
soundMove = nullptr;
|
||||||
soundAccept = nullptr;
|
soundAccept = nullptr;
|
||||||
soundCancel = nullptr;
|
soundCancel = nullptr;
|
||||||
|
|
||||||
init();
|
// Inicializa variables
|
||||||
|
name = "";
|
||||||
|
selector.index = 0;
|
||||||
|
itemSelected = MENU_NO_OPTION;
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
w = 0;
|
||||||
|
rectBG.rect = {0, 0, 0, 0};
|
||||||
|
rectBG.color = {0, 0, 0};
|
||||||
|
rectBG.a = 0;
|
||||||
|
backgroundType = MENU_BACKGROUND_SOLID;
|
||||||
|
isCenteredOnX = false;
|
||||||
|
isCenteredOnY = false;
|
||||||
|
areElementsCenteredOnX = false;
|
||||||
|
centerX = 0;
|
||||||
|
centerY = 0;
|
||||||
|
widestItem = 0;
|
||||||
|
colorGreyed = {128, 128, 128};
|
||||||
|
defaultActionWhenCancel = 0;
|
||||||
|
font_png = "";
|
||||||
|
font_txt = "";
|
||||||
|
|
||||||
|
// Selector
|
||||||
|
selector.originY = 0;
|
||||||
|
selector.targetY = 0;
|
||||||
|
selector.despY = 0;
|
||||||
|
selector.originH = 0;
|
||||||
|
selector.targetH = 0;
|
||||||
|
selector.incH = 0;
|
||||||
|
selector.y = 0.0f;
|
||||||
|
selector.h = 0.0f;
|
||||||
|
selector.numJumps = 8;
|
||||||
|
selector.moving = false;
|
||||||
|
selector.resizing = false;
|
||||||
|
selector.rect = {0, 0, 0, 0};
|
||||||
|
selector.color = {0, 0, 0};
|
||||||
|
selector.itemColor = {0, 0, 0};
|
||||||
|
selector.a = 255;
|
||||||
|
|
||||||
|
// Inicializa las variables desde un fichero
|
||||||
if (file != "")
|
if (file != "")
|
||||||
{
|
{
|
||||||
load(file);
|
load(file);
|
||||||
}
|
}
|
||||||
reorganize();
|
|
||||||
|
// Deja el cursor en el primer elemento
|
||||||
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu::~Menu()
|
Menu::~Menu()
|
||||||
@@ -56,7 +99,7 @@ bool Menu::load(std::string file_path)
|
|||||||
// Indica si se ha creado ya el objeto de texto
|
// Indica si se ha creado ya el objeto de texto
|
||||||
bool textAllocated = false;
|
bool textAllocated = false;
|
||||||
|
|
||||||
std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
std::string line;
|
std::string line;
|
||||||
std::ifstream file(file_path);
|
std::ifstream file(file_path);
|
||||||
|
|
||||||
@@ -78,7 +121,7 @@ bool Menu::load(std::string file_path)
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
// Lee la siguiente linea
|
||||||
std::getline(file, line);
|
std::getline(file, line);
|
||||||
|
|
||||||
// Encuentra la posición del caracter '='
|
// Encuentra la posición del caracter '='
|
||||||
@@ -118,7 +161,7 @@ bool Menu::load(std::string file_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
printf("Closing file %s\n\n", filename.c_str());
|
printf("Closing file %s\n", filename.c_str());
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
// El fichero no se puede abrir
|
// El fichero no se puede abrir
|
||||||
@@ -165,6 +208,7 @@ bool Menu::setItem(item_t *item, std::string var, std::string value)
|
|||||||
else if ((var == "") || (var == "[/item]"))
|
else if ((var == "") || (var == "[/item]"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
@@ -309,48 +353,6 @@ bool Menu::setVars(std::string var, std::string value)
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables
|
|
||||||
void Menu::init()
|
|
||||||
{
|
|
||||||
// Inicia variables
|
|
||||||
name = "";
|
|
||||||
selector.index = 0;
|
|
||||||
itemSelected = MENU_NO_OPTION;
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
rectBG.rect = {0, 0, 0, 0};
|
|
||||||
rectBG.color = {0, 0, 0};
|
|
||||||
rectBG.a = 0;
|
|
||||||
backgroundType = MENU_BACKGROUND_SOLID;
|
|
||||||
isCenteredOnX = false;
|
|
||||||
isCenteredOnY = false;
|
|
||||||
areElementsCenteredOnX = false;
|
|
||||||
centerX = 0;
|
|
||||||
centerY = 0;
|
|
||||||
widestItem = 0;
|
|
||||||
colorGreyed = {128, 128, 128};
|
|
||||||
defaultActionWhenCancel = 0;
|
|
||||||
font_png = "";
|
|
||||||
font_txt = "";
|
|
||||||
|
|
||||||
// Selector
|
|
||||||
selector.originY = 0;
|
|
||||||
selector.targetY = 0;
|
|
||||||
selector.despY = 0;
|
|
||||||
selector.originH = 0;
|
|
||||||
selector.targetH = 0;
|
|
||||||
selector.incH = 0;
|
|
||||||
selector.y = 0.0f;
|
|
||||||
selector.h = 0.0f;
|
|
||||||
selector.numJumps = 8;
|
|
||||||
selector.moving = false;
|
|
||||||
selector.resizing = false;
|
|
||||||
selector.rect = {0, 0, 0, 0};
|
|
||||||
selector.color = {0, 0, 0};
|
|
||||||
selector.itemColor = {0, 0, 0};
|
|
||||||
selector.a = 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carga los ficheros de audio
|
// Carga los ficheros de audio
|
||||||
void Menu::loadAudioFile(std::string file, int sound)
|
void Menu::loadAudioFile(std::string file, int sound)
|
||||||
{
|
{
|
||||||
@@ -403,7 +405,8 @@ void Menu::updateSelector()
|
|||||||
selector.moving = false;
|
selector.moving = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (selector.despY < 0) // Va hacia arriba
|
|
||||||
|
else if (selector.despY < 0) // Va hacia arriba
|
||||||
{
|
{
|
||||||
if (selector.y < selector.targetY) // Ha llegado al destino
|
if (selector.y < selector.targetY) // Ha llegado al destino
|
||||||
{
|
{
|
||||||
@@ -431,7 +434,8 @@ void Menu::updateSelector()
|
|||||||
selector.resizing = false;
|
selector.resizing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (selector.incH < 0) // Decrece
|
|
||||||
|
else if (selector.incH < 0) // Decrece
|
||||||
{
|
{
|
||||||
if (selector.h < selector.targetH) // Ha llegado al destino
|
if (selector.h < selector.targetH) // Ha llegado al destino
|
||||||
{
|
{
|
||||||
@@ -454,7 +458,7 @@ void Menu::setSelectorPos(int index)
|
|||||||
if (index < (int)item.size())
|
if (index < (int)item.size())
|
||||||
{
|
{
|
||||||
selector.index = index;
|
selector.index = index;
|
||||||
selector.rect.y = selector.y = selector.originY = selector.targetY = item[selector.index].rect.y;
|
selector.rect.y = selector.y = selector.originY = selector.targetY = item.at(selector.index).rect.y;
|
||||||
selector.rect.w = rectBG.rect.w;
|
selector.rect.w = rectBG.rect.w;
|
||||||
selector.rect.x = rectBG.rect.x;
|
selector.rect.x = rectBG.rect.x;
|
||||||
selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index);
|
selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index);
|
||||||
@@ -482,10 +486,17 @@ void Menu::reset()
|
|||||||
{
|
{
|
||||||
itemSelected = MENU_NO_OPTION;
|
itemSelected = MENU_NO_OPTION;
|
||||||
selector.index = 0;
|
selector.index = 0;
|
||||||
selector.originY = selector.targetY = selector.y = item[0].rect.y;
|
selector.originY = selector.targetY = selector.y = item.at(0).rect.y;
|
||||||
selector.originH = selector.targetH = item[0].rect.h;
|
selector.originH = selector.targetH = item.at(0).rect.h;
|
||||||
selector.moving = false;
|
selector.moving = false;
|
||||||
selector.resizing = false;
|
selector.resizing = false;
|
||||||
|
|
||||||
|
// Si el primer elemento no es seleccionable, incrementa el selector
|
||||||
|
if (!item.at(selector.index).selectable)
|
||||||
|
{
|
||||||
|
increaseSelectorIndex();
|
||||||
|
setSelectorPos(selector.index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
||||||
@@ -513,18 +524,18 @@ void Menu::reorganize()
|
|||||||
bool Menu::increaseSelectorIndex()
|
bool Menu::increaseSelectorIndex()
|
||||||
{
|
{
|
||||||
// Obten las coordenadas del elemento actual
|
// Obten las coordenadas del elemento actual
|
||||||
selector.y = selector.originY = item[selector.index].rect.y;
|
selector.y = selector.originY = item.at(selector.index).rect.y;
|
||||||
selector.h = selector.originH = getSelectorHeight(selector.index);
|
selector.h = selector.originH = getSelectorHeight(selector.index);
|
||||||
|
|
||||||
// Calcula cual es el siguiente elemento
|
// Calcula cual es el siguiente elemento
|
||||||
++selector.index %= item.size();
|
++selector.index %= item.size();
|
||||||
while (!item[selector.index].selectable)
|
while (!item.at(selector.index).selectable)
|
||||||
{
|
{
|
||||||
++selector.index %= item.size();
|
++selector.index %= item.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece las coordenadas y altura de destino
|
// Establece las coordenadas y altura de destino
|
||||||
selector.targetY = item[selector.index].rect.y;
|
selector.targetY = item.at(selector.index).rect.y;
|
||||||
selector.despY = (selector.targetY - selector.originY) / selector.numJumps;
|
selector.despY = (selector.targetY - selector.originY) / selector.numJumps;
|
||||||
|
|
||||||
selector.targetH = getSelectorHeight(selector.index);
|
selector.targetH = getSelectorHeight(selector.index);
|
||||||
@@ -543,24 +554,24 @@ bool Menu::increaseSelectorIndex()
|
|||||||
bool Menu::decreaseSelectorIndex()
|
bool Menu::decreaseSelectorIndex()
|
||||||
{
|
{
|
||||||
// Obten las coordenadas del elemento actual
|
// Obten las coordenadas del elemento actual
|
||||||
selector.y = selector.originY = item[selector.index].rect.y;
|
selector.y = selector.originY = item.at(selector.index).rect.y;
|
||||||
selector.h = selector.originH = getSelectorHeight(selector.index);
|
selector.h = selector.originH = getSelectorHeight(selector.index);
|
||||||
|
|
||||||
// Calcula cual es el siguiente elemento
|
// Calcula cual es el siguiente elemento
|
||||||
if (selector.index == 0)
|
if (selector.index == 0)
|
||||||
{
|
{
|
||||||
selector.index = item.size();
|
selector.index = item.size() - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
selector.index--;
|
selector.index--;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!item[selector.index].selectable)
|
while (!item.at(selector.index).selectable)
|
||||||
{
|
{
|
||||||
if (selector.index == 0)
|
if (selector.index == 0)
|
||||||
{
|
{
|
||||||
selector.index = item.size();
|
selector.index = item.size() - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -569,7 +580,7 @@ bool Menu::decreaseSelectorIndex()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establece las coordenadas y altura de destino
|
// Establece las coordenadas y altura de destino
|
||||||
selector.targetY = item[selector.index].rect.y;
|
selector.targetY = item.at(selector.index).rect.y;
|
||||||
selector.despY = (selector.targetY - selector.originY) / selector.numJumps;
|
selector.despY = (selector.targetY - selector.originY) / selector.numJumps;
|
||||||
|
|
||||||
selector.targetH = getSelectorHeight(selector.index);
|
selector.targetH = getSelectorHeight(selector.index);
|
||||||
@@ -603,8 +614,6 @@ void Menu::render()
|
|||||||
|
|
||||||
// Renderiza el rectangulo del selector
|
// Renderiza el rectangulo del selector
|
||||||
const SDL_Rect temp = {selector.rect.x, selector.rect.y - 1, selector.rect.w, selector.rect.h + 1};
|
const SDL_Rect temp = {selector.rect.x, selector.rect.y - 1, selector.rect.w, selector.rect.h + 1};
|
||||||
// temp.y--;
|
|
||||||
// temp.h++;
|
|
||||||
SDL_SetRenderDrawColor(renderer, selector.color.r, selector.color.g, selector.color.b, selector.a);
|
SDL_SetRenderDrawColor(renderer, selector.color.r, selector.color.g, selector.color.b, selector.a);
|
||||||
SDL_RenderFillRect(renderer, &temp);
|
SDL_RenderFillRect(renderer, &temp);
|
||||||
|
|
||||||
@@ -621,40 +630,74 @@ void Menu::render()
|
|||||||
if (i == selector.index)
|
if (i == selector.index)
|
||||||
{
|
{
|
||||||
const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
|
const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
|
||||||
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color);
|
text->writeColored(item.at(i).rect.x, item.at(i).rect.y, item.at(i).label, color);
|
||||||
}
|
}
|
||||||
else if (item[i].selectable)
|
|
||||||
|
else if (item.at(i).selectable)
|
||||||
{
|
{
|
||||||
text->write(item[i].rect.x, item[i].rect.y, item[i].label);
|
text->write(item.at(i).rect.x, item.at(i).rect.y, item.at(i).label);
|
||||||
}
|
}
|
||||||
else if (item[i].greyed)
|
|
||||||
|
else if (item.at(i).greyed)
|
||||||
{
|
{
|
||||||
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, colorGreyed);
|
text->writeColored(item.at(i).rect.x, item.at(i).rect.y, item.at(i).label, colorGreyed);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
// No seleccionable
|
{ // No seleccionable
|
||||||
{
|
if ((item.at(i).linkedUp) && (i == selector.index + 1))
|
||||||
if ((item[i].linkedUp) && (i == selector.index + 1))
|
|
||||||
{
|
{
|
||||||
const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
|
const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
|
||||||
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color);
|
text->writeColored(item.at(i).rect.x, item.at(i).rect.y, item.at(i).label, color);
|
||||||
}
|
}
|
||||||
else // No enlazado con el de arriba
|
else // No enlazado con el de arriba
|
||||||
{
|
{
|
||||||
text->write(item[i].rect.x, item[i].rect.y, item[i].label);
|
text->write(item.at(i).rect.x, item.at(i).rect.y, item.at(i).label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el rectangulo de fondo del menu y el selector
|
// Establece el rectangulo de fondo del menu y el selector
|
||||||
void Menu::setRectSize()
|
void Menu::setRectSize(int w, int h)
|
||||||
{
|
{
|
||||||
|
// Establece el ancho
|
||||||
|
if (w == 0)
|
||||||
|
{ // Si no se pasa un valor, se busca si hay uno prefijado
|
||||||
|
if (this->w == 0)
|
||||||
|
{ // Si no hay prefijado, coge el item mas ancho
|
||||||
rectBG.rect.w = findWidth() + text->getCharacterSize();
|
rectBG.rect.w = findWidth() + text->getCharacterSize();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Si hay prefijado, coge ese
|
||||||
|
rectBG.rect.w = this->w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Si se pasa un valor, se usa y se prefija
|
||||||
|
rectBG.rect.w = w;
|
||||||
|
this->w = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el alto
|
||||||
|
if (h == 0)
|
||||||
|
{ // Si no se pasa un valor, se busca de manera automatica
|
||||||
rectBG.rect.h = findHeight() + text->getCharacterSize();
|
rectBG.rect.h = findHeight() + text->getCharacterSize();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Si se pasa un valor, se aplica
|
||||||
|
rectBG.rect.h = h;
|
||||||
|
}
|
||||||
|
|
||||||
// La posición X es la del menú menos medio caracter
|
// La posición X es la del menú menos medio caracter
|
||||||
|
if (this->w != 0)
|
||||||
|
{ // Si el ancho esta prefijado, la x coinccide
|
||||||
|
rectBG.rect.x = x;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Si el ancho es automatico, se le da un poco de margen
|
||||||
rectBG.rect.x = x - (text->getCharacterSize() / 2);
|
rectBG.rect.x = x - (text->getCharacterSize() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
// La posición Y es la del menu menos la altura de medio caracter
|
// La posición Y es la del menu menos la altura de medio caracter
|
||||||
rectBG.rect.y = y - (text->getCharacterSize() / 2);
|
rectBG.rect.y = y - (text->getCharacterSize() / 2);
|
||||||
@@ -687,10 +730,28 @@ void Menu::setSelectorTextColor(color_t color)
|
|||||||
void Menu::centerMenuOnX(int value)
|
void Menu::centerMenuOnX(int value)
|
||||||
{
|
{
|
||||||
isCenteredOnX = true;
|
isCenteredOnX = true;
|
||||||
|
if (value != 0)
|
||||||
|
{
|
||||||
centerX = value;
|
centerX = value;
|
||||||
|
}
|
||||||
|
else if (centerX == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Establece la nueva posición centrada en funcion del elemento más ancho
|
// Establece la nueva posición centrada en funcion del elemento más ancho o del ancho fijo del menu
|
||||||
x = (value) - (findWidth() / 2);
|
if (w != 0)
|
||||||
|
{ // Si se ha definido un ancho fijo
|
||||||
|
x = (centerX) - (w / 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Si se actua en función del elemento más ancho
|
||||||
|
x = (centerX) - (findWidth() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el rectangulo de fondo y del selector
|
||||||
|
rectBG.rect.x = x;
|
||||||
|
selector.rect.x = x;
|
||||||
|
|
||||||
// Reposiciona los elementos del menu
|
// Reposiciona los elementos del menu
|
||||||
for (auto &i : item)
|
for (auto &i : item)
|
||||||
@@ -700,6 +761,12 @@ void Menu::centerMenuOnX(int value)
|
|||||||
|
|
||||||
// Recalcula el rectangulo de fondo
|
// Recalcula el rectangulo de fondo
|
||||||
setRectSize();
|
setRectSize();
|
||||||
|
|
||||||
|
// Vuelve a centrar los elementos si fuera el caso
|
||||||
|
if (areElementsCenteredOnX)
|
||||||
|
{
|
||||||
|
centerMenuElementsOnX();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Centra el menu respecto un punto en el eje Y
|
// Centra el menu respecto un punto en el eje Y
|
||||||
@@ -733,14 +800,13 @@ void Menu::centerMenuElementsOnX()
|
|||||||
void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown)
|
void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown)
|
||||||
{
|
{
|
||||||
item_t temp;
|
item_t temp;
|
||||||
// Si es el primer item coge la posición en el eje Y del propio menu
|
|
||||||
if (item.size() == 0)
|
if (item.empty())
|
||||||
{
|
{ // Si es el primer item coge la posición en el eje Y del propio menu
|
||||||
temp.rect.y = y;
|
temp.rect.y = y;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// En caso contrario, coge la posición en el eje Y a partir del elemento anterior
|
{ // En caso contrario, coge la posición en el eje Y a partir del último elemento
|
||||||
{
|
|
||||||
temp.rect.y = item.back().rect.y + item.back().rect.h + item.back().hPaddingDown;
|
temp.rect.y = item.back().rect.y + item.back().rect.h + item.back().hPaddingDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -751,13 +817,14 @@ void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool gre
|
|||||||
temp.linkedDown = linkedDown;
|
temp.linkedDown = linkedDown;
|
||||||
|
|
||||||
item.push_back(temp);
|
item.push_back(temp);
|
||||||
|
|
||||||
setItemCaption(item.size() - 1, text);
|
setItemCaption(item.size() - 1, text);
|
||||||
|
|
||||||
if (item.size() > 0)
|
if (item.size() > 1)
|
||||||
{
|
{
|
||||||
if (item[item.size() - 1].linkedDown)
|
if (item.at(item.size() - 2).linkedDown)
|
||||||
{
|
{
|
||||||
item[item.size()].linkedUp = true;
|
item.back().linkedUp = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -768,13 +835,10 @@ void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool gre
|
|||||||
// Cambia el texto de un item
|
// Cambia el texto de un item
|
||||||
void Menu::setItemCaption(int index, std::string text)
|
void Menu::setItemCaption(int index, std::string text)
|
||||||
{
|
{
|
||||||
item[index].label = text;
|
item.at(index).label = text;
|
||||||
item[index].rect.w = this->text->lenght(item[index].label);
|
item.at(index).rect.w = this->text->lenght(item.at(index).label);
|
||||||
item[index].rect.h = this->text->getCharacterSize();
|
item.at(index).rect.h = this->text->getCharacterSize();
|
||||||
reorganize();
|
reorganize();
|
||||||
|
|
||||||
const std::string texto = item[index].label + ":" + std::to_string(item[index].rect.w);
|
|
||||||
printf("Adding menu item -> %s\n", texto.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el indice del itemm que se usará por defecto al cancelar el menu
|
// Establece el indice del itemm que se usará por defecto al cancelar el menu
|
||||||
@@ -850,41 +914,69 @@ int Menu::findHeight()
|
|||||||
// Recoloca los elementos del menu en el eje Y
|
// Recoloca los elementos del menu en el eje Y
|
||||||
void Menu::replaceElementsOnY()
|
void Menu::replaceElementsOnY()
|
||||||
{
|
{
|
||||||
item[0].rect.y = y;
|
item.at(0).rect.y = y;
|
||||||
|
|
||||||
for (int i = 1; i < (int)item.size(); i++)
|
for (int i = 1; i < (int)item.size(); i++)
|
||||||
{
|
{
|
||||||
item[i].rect.y = item[i - 1].rect.y + item[i - 1].rect.h + item[i - 1].hPaddingDown;
|
item.at(i).rect.y = item.at(i - 1).rect.y + item.at(i - 1).rect.h + item.at(i - 1).hPaddingDown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el estado seleccionable de un item
|
// Establece el estado seleccionable de un item
|
||||||
void Menu::setSelectable(int index, bool value)
|
void Menu::setSelectable(int index, bool value)
|
||||||
{
|
{
|
||||||
item[index].selectable = value;
|
item.at(index).selectable = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el estado agrisado de un item
|
// Establece el estado agrisado de un item
|
||||||
void Menu::setGreyed(int index, bool value)
|
void Menu::setGreyed(int index, bool value)
|
||||||
{
|
{
|
||||||
item[index].greyed = value;
|
item.at(index).greyed = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el estado de enlace de un item
|
// Establece el estado de enlace de un item
|
||||||
void Menu::setLinkedDown(int index, bool value)
|
void Menu::setLinkedDown(int index, bool value)
|
||||||
{
|
{
|
||||||
item[index].linkedDown = value;
|
item.at(index).linkedDown = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula la altura del selector
|
// Calcula la altura del selector
|
||||||
int Menu::getSelectorHeight(int value)
|
int Menu::getSelectorHeight(int value)
|
||||||
{
|
{
|
||||||
if (item[value].linkedDown)
|
if (item.at(value).linkedDown)
|
||||||
{
|
{
|
||||||
return item[value].rect.h + item[value].hPaddingDown + item[value + 1].rect.h;
|
return item.at(value).rect.h + item.at(value).hPaddingDown + item.at(value + 1).rect.h;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return item[value].rect.h;
|
return item.at(value).rect.h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el nombre del menu
|
||||||
|
void Menu::setName(std::string name)
|
||||||
|
{
|
||||||
|
this->name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la posición del menu
|
||||||
|
void Menu::setPos(int x, int y)
|
||||||
|
{
|
||||||
|
this->x = x;
|
||||||
|
this->y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el tipo de fondo del menu
|
||||||
|
void Menu::setBackgroundType(int value)
|
||||||
|
{
|
||||||
|
backgroundType = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la fuente de texto que se utilizará
|
||||||
|
void Menu::setText(std::string font_png, std::string font_txt)
|
||||||
|
{
|
||||||
|
if (!text)
|
||||||
|
{
|
||||||
|
text = new Text(font_png, font_txt, renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <vector>
|
|
||||||
#include "sprite.h"
|
|
||||||
#include "text.h"
|
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include <sstream>
|
#include "sprite.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "utils.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifndef MENU_H
|
#ifndef MENU_H
|
||||||
#define MENU_H
|
#define MENU_H
|
||||||
@@ -68,6 +68,13 @@ private:
|
|||||||
int a; // Cantidad de transparencia para el rectangulo del selector
|
int a; // Cantidad de transparencia para el rectangulo del selector
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Objetos
|
||||||
|
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
|
||||||
|
|
||||||
|
// Variables
|
||||||
std::string name; // Nombre del menu
|
std::string name; // Nombre del menu
|
||||||
int x; // Posición en el eje X de la primera letra del primer elemento
|
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 y; // Posición en el eje Y de la primera letra del primer elemento
|
||||||
@@ -85,10 +92,6 @@ private:
|
|||||||
JA_Sound soundAccept; // Sonido al aceptar o elegir una opción del menu
|
JA_Sound soundAccept; // Sonido al aceptar o elegir una opción del menu
|
||||||
JA_Sound soundCancel; // Sonido al cancelar el menu
|
JA_Sound soundCancel; // Sonido al cancelar el menu
|
||||||
JA_Sound soundMove; // Sonido al mover el selector
|
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
|
color_t colorGreyed; // Color para los elementos agrisados
|
||||||
rectangle_t rectBG; // Rectangulo de fondo del menu
|
rectangle_t rectBG; // Rectangulo de fondo del menu
|
||||||
std::vector<item_t> item; // Estructura para cada elemento del menu
|
std::vector<item_t> item; // Estructura para cada elemento del menu
|
||||||
@@ -105,12 +108,6 @@ private:
|
|||||||
// Asigna variables a partir de dos cadenas
|
// Asigna variables a partir de dos cadenas
|
||||||
bool setItem(item_t *item, std::string var, std::string value);
|
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();
|
|
||||||
|
|
||||||
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
||||||
void reorganize();
|
void reorganize();
|
||||||
|
|
||||||
@@ -143,7 +140,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file="");
|
Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file = "");
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Menu();
|
~Menu();
|
||||||
@@ -179,7 +176,7 @@ public:
|
|||||||
void setSelectorTextColor(color_t color);
|
void setSelectorTextColor(color_t color);
|
||||||
|
|
||||||
// Centra el menu respecto a un punto en el eje X
|
// Centra el menu respecto a un punto en el eje X
|
||||||
void centerMenuOnX(int value);
|
void centerMenuOnX(int value = 0);
|
||||||
|
|
||||||
// Centra el menu respecto a un punto en el eje Y
|
// Centra el menu respecto a un punto en el eje Y
|
||||||
void centerMenuOnY(int value);
|
void centerMenuOnY(int value);
|
||||||
@@ -208,7 +205,20 @@ public:
|
|||||||
// Establece el estado de enlace de un item
|
// Establece el estado de enlace de un item
|
||||||
void setLinkedDown(int index, bool value);
|
void setLinkedDown(int index, bool value);
|
||||||
|
|
||||||
// hacer procedimientos para establecer el titulo, la x, la y, la tipografia y el tipo de fondo
|
// 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);
|
||||||
|
|
||||||
|
// Establece la fuente de texto que se utilizará
|
||||||
|
void setText(std::string font_png, std::string font_txt);
|
||||||
|
|
||||||
|
// Establece el rectangulo de fondo del menu
|
||||||
|
void setRectSize(int w = 0, int h = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -45,7 +45,7 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
|
|||||||
spriteClip = {0, 0, w, h};
|
spriteClip = {0, 0, w, h};
|
||||||
|
|
||||||
// Establece el centro de rotación
|
// Establece el centro de rotación
|
||||||
center = {0, 0};
|
center = nullptr;
|
||||||
|
|
||||||
// Establece el tipo de volteado
|
// Establece el tipo de volteado
|
||||||
currentFlip = SDL_FLIP_NONE;
|
currentFlip = SDL_FLIP_NONE;
|
||||||
@@ -73,7 +73,7 @@ void MovingSprite::clear()
|
|||||||
|
|
||||||
angle = 0.0; // Angulo para dibujarlo
|
angle = 0.0; // Angulo para dibujarlo
|
||||||
rotateEnabled = false; // Indica si ha de rotar
|
rotateEnabled = false; // Indica si ha de rotar
|
||||||
center = {0, 0}; // Centro de rotación
|
center = nullptr; // Centro de rotación
|
||||||
rotateSpeed = 0; // Velocidad de giro
|
rotateSpeed = 0; // Velocidad de giro
|
||||||
rotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
rotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
||||||
counter = 0; // Contador interno
|
counter = 0; // Contador interno
|
||||||
@@ -101,7 +101,9 @@ void MovingSprite::move()
|
|||||||
void MovingSprite::render()
|
void MovingSprite::render()
|
||||||
{
|
{
|
||||||
if (enabled)
|
if (enabled)
|
||||||
texture->render(renderer, (int)x, (int)y, &spriteClip, zoomW, zoomH, angle, ¢er, currentFlip);
|
{
|
||||||
|
texture->render(renderer, (int)x, (int)y, &spriteClip, zoomW, zoomH, angle, center, currentFlip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
@@ -158,11 +160,13 @@ double MovingSprite::getAngle()
|
|||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la posición del objeto
|
// Establece la posición y el tamaño del objeto
|
||||||
void MovingSprite::setPos(SDL_Rect rect)
|
void MovingSprite::setRect(SDL_Rect rect)
|
||||||
{
|
{
|
||||||
x = (float)rect.x;
|
x = (float)rect.x;
|
||||||
y = (float)rect.y;
|
y = (float)rect.y;
|
||||||
|
w = rect.w;
|
||||||
|
h = rect.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
@@ -265,7 +269,14 @@ void MovingSprite::setRotate(bool value)
|
|||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void MovingSprite::setRotateSpeed(int value)
|
void MovingSprite::setRotateSpeed(int value)
|
||||||
{
|
{
|
||||||
|
if (value < 1)
|
||||||
|
{
|
||||||
|
rotateSpeed = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
rotateSpeed = value;
|
rotateSpeed = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
@@ -324,15 +335,6 @@ SDL_Rect MovingSprite::getRect()
|
|||||||
return rect;
|
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
|
// Deshace el último movimiento
|
||||||
void MovingSprite::undoMove()
|
void MovingSprite::undoMove()
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,7 @@ protected:
|
|||||||
int rotateSpeed; // Velocidad de giro
|
int rotateSpeed; // Velocidad de giro
|
||||||
double rotateAmount; // Cantidad de grados a girar en cada iteración
|
double rotateAmount; // Cantidad de grados a girar en cada iteración
|
||||||
int counter; // Contador interno
|
int counter; // Contador interno
|
||||||
SDL_Point center; // Centro de rotación
|
SDL_Point *center; // Centro de rotación
|
||||||
SDL_RendererFlip currentFlip; // Indica como se voltea el sprite
|
SDL_RendererFlip currentFlip; // Indica como se voltea el sprite
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -88,8 +88,8 @@ public:
|
|||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint16 getRotateSpeed();
|
Uint16 getRotateSpeed();
|
||||||
|
|
||||||
// Establece la posición del objeto
|
// Establece la posición y el tamaño del objeto
|
||||||
void setPos(SDL_Rect rect);
|
void setRect(SDL_Rect rect);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setPosX(float value);
|
void setPosX(float value);
|
||||||
@@ -151,9 +151,6 @@ public:
|
|||||||
// Devuelve el rectangulo donde está el sprite
|
// Devuelve el rectangulo donde está el sprite
|
||||||
SDL_Rect getRect();
|
SDL_Rect getRect();
|
||||||
|
|
||||||
// Establece los valores de posición y tamaño del sprite
|
|
||||||
void setRect(SDL_Rect rect);
|
|
||||||
|
|
||||||
// Deshace el último movimiento
|
// Deshace el último movimiento
|
||||||
void undoMove();
|
void undoMove();
|
||||||
|
|
||||||
@@ -21,8 +21,10 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, i
|
|||||||
|
|
||||||
// Crea la textura donde se dibujan los graficos del juego
|
// Crea la textura donde se dibujan los graficos del juego
|
||||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
||||||
if (gameCanvas == NULL)
|
if (gameCanvas == nullptr)
|
||||||
|
{
|
||||||
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
setVideoMode(options->fullScreenMode);
|
setVideoMode(options->fullScreenMode);
|
||||||
@@ -59,14 +61,14 @@ void Screen::start()
|
|||||||
void Screen::blit()
|
void Screen::blit()
|
||||||
{
|
{
|
||||||
// Vuelve a dejar el renderizador en modo normal
|
// Vuelve a dejar el renderizador en modo normal
|
||||||
SDL_SetRenderTarget(renderer, NULL);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
// Borra el contenido previo
|
// Borra el contenido previo
|
||||||
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||||
SDL_RenderCopy(renderer, gameCanvas, NULL, &dest);
|
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
||||||
|
|
||||||
// Muestra por pantalla el renderizador
|
// Muestra por pantalla el renderizador
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
@@ -344,7 +346,7 @@ void Screen::renderSpectrumFade()
|
|||||||
const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght;
|
const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght;
|
||||||
const int max = spectrumColor.size() - 1;
|
const int max = spectrumColor.size() - 1;
|
||||||
const int index = max + (0 - max) * step;
|
const int index = max + (0 - max) * step;
|
||||||
const color_t c = spectrumColor[index];
|
const color_t c = spectrumColor.at(index);
|
||||||
SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b);
|
SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ Sprite::Sprite(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *rend
|
|||||||
this->texture = texture;
|
this->texture = texture;
|
||||||
|
|
||||||
// Establece el rectangulo de donde coger la imagen
|
// Establece el rectangulo de donde coger la imagen
|
||||||
spriteClip = {x, y, w, h};
|
spriteClip = {0, 0, w, h};
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
enabled = true;
|
enabled = true;
|
||||||
@@ -41,7 +41,7 @@ Sprite::Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer)
|
|||||||
this->texture = texture;
|
this->texture = texture;
|
||||||
|
|
||||||
// Establece el rectangulo de donde coger la imagen
|
// Establece el rectangulo de donde coger la imagen
|
||||||
spriteClip = {x, y, w, h};
|
spriteClip = {0, 0, w, h};
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
enabled = true;
|
enabled = true;
|
||||||
@@ -148,6 +148,12 @@ void Sprite::setTexture(LTexture *texture)
|
|||||||
this->texture = texture;
|
this->texture = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
SDL_Renderer *Sprite::getRenderer()
|
||||||
|
{
|
||||||
|
return renderer;
|
||||||
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Sprite::setRenderer(SDL_Renderer *renderer)
|
void Sprite::setRenderer(SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
@@ -74,6 +74,9 @@ public:
|
|||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setTexture(LTexture *texture);
|
void setTexture(LTexture *texture);
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
SDL_Renderer *getRenderer();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setRenderer(SDL_Renderer *renderer);
|
void setRenderer(SDL_Renderer *renderer);
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Ogg Vorbis audio decoder - v1.22 - public domain
|
// Ogg Vorbis audio decoder - v1.20 - public domain
|
||||||
// http://nothings.org/stb_vorbis/
|
// http://nothings.org/stb_vorbis/
|
||||||
//
|
//
|
||||||
// Original version written by Sean Barrett in 2007.
|
// Original version written by Sean Barrett in 2007.
|
||||||
@@ -29,15 +29,12 @@
|
|||||||
// Bernhard Wodo Evan Balster github:alxprd
|
// Bernhard Wodo Evan Balster github:alxprd
|
||||||
// Tom Beaumont Ingo Leitgeb Nicolas Guillemot
|
// Tom Beaumont Ingo Leitgeb Nicolas Guillemot
|
||||||
// Phillip Bennefall Rohit Thiago Goulart
|
// Phillip Bennefall Rohit Thiago Goulart
|
||||||
// github:manxorist Saga Musix github:infatum
|
// github:manxorist saga musix github:infatum
|
||||||
// Timur Gagiev Maxwell Koo Peter Waller
|
// Timur Gagiev Maxwell Koo Peter Waller
|
||||||
// github:audinowho Dougall Johnson David Reid
|
// github:audinowho Dougall Johnson David Reid
|
||||||
// github:Clownacy Pedro J. Estebanez Remi Verschelde
|
// github:Clownacy Pedro J. Estebanez Remi Verschelde
|
||||||
// AnthoFoxo github:morlat Gabriel Ravier
|
|
||||||
//
|
//
|
||||||
// Partial history:
|
// Partial history:
|
||||||
// 1.22 - 2021-07-11 - various small fixes
|
|
||||||
// 1.21 - 2021-07-02 - fix bug for files with no comments
|
|
||||||
// 1.20 - 2020-07-11 - several small fixes
|
// 1.20 - 2020-07-11 - several small fixes
|
||||||
// 1.19 - 2020-02-05 - warnings
|
// 1.19 - 2020-02-05 - warnings
|
||||||
// 1.18 - 2020-02-02 - fix seek bugs; parse header comments; misc warnings etc.
|
// 1.18 - 2020-02-02 - fix seek bugs; parse header comments; misc warnings etc.
|
||||||
@@ -223,12 +220,6 @@ extern int stb_vorbis_decode_frame_pushdata(
|
|||||||
// channel. In other words, (*output)[0][0] contains the first sample from
|
// channel. In other words, (*output)[0][0] contains the first sample from
|
||||||
// the first channel, and (*output)[1][0] contains the first sample from
|
// the first channel, and (*output)[1][0] contains the first sample from
|
||||||
// the second channel.
|
// the second channel.
|
||||||
//
|
|
||||||
// *output points into stb_vorbis's internal output buffer storage; these
|
|
||||||
// buffers are owned by stb_vorbis and application code should not free
|
|
||||||
// them or modify their contents. They are transient and will be overwritten
|
|
||||||
// once you ask for more data to get decoded, so be sure to grab any data
|
|
||||||
// you need before then.
|
|
||||||
|
|
||||||
extern void stb_vorbis_flush_pushdata(stb_vorbis *f);
|
extern void stb_vorbis_flush_pushdata(stb_vorbis *f);
|
||||||
// inform stb_vorbis that your next datablock will not be contiguous with
|
// inform stb_vorbis that your next datablock will not be contiguous with
|
||||||
@@ -588,7 +579,7 @@ enum STBVorbisError
|
|||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
#if defined(__linux__) || defined(__linux) || defined(__sun__) || defined(__EMSCRIPTEN__) || defined(__NEWLIB__)
|
#if defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__) || defined(__NEWLIB__)
|
||||||
#include <alloca.h>
|
#include <alloca.h>
|
||||||
#endif
|
#endif
|
||||||
#else // STB_VORBIS_NO_CRT
|
#else // STB_VORBIS_NO_CRT
|
||||||
@@ -655,12 +646,6 @@ typedef signed int int32;
|
|||||||
|
|
||||||
typedef float codetype;
|
typedef float codetype;
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define STBV_NOTUSED(v) (void)(v)
|
|
||||||
#else
|
|
||||||
#define STBV_NOTUSED(v) (void)sizeof(v)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// @NOTE
|
// @NOTE
|
||||||
//
|
//
|
||||||
// Some arrays below are tagged "//varies", which means it's actually
|
// Some arrays below are tagged "//varies", which means it's actually
|
||||||
@@ -1061,7 +1046,7 @@ static float float32_unpack(uint32 x)
|
|||||||
uint32 sign = x & 0x80000000;
|
uint32 sign = x & 0x80000000;
|
||||||
uint32 exp = (x & 0x7fe00000) >> 21;
|
uint32 exp = (x & 0x7fe00000) >> 21;
|
||||||
double res = sign ? -(double)mantissa : (double)mantissa;
|
double res = sign ? -(double)mantissa : (double)mantissa;
|
||||||
return (float) ldexp((float)res, (int)exp-788);
|
return (float) ldexp((float)res, exp-788);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1092,7 +1077,6 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values)
|
|||||||
// find the first entry
|
// find the first entry
|
||||||
for (k=0; k < n; ++k) if (len[k] < NO_CODE) break;
|
for (k=0; k < n; ++k) if (len[k] < NO_CODE) break;
|
||||||
if (k == n) { assert(c->sorted_entries == 0); return TRUE; }
|
if (k == n) { assert(c->sorted_entries == 0); return TRUE; }
|
||||||
assert(len[k] < 32); // no error return required, code reading lens checks this
|
|
||||||
// add to the list
|
// add to the list
|
||||||
add_entry(c, 0, k, m++, len[k], values);
|
add_entry(c, 0, k, m++, len[k], values);
|
||||||
// add all available leaves
|
// add all available leaves
|
||||||
@@ -1106,7 +1090,6 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values)
|
|||||||
uint32 res;
|
uint32 res;
|
||||||
int z = len[i], y;
|
int z = len[i], y;
|
||||||
if (z == NO_CODE) continue;
|
if (z == NO_CODE) continue;
|
||||||
assert(z < 32); // no error return required, code reading lens checks this
|
|
||||||
// find lowest available leaf (should always be earliest,
|
// find lowest available leaf (should always be earliest,
|
||||||
// which is what the specification calls for)
|
// which is what the specification calls for)
|
||||||
// note that this property, and the fact we can never have
|
// note that this property, and the fact we can never have
|
||||||
@@ -1116,10 +1099,12 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values)
|
|||||||
while (z > 0 && !available[z]) --z;
|
while (z > 0 && !available[z]) --z;
|
||||||
if (z == 0) { return FALSE; }
|
if (z == 0) { return FALSE; }
|
||||||
res = available[z];
|
res = available[z];
|
||||||
|
assert(z >= 0 && z < 32);
|
||||||
available[z] = 0;
|
available[z] = 0;
|
||||||
add_entry(c, bit_reverse(res), i, m++, len[i], values);
|
add_entry(c, bit_reverse(res), i, m++, len[i], values);
|
||||||
// propagate availability up the tree
|
// propagate availability up the tree
|
||||||
if (z != len[i]) {
|
if (z != len[i]) {
|
||||||
|
assert(len[i] >= 0 && len[i] < 32);
|
||||||
for (y=len[i]; y > z; --y) {
|
for (y=len[i]; y > z; --y) {
|
||||||
assert(available[y] == 0);
|
assert(available[y] == 0);
|
||||||
available[y] = res + (1 << (32-y));
|
available[y] = res + (1 << (32-y));
|
||||||
@@ -2592,33 +2577,34 @@ static void imdct_step3_inner_s_loop_ld654(int n, float *e, int i_off, float *A,
|
|||||||
|
|
||||||
while (z > base) {
|
while (z > base) {
|
||||||
float k00,k11;
|
float k00,k11;
|
||||||
float l00,l11;
|
|
||||||
|
|
||||||
k00 = z[-0] - z[ -8];
|
k00 = z[-0] - z[-8];
|
||||||
k11 = z[-1] - z[ -9];
|
k11 = z[-1] - z[-9];
|
||||||
l00 = z[-2] - z[-10];
|
z[-0] = z[-0] + z[-8];
|
||||||
l11 = z[-3] - z[-11];
|
z[-1] = z[-1] + z[-9];
|
||||||
z[ -0] = z[-0] + z[ -8];
|
z[-8] = k00;
|
||||||
z[ -1] = z[-1] + z[ -9];
|
z[-9] = k11 ;
|
||||||
z[ -2] = z[-2] + z[-10];
|
|
||||||
z[ -3] = z[-3] + z[-11];
|
|
||||||
z[ -8] = k00;
|
|
||||||
z[ -9] = k11;
|
|
||||||
z[-10] = (l00+l11) * A2;
|
|
||||||
z[-11] = (l11-l00) * A2;
|
|
||||||
|
|
||||||
k00 = z[ -4] - z[-12];
|
k00 = z[ -2] - z[-10];
|
||||||
|
k11 = z[ -3] - z[-11];
|
||||||
|
z[ -2] = z[ -2] + z[-10];
|
||||||
|
z[ -3] = z[ -3] + z[-11];
|
||||||
|
z[-10] = (k00+k11) * A2;
|
||||||
|
z[-11] = (k11-k00) * A2;
|
||||||
|
|
||||||
|
k00 = z[-12] - z[ -4]; // reverse to avoid a unary negation
|
||||||
k11 = z[ -5] - z[-13];
|
k11 = z[ -5] - z[-13];
|
||||||
l00 = z[ -6] - z[-14];
|
|
||||||
l11 = z[ -7] - z[-15];
|
|
||||||
z[ -4] = z[ -4] + z[-12];
|
z[ -4] = z[ -4] + z[-12];
|
||||||
z[ -5] = z[ -5] + z[-13];
|
z[ -5] = z[ -5] + z[-13];
|
||||||
|
z[-12] = k11;
|
||||||
|
z[-13] = k00;
|
||||||
|
|
||||||
|
k00 = z[-14] - z[ -6]; // reverse to avoid a unary negation
|
||||||
|
k11 = z[ -7] - z[-15];
|
||||||
z[ -6] = z[ -6] + z[-14];
|
z[ -6] = z[ -6] + z[-14];
|
||||||
z[ -7] = z[ -7] + z[-15];
|
z[ -7] = z[ -7] + z[-15];
|
||||||
z[-12] = k11;
|
z[-14] = (k00+k11) * A2;
|
||||||
z[-13] = -k00;
|
z[-15] = (k00-k11) * A2;
|
||||||
z[-14] = (l11-l00) * A2;
|
|
||||||
z[-15] = (l00+l11) * -A2;
|
|
||||||
|
|
||||||
iter_54(z);
|
iter_54(z);
|
||||||
iter_54(z-8);
|
iter_54(z-8);
|
||||||
@@ -3083,7 +3069,6 @@ static int do_floor(vorb *f, Mapping *map, int i, int n, float *target, YTYPE *f
|
|||||||
for (q=1; q < g->values; ++q) {
|
for (q=1; q < g->values; ++q) {
|
||||||
j = g->sorted_order[q];
|
j = g->sorted_order[q];
|
||||||
#ifndef STB_VORBIS_NO_DEFER_FLOOR
|
#ifndef STB_VORBIS_NO_DEFER_FLOOR
|
||||||
STBV_NOTUSED(step2_flag);
|
|
||||||
if (finalY[j] >= 0)
|
if (finalY[j] >= 0)
|
||||||
#else
|
#else
|
||||||
if (step2_flag[j])
|
if (step2_flag[j])
|
||||||
@@ -3186,7 +3171,6 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|||||||
|
|
||||||
// WINDOWING
|
// WINDOWING
|
||||||
|
|
||||||
STBV_NOTUSED(left_end);
|
|
||||||
n = f->blocksize[m->blockflag];
|
n = f->blocksize[m->blockflag];
|
||||||
map = &f->mapping[m->mapping];
|
map = &f->mapping[m->mapping];
|
||||||
|
|
||||||
@@ -3384,7 +3368,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|||||||
// this isn't to spec, but spec would require us to read ahead
|
// this isn't to spec, but spec would require us to read ahead
|
||||||
// and decode the size of all current frames--could be done,
|
// and decode the size of all current frames--could be done,
|
||||||
// but presumably it's not a commonly used feature
|
// but presumably it's not a commonly used feature
|
||||||
f->current_loc = 0u - n2; // start of first frame is positioned for discard (NB this is an intentional unsigned overflow/wrap-around)
|
f->current_loc = -n2; // start of first frame is positioned for discard
|
||||||
// we might have to discard samples "from" the next frame too,
|
// we might have to discard samples "from" the next frame too,
|
||||||
// if we're lapping a large block then a small at the start?
|
// if we're lapping a large block then a small at the start?
|
||||||
f->discard_samples_deferred = n - right_end;
|
f->discard_samples_deferred = n - right_end;
|
||||||
@@ -3658,10 +3642,8 @@ static int start_decoder(vorb *f)
|
|||||||
f->vendor[len] = (char)'\0';
|
f->vendor[len] = (char)'\0';
|
||||||
//user comments
|
//user comments
|
||||||
f->comment_list_length = get32_packet(f);
|
f->comment_list_length = get32_packet(f);
|
||||||
f->comment_list = NULL;
|
if (f->comment_list_length > 0) {
|
||||||
if (f->comment_list_length > 0)
|
f->comment_list = (char**)setup_malloc(f, sizeof(char*) * (f->comment_list_length));
|
||||||
{
|
|
||||||
f->comment_list = (char**) setup_malloc(f, sizeof(char*) * (f->comment_list_length));
|
|
||||||
if (f->comment_list == NULL) return error(f, VORBIS_outofmem);
|
if (f->comment_list == NULL) return error(f, VORBIS_outofmem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3885,7 +3867,8 @@ static int start_decoder(vorb *f)
|
|||||||
unsigned int div=1;
|
unsigned int div=1;
|
||||||
for (k=0; k < c->dimensions; ++k) {
|
for (k=0; k < c->dimensions; ++k) {
|
||||||
int off = (z / div) % c->lookup_values;
|
int off = (z / div) % c->lookup_values;
|
||||||
float val = mults[off]*c->delta_value + c->minimum_value + last;
|
float val = mults[off];
|
||||||
|
val = mults[off]*c->delta_value + c->minimum_value + last;
|
||||||
c->multiplicands[j*c->dimensions + k] = val;
|
c->multiplicands[j*c->dimensions + k] = val;
|
||||||
if (c->sequence_p)
|
if (c->sequence_p)
|
||||||
last = val;
|
last = val;
|
||||||
@@ -3968,7 +3951,7 @@ static int start_decoder(vorb *f)
|
|||||||
if (g->class_masterbooks[j] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
if (g->class_masterbooks[j] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
||||||
}
|
}
|
||||||
for (k=0; k < 1 << g->class_subclasses[j]; ++k) {
|
for (k=0; k < 1 << g->class_subclasses[j]; ++k) {
|
||||||
g->subclass_books[j][k] = (int16)get_bits(f,8)-1;
|
g->subclass_books[j][k] = get_bits(f,8)-1;
|
||||||
if (g->subclass_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
if (g->subclass_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4526,7 +4509,6 @@ stb_vorbis *stb_vorbis_open_pushdata(
|
|||||||
*error = VORBIS_need_more_data;
|
*error = VORBIS_need_more_data;
|
||||||
else
|
else
|
||||||
*error = p.error;
|
*error = p.error;
|
||||||
vorbis_deinit(&p);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
f = vorbis_alloc(&p);
|
f = vorbis_alloc(&p);
|
||||||
@@ -4584,7 +4566,7 @@ static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last)
|
|||||||
header[i] = get8(f);
|
header[i] = get8(f);
|
||||||
if (f->eof) return 0;
|
if (f->eof) return 0;
|
||||||
if (header[4] != 0) goto invalid;
|
if (header[4] != 0) goto invalid;
|
||||||
goal = header[22] + (header[23] << 8) + (header[24]<<16) + ((uint32)header[25]<<24);
|
goal = header[22] + (header[23] << 8) + (header[24]<<16) + (header[25]<<24);
|
||||||
for (i=22; i < 26; ++i)
|
for (i=22; i < 26; ++i)
|
||||||
header[i] = 0;
|
header[i] = 0;
|
||||||
crc = 0;
|
crc = 0;
|
||||||
@@ -4988,7 +4970,7 @@ unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f)
|
|||||||
// set. whoops!
|
// set. whoops!
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//previous_safe = last_page_loc+1; // NOTE: not used after this point, but note for debugging
|
previous_safe = last_page_loc+1;
|
||||||
last_page_loc = stb_vorbis_get_file_offset(f);
|
last_page_loc = stb_vorbis_get_file_offset(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5099,10 +5081,7 @@ stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const st
|
|||||||
stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc)
|
stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc)
|
||||||
{
|
{
|
||||||
stb_vorbis *f, p;
|
stb_vorbis *f, p;
|
||||||
if (!data) {
|
if (data == NULL) return NULL;
|
||||||
if (error) *error = VORBIS_unexpected_eof;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
vorbis_init(&p, alloc);
|
vorbis_init(&p, alloc);
|
||||||
p.stream = (uint8 *) data;
|
p.stream = (uint8 *) data;
|
||||||
p.stream_end = (uint8 *) data + len;
|
p.stream_end = (uint8 *) data + len;
|
||||||
@@ -5177,11 +5156,11 @@ static void copy_samples(short *dest, float *src, int len)
|
|||||||
|
|
||||||
static void compute_samples(int mask, short *output, int num_c, float **data, int d_offset, int len)
|
static void compute_samples(int mask, short *output, int num_c, float **data, int d_offset, int len)
|
||||||
{
|
{
|
||||||
#define STB_BUFFER_SIZE 32
|
#define BUFFER_SIZE 32
|
||||||
float buffer[STB_BUFFER_SIZE];
|
float buffer[BUFFER_SIZE];
|
||||||
int i,j,o,n = STB_BUFFER_SIZE;
|
int i,j,o,n = BUFFER_SIZE;
|
||||||
check_endianness();
|
check_endianness();
|
||||||
for (o = 0; o < len; o += STB_BUFFER_SIZE) {
|
for (o = 0; o < len; o += BUFFER_SIZE) {
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
if (o + n > len) n = len - o;
|
if (o + n > len) n = len - o;
|
||||||
for (j=0; j < num_c; ++j) {
|
for (j=0; j < num_c; ++j) {
|
||||||
@@ -5198,17 +5177,16 @@ static void compute_samples(int mask, short *output, int num_c, float **data, in
|
|||||||
output[o+i] = v;
|
output[o+i] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef STB_BUFFER_SIZE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compute_stereo_samples(short *output, int num_c, float **data, int d_offset, int len)
|
static void compute_stereo_samples(short *output, int num_c, float **data, int d_offset, int len)
|
||||||
{
|
{
|
||||||
#define STB_BUFFER_SIZE 32
|
#define BUFFER_SIZE 32
|
||||||
float buffer[STB_BUFFER_SIZE];
|
float buffer[BUFFER_SIZE];
|
||||||
int i,j,o,n = STB_BUFFER_SIZE >> 1;
|
int i,j,o,n = BUFFER_SIZE >> 1;
|
||||||
// o is the offset in the source data
|
// o is the offset in the source data
|
||||||
check_endianness();
|
check_endianness();
|
||||||
for (o = 0; o < len; o += STB_BUFFER_SIZE >> 1) {
|
for (o = 0; o < len; o += BUFFER_SIZE >> 1) {
|
||||||
// o2 is the offset in the output data
|
// o2 is the offset in the output data
|
||||||
int o2 = o << 1;
|
int o2 = o << 1;
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
@@ -5238,7 +5216,6 @@ static void compute_stereo_samples(short *output, int num_c, float **data, int d
|
|||||||
output[o2+i] = v;
|
output[o2+i] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef STB_BUFFER_SIZE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void convert_samples_short(int buf_c, short **buffer, int b_offset, int data_c, float **data, int d_offset, int samples)
|
static void convert_samples_short(int buf_c, short **buffer, int b_offset, int data_c, float **data, int d_offset, int samples)
|
||||||
@@ -5311,6 +5288,8 @@ int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short
|
|||||||
float **outputs;
|
float **outputs;
|
||||||
int len = num_shorts / channels;
|
int len = num_shorts / channels;
|
||||||
int n=0;
|
int n=0;
|
||||||
|
int z = f->channels;
|
||||||
|
if (z > channels) z = channels;
|
||||||
while (n < len) {
|
while (n < len) {
|
||||||
int k = f->channel_buffer_end - f->channel_buffer_start;
|
int k = f->channel_buffer_end - f->channel_buffer_start;
|
||||||
if (n+k >= len) k = len - n;
|
if (n+k >= len) k = len - n;
|
||||||
@@ -5329,6 +5308,8 @@ int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, in
|
|||||||
{
|
{
|
||||||
float **outputs;
|
float **outputs;
|
||||||
int n=0;
|
int n=0;
|
||||||
|
int z = f->channels;
|
||||||
|
if (z > channels) z = channels;
|
||||||
while (n < len) {
|
while (n < len) {
|
||||||
int k = f->channel_buffer_end - f->channel_buffer_start;
|
int k = f->channel_buffer_end - f->channel_buffer_start;
|
||||||
if (n+k >= len) k = len - n;
|
if (n+k >= len) k = len - n;
|
||||||
@@ -6,13 +6,12 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
texture = new LTexture(renderer, bitmapFile);
|
// Carga los offsets desde el fichero
|
||||||
sprite = new Sprite({0, 0, 0, 0}, texture, renderer);
|
initOffsetFromFile(textFile);
|
||||||
sprite->setTexture(texture);
|
|
||||||
sprite->setRenderer(renderer);
|
|
||||||
file = textFile;
|
|
||||||
|
|
||||||
init();
|
// Crea los objetos
|
||||||
|
texture = new LTexture(renderer, bitmapFile);
|
||||||
|
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -22,35 +21,6 @@ Text::~Text()
|
|||||||
delete sprite;
|
delete sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializador
|
|
||||||
void Text::init()
|
|
||||||
{
|
|
||||||
// Inicializa a cero el vector con las coordenadas
|
|
||||||
for (int i = 0; i < 128; ++i)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
offset[i].x = ((i - 32) % 15) * boxWidth;
|
|
||||||
offset[i].y = ((i - 32) / 15) * boxHeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escribe texto en pantalla
|
// Escribe texto en pantalla
|
||||||
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||||
{
|
{
|
||||||
@@ -139,10 +109,19 @@ int Text::lenght(std::string text, int kerning)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el vector de offsets desde un fichero
|
// Inicializa el vector de offsets desde un fichero
|
||||||
void Text::initOffsetFromFile()
|
void Text::initOffsetFromFile(std::string file)
|
||||||
{
|
{
|
||||||
|
// Inicializa a cero el vector con las coordenadas
|
||||||
|
for (int i = 0; i < 128; ++i)
|
||||||
|
{
|
||||||
|
offset[i].x = 0;
|
||||||
|
offset[i].y = 0;
|
||||||
|
offset[i].w = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abre el fichero para leer los valores
|
||||||
|
const std::string filename = file.substr(file.find_last_of("\\/") + 1).c_str();
|
||||||
std::ifstream rfile(file);
|
std::ifstream rfile(file);
|
||||||
printf("Reading file %s\n", file.c_str());
|
|
||||||
|
|
||||||
if (rfile.is_open() && rfile.good())
|
if (rfile.is_open() && rfile.good())
|
||||||
{
|
{
|
||||||
@@ -164,7 +143,9 @@ void Text::initOffsetFromFile()
|
|||||||
{
|
{
|
||||||
// Almacena solo las lineas impares
|
// Almacena solo las lineas impares
|
||||||
if (line_read % 2 == 1)
|
if (line_read % 2 == 1)
|
||||||
|
{
|
||||||
offset[index++].w = std::stoi(buffer);
|
offset[index++].w = std::stoi(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
// Limpia el buffer
|
// Limpia el buffer
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
@@ -172,14 +153,21 @@ void Text::initOffsetFromFile()
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
printf("Closing file %s\n\n", file.c_str());
|
printf("Text loaded: %s\n", filename.c_str());
|
||||||
rfile.close();
|
rfile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// El fichero no se puede abrir
|
// El fichero no se puede abrir
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Warning: Unable to open %s file\n", file.c_str());
|
printf("Warning: Unable to open %s file\n", filename.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||||
|
for (int i = 32; i < 128; ++i)
|
||||||
|
{
|
||||||
|
offset[i].x = ((i - 32) % 15) * boxWidth;
|
||||||
|
offset[i].y = ((i - 32) / 15) * boxHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,26 +15,24 @@
|
|||||||
class Text
|
class Text
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Sprite *sprite; // Objeto con los graficos para el texto
|
struct offset_t
|
||||||
|
|
||||||
struct Offset
|
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int w;
|
int w;
|
||||||
};
|
};
|
||||||
Offset offset[128]; // Vector con las posiciones y ancho de cada letra
|
|
||||||
|
|
||||||
int boxWidth; // Anchura de la caja de cada caracter en el png
|
// Objetos
|
||||||
int boxHeight; // Altura de la caja de cada caracter en el png
|
Sprite *sprite; // Objeto con los graficos para el texto
|
||||||
std::string file; // Fichero con los descriptores de la fuente
|
|
||||||
LTexture *texture; // Textura con los bitmaps del texto
|
LTexture *texture; // Textura con los bitmaps del texto
|
||||||
|
|
||||||
// Inicializador
|
// Variables
|
||||||
void init();
|
int boxWidth; // Anchura de la caja de cada caracter en el png
|
||||||
|
int boxHeight; // Altura de la caja de cada caracter en el png
|
||||||
|
offset_t offset[128]; // Vector con las posiciones y ancho de cada letra
|
||||||
|
|
||||||
// Inicializa el vector de offsets desde un fichero
|
// Inicializa el vector de offsets desde un fichero
|
||||||
void initOffsetFromFile();
|
void initOffsetFromFile(std::string file);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -350,91 +350,91 @@ void Director::initInput()
|
|||||||
bool Director::setFileList()
|
bool Director::setFileList()
|
||||||
{
|
{
|
||||||
// Ficheros del mapa
|
// Ficheros del mapa
|
||||||
asset->add("/data/map/01.map", data);
|
asset->add("/data/map/01.map", t_data);
|
||||||
asset->add("/data/map/01.tmx", data);
|
asset->add("/data/map/01.tmx", t_data);
|
||||||
asset->add("/data/map/01.ene", data);
|
asset->add("/data/map/01.ene", t_data);
|
||||||
asset->add("/data/map/02.map", data);
|
asset->add("/data/map/02.map", t_data);
|
||||||
asset->add("/data/map/02.tmx", data);
|
asset->add("/data/map/02.tmx", t_data);
|
||||||
asset->add("/data/map/02.ene", data);
|
asset->add("/data/map/02.ene", t_data);
|
||||||
asset->add("/data/map/03.map", data);
|
asset->add("/data/map/03.map", t_data);
|
||||||
asset->add("/data/map/03.tmx", data);
|
asset->add("/data/map/03.tmx", t_data);
|
||||||
asset->add("/data/map/03.ene", data);
|
asset->add("/data/map/03.ene", t_data);
|
||||||
asset->add("/data/map/04.map", data);
|
asset->add("/data/map/04.map", t_data);
|
||||||
asset->add("/data/map/04.tmx", data);
|
asset->add("/data/map/04.tmx", t_data);
|
||||||
asset->add("/data/map/05.map", data);
|
asset->add("/data/map/05.map", t_data);
|
||||||
asset->add("/data/map/05.tmx", data);
|
asset->add("/data/map/05.tmx", t_data);
|
||||||
asset->add("/data/map/06.map", data);
|
asset->add("/data/map/06.map", t_data);
|
||||||
asset->add("/data/map/06.tmx", data);
|
asset->add("/data/map/06.tmx", t_data);
|
||||||
asset->add("/data/map/07.map", data);
|
asset->add("/data/map/07.map", t_data);
|
||||||
asset->add("/data/map/07.tmx", data);
|
asset->add("/data/map/07.tmx", t_data);
|
||||||
asset->add("/data/map/08.map", data);
|
asset->add("/data/map/08.map", t_data);
|
||||||
asset->add("/data/map/08.tmx", data);
|
asset->add("/data/map/08.tmx", t_data);
|
||||||
asset->add("/data/map/09.map", data);
|
asset->add("/data/map/09.map", t_data);
|
||||||
asset->add("/data/map/09.tmx", data);
|
asset->add("/data/map/09.tmx", t_data);
|
||||||
asset->add("/data/map/10.map", data);
|
asset->add("/data/map/10.map", t_data);
|
||||||
asset->add("/data/map/10.tmx", data);
|
asset->add("/data/map/10.tmx", t_data);
|
||||||
asset->add("/data/map/tiles_surface.png", bitmap);
|
asset->add("/data/map/tiles_surface.png", t_bitmap);
|
||||||
|
|
||||||
// Ficheros de configuración
|
// Ficheros de configuración
|
||||||
asset->add("/data/config/config.txt", data, false);
|
asset->add("/data/config/config.txt", t_data, false);
|
||||||
asset->add("/data/input/gamecontrollerdb.txt", data);
|
asset->add("/data/input/gamecontrollerdb.txt", t_data);
|
||||||
|
|
||||||
// Ficheros del jugador
|
// Ficheros del jugador
|
||||||
asset->add("/data/player/player.png", bitmap);
|
asset->add("/data/player/player.png", t_bitmap);
|
||||||
asset->add("/data/player/player.ani", data);
|
asset->add("/data/player/player.ani", t_data);
|
||||||
|
|
||||||
// Ficheros de sonido
|
// Ficheros de sonido
|
||||||
asset->add("/data/sound/sound_player_coin.wav", sound);
|
asset->add("/data/sound/sound_player_coin.wav", t_sound);
|
||||||
asset->add("/data/sound/sound_player_death.wav", sound);
|
asset->add("/data/sound/sound_player_death.wav", t_sound);
|
||||||
asset->add("/data/sound/sound_drop_enemy.wav", sound);
|
asset->add("/data/sound/sound_drop_enemy.wav", t_sound);
|
||||||
asset->add("/data/sound/sound_drop_splat.wav", sound);
|
asset->add("/data/sound/sound_drop_splat.wav", t_sound);
|
||||||
asset->add("/data/sound/sound_player_jump.wav", sound);
|
asset->add("/data/sound/sound_player_jump.wav", t_sound);
|
||||||
asset->add("/data/sound/sound_menu_logo.wav", sound);
|
asset->add("/data/sound/sound_menu_logo.wav", t_sound);
|
||||||
asset->add("/data/sound/sound_menu_start.wav", sound);
|
asset->add("/data/sound/sound_menu_start.wav", t_sound);
|
||||||
asset->add("/data/sound/sound_menu_select.wav", sound);
|
asset->add("/data/sound/sound_menu_select.wav", t_sound);
|
||||||
asset->add("/data/sound/sound_menu_cancel.wav", sound);
|
asset->add("/data/sound/sound_menu_cancel.wav", t_sound);
|
||||||
asset->add("/data/sound/sound_menu_move.wav", sound);
|
asset->add("/data/sound/sound_menu_move.wav", t_sound);
|
||||||
|
|
||||||
// Ficheros con musica
|
// Ficheros con musica
|
||||||
asset->add("/data/music/music_title.ogg", music);
|
asset->add("/data/music/music_title.ogg", t_music);
|
||||||
asset->add("/data/music/music_surface.ogg", music);
|
asset->add("/data/music/music_surface.ogg", t_music);
|
||||||
asset->add("/data/music/music_volcano.ogg", music);
|
asset->add("/data/music/music_volcano.ogg", t_music);
|
||||||
|
|
||||||
// Ficheros de fuentes de texto
|
// Ficheros de fuentes de texto
|
||||||
asset->add("/data/font/debug.png", font);
|
asset->add("/data/font/debug.png", t_font);
|
||||||
asset->add("/data/font/debug.txt", font);
|
asset->add("/data/font/debug.txt", t_font);
|
||||||
asset->add("/data/font/dogica.png", font);
|
asset->add("/data/font/dogica.png", t_font);
|
||||||
asset->add("/data/font/dogica.txt", font);
|
asset->add("/data/font/dogica.txt", t_font);
|
||||||
asset->add("/data/font/smb2.png", font);
|
asset->add("/data/font/smb2.png", t_font);
|
||||||
asset->add("/data/font/smb2.txt", font);
|
asset->add("/data/font/smb2.txt", t_font);
|
||||||
|
|
||||||
// Ficheros de enemigos
|
// Ficheros de enemigos
|
||||||
asset->add("/data/actors/enemies/walking_eye.png", bitmap);
|
asset->add("/data/actors/enemies/walking_eye.png", t_bitmap);
|
||||||
asset->add("/data/actors/enemies/walking_eye.ani", data);
|
asset->add("/data/actors/enemies/walking_eye.ani", t_data);
|
||||||
asset->add("/data/actors/enemies/bug.png", bitmap);
|
asset->add("/data/actors/enemies/bug.png", t_bitmap);
|
||||||
asset->add("/data/actors/enemies/bug.ani", data);
|
asset->add("/data/actors/enemies/bug.ani", t_data);
|
||||||
asset->add("/data/actors/enemies/flying_eye.png", bitmap);
|
asset->add("/data/actors/enemies/flying_eye.png", t_bitmap);
|
||||||
asset->add("/data/actors/enemies/flying_eye.ani", data);
|
asset->add("/data/actors/enemies/flying_eye.ani", t_data);
|
||||||
asset->add("/data/actors/enemies/flying_eye_horn.png", bitmap);
|
asset->add("/data/actors/enemies/flying_eye_horn.png", t_bitmap);
|
||||||
asset->add("/data/actors/enemies/flying_eye_horn.ani", data);
|
asset->add("/data/actors/enemies/flying_eye_horn.ani", t_data);
|
||||||
asset->add("/data/actors/enemies/manzana.png", bitmap);
|
asset->add("/data/actors/enemies/manzana.png", t_bitmap);
|
||||||
asset->add("/data/actors/enemies/manzana.ani", data);
|
asset->add("/data/actors/enemies/manzana.ani", t_data);
|
||||||
|
|
||||||
// Ficheros de actores
|
// Ficheros de actores
|
||||||
asset->add("/data/actors/moving_platform.png", bitmap);
|
asset->add("/data/actors/moving_platform.png", t_bitmap);
|
||||||
asset->add("/data/actors/moving_platform.ani", data);
|
asset->add("/data/actors/moving_platform.ani", t_data);
|
||||||
asset->add("/data/actors/items/diamond.png", bitmap);
|
asset->add("/data/actors/items/diamond.png", t_bitmap);
|
||||||
asset->add("/data/actors/items/diamond.ani", data);
|
asset->add("/data/actors/items/diamond.ani", t_data);
|
||||||
|
|
||||||
// Ficheros del logo
|
// Ficheros del logo
|
||||||
asset->add("/data/logo/logo.png", bitmap);
|
asset->add("/data/logo/logo.png", t_bitmap);
|
||||||
|
|
||||||
// Ficheros de la intro
|
// Ficheros de la intro
|
||||||
asset->add("/data/intro/intro.png", bitmap);
|
asset->add("/data/intro/intro.png", t_bitmap);
|
||||||
asset->add("/data/intro/intro.ani", data);
|
asset->add("/data/intro/intro.ani", t_data);
|
||||||
|
|
||||||
// Ficheros de menu
|
// Ficheros de menu
|
||||||
asset->add("/data/menu/title.men", data);
|
asset->add("/data/menu/title.men", t_data);
|
||||||
|
|
||||||
return asset->check();
|
return asset->check();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <string>
|
#include "common/asset.h"
|
||||||
#include "asset.h"
|
#include "common/const.h"
|
||||||
#include "jail_audio.h"
|
#include "common/debug.h"
|
||||||
|
#include "common/input.h"
|
||||||
|
#include "common/jail_audio.h"
|
||||||
|
#include "common/screen.h"
|
||||||
|
#include "common/utils.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "input.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "screen.h"
|
|
||||||
#include "logo.h"
|
|
||||||
#include "intro.h"
|
#include "intro.h"
|
||||||
|
#include "logo.h"
|
||||||
#include "title.h"
|
#include "title.h"
|
||||||
#include "debug.h"
|
#include <string>
|
||||||
#include "const.h"
|
|
||||||
|
|
||||||
#ifndef PROG_H
|
#ifndef PROG_H
|
||||||
#define PROG_H
|
#define PROG_H
|
||||||
|
|
||||||
|
// Textos
|
||||||
|
#define WINDOW_CAPTION "Volcano"
|
||||||
|
|
||||||
class Director
|
class Director
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "common/animatedsprite.h"
|
||||||
#include "asset.h"
|
#include "common/asset.h"
|
||||||
#include "animatedsprite.h"
|
#include "common/utils.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifndef ENEMY_H
|
#ifndef ENEMY_H
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "common/asset.h"
|
||||||
#include "asset.h"
|
#include "common/utils.h"
|
||||||
#include "enemy.h"
|
|
||||||
#include "enemy_path.h"
|
#include "enemy_path.h"
|
||||||
|
#include "enemy.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, D
|
|||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
|
|
||||||
section.name = SECTION_PROG_GAME;
|
section.name = SECTION_PROG_GAME;
|
||||||
section.subsection = SUBSECTION_GAME_PLAY;
|
section.subsection = 0;
|
||||||
|
|
||||||
musicEnabled = !debug->getEnabled();
|
musicEnabled = !debug->getEnabled();
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ section_t Game::run()
|
|||||||
while (section.name == SECTION_PROG_GAME)
|
while (section.name == SECTION_PROG_GAME)
|
||||||
{
|
{
|
||||||
// Sección juego jugando
|
// Sección juego jugando
|
||||||
if (section.subsection == SUBSECTION_GAME_PLAY)
|
if (section.subsection == 0)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
render();
|
render();
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "common/asset.h"
|
||||||
#include "asset.h"
|
#include "common/debug.h"
|
||||||
#include "screen.h"
|
#include "common/input.h"
|
||||||
#include "input.h"
|
#include "common/screen.h"
|
||||||
|
#include "common/text.h"
|
||||||
|
#include "common/utils.h"
|
||||||
|
#include "enemy_engine.h"
|
||||||
|
#include "item_tracker.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "item_tracker.h"
|
|
||||||
#include "enemy_engine.h"
|
|
||||||
#include "text.h"
|
|
||||||
#include "scoreboard.h"
|
#include "scoreboard.h"
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
#define GAME_H
|
#define GAME_H
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "const.h"
|
#include "common/animatedsprite.h"
|
||||||
#include "asset.h"
|
#include "common/asset.h"
|
||||||
#include "utils.h"
|
#include "common/const.h"
|
||||||
#include "screen.h"
|
#include "common/jail_audio.h"
|
||||||
#include "animatedsprite.h"
|
#include "common/screen.h"
|
||||||
#include "jail_audio.h"
|
#include "common/utils.h"
|
||||||
|
|
||||||
#ifndef INTRO_H
|
#ifndef INTRO_H
|
||||||
#define INTRO_H
|
#define INTRO_H
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "common/utils.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "const.h"
|
#include "common/asset.h"
|
||||||
#include "utils.h"
|
#include "common/const.h"
|
||||||
#include "sprite.h"
|
#include "common/jail_audio.h"
|
||||||
#include "screen.h"
|
#include "common/screen.h"
|
||||||
#include "asset.h"
|
#include "common/sprite.h"
|
||||||
#include "jail_audio.h"
|
#include "common/utils.h"
|
||||||
#include "const.h"
|
|
||||||
|
|
||||||
#ifndef LOGO_H
|
#ifndef LOGO_H
|
||||||
#define LOGO_H
|
#define LOGO_H
|
||||||
|
|||||||
14
source/map.h
14
source/map.h
@@ -1,16 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
|
||||||
#include "asset.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include "item_tracker.h"
|
|
||||||
#include "actor_moving_platform.h"
|
|
||||||
#include "actor_diamond.h"
|
#include "actor_diamond.h"
|
||||||
|
#include "actor_moving_platform.h"
|
||||||
|
#include "common/asset.h"
|
||||||
|
#include "common/const.h"
|
||||||
|
#include "common/utils.h"
|
||||||
|
#include "item_tracker.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#ifndef MAP_H
|
#ifndef MAP_H
|
||||||
#define MAP_H
|
#define MAP_H
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "jail_audio.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "input.h"
|
|
||||||
#include "animatedsprite.h"
|
|
||||||
#include "asset.h"
|
|
||||||
#include "map.h"
|
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "debug.h"
|
#include "common/animatedsprite.h"
|
||||||
|
#include "common/asset.h"
|
||||||
|
#include "common/debug.h"
|
||||||
|
#include "common/input.h"
|
||||||
|
#include "common/jail_audio.h"
|
||||||
|
#include "common/utils.h"
|
||||||
|
#include "map.h"
|
||||||
|
|
||||||
#ifndef PLAYER_H
|
#ifndef PLAYER_H
|
||||||
#define PLAYER_H
|
#define PLAYER_H
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "common/asset.h"
|
||||||
#include "text.h"
|
#include "common/const.h"
|
||||||
#include "asset.h"
|
#include "common/input.h"
|
||||||
#include "sprite.h"
|
#include "common/sprite.h"
|
||||||
#include "const.h"
|
#include "common/text.h"
|
||||||
#include "input.h"
|
#include "common/utils.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifndef SCOREBOARD_H
|
#ifndef SCOREBOARD_H
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "const.h"
|
#include "common/animatedsprite.h"
|
||||||
#include "asset.h"
|
#include "common/asset.h"
|
||||||
#include "utils.h"
|
#include "common/const.h"
|
||||||
#include "input.h"
|
#include "common/input.h"
|
||||||
#include "screen.h"
|
#include "common/jail_audio.h"
|
||||||
#include "text.h"
|
#include "common/menu.h"
|
||||||
#include "menu.h"
|
#include "common/screen.h"
|
||||||
#include "animatedsprite.h"
|
#include "common/text.h"
|
||||||
#include "jail_audio.h"
|
#include "common/utils.h"
|
||||||
|
|
||||||
#ifndef TITLE_H
|
#ifndef TITLE_H
|
||||||
#define TITLE_H
|
#define TITLE_H
|
||||||
|
|
||||||
|
#define TEXT_COPYRIGHT "2016,2022 JAILDESIGNER & JAILBROTHER"
|
||||||
|
#define VERSION "0.6"
|
||||||
|
|
||||||
// Clase Intro
|
// Clase Intro
|
||||||
class Title
|
class Title
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user