Reorganizados los .cpp i .h en la carpeta common
This commit is contained in:
14
Makefile
14
Makefile
@@ -1,17 +1,15 @@
|
||||
executable = volcano_2022
|
||||
source = source/*.cpp source/common/*.cpp
|
||||
|
||||
windows:
|
||||
@echo off
|
||||
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:
|
||||
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:
|
||||
mkdir -p bin
|
||||
g++ source/*.cpp -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
|
||||
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
|
||||
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
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "asset.h"
|
||||
#include "animatedsprite.h"
|
||||
#include "common/animatedsprite.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/utils.h"
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
}
|
||||
@@ -1,74 +1,92 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "movingsprite.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#ifndef ANIMATEDSPRITE_H
|
||||
#define ANIMATEDSPRITE_H
|
||||
|
||||
// Clase AnimatedSprite
|
||||
class AnimatedSprite : public MovingSprite
|
||||
{
|
||||
private:
|
||||
struct t_animation
|
||||
{
|
||||
std::string name; // Nombre de la animacion
|
||||
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
|
||||
int speed; // Velocidad de la animación
|
||||
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
|
||||
bool completed; // Indica si ha finalizado la animación
|
||||
int currentFrame; // Frame actual
|
||||
int counter; // Contador para las animaciones
|
||||
};
|
||||
std::vector<t_animation> animation; // Vector con las diferentes animaciones
|
||||
int currentAnimation; // Animacion activa
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "");
|
||||
|
||||
// Destructor
|
||||
~AnimatedSprite();
|
||||
|
||||
// Calcula el frame correspondiente a la animación actual
|
||||
void animate();
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
void setCurrentFrame(int num);
|
||||
|
||||
// Establece el valor del contador
|
||||
void setAnimationCounter(std::string name, int num);
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void setAnimationSpeed(std::string name, int speed);
|
||||
|
||||
// Establece el frame al que vuelve la animación al finalizar
|
||||
void setAnimationLoop(std::string name, int loop);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAnimationCompleted(std::string name, bool value);
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool animationIsCompleted();
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
SDL_Rect getAnimationClip(std::string name, Uint8 index);
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int getIndex(std::string name);
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
bool load(std::string filePath);
|
||||
|
||||
// Establece la animacion actual
|
||||
void setCurrentAnimation(std::string name = "default");
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update();
|
||||
};
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "movingsprite.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef ANIMATEDSPRITE_H
|
||||
#define ANIMATEDSPRITE_H
|
||||
|
||||
// Clase AnimatedSprite
|
||||
class AnimatedSprite : public MovingSprite
|
||||
{
|
||||
private:
|
||||
struct t_animation
|
||||
{
|
||||
std::string name; // Nombre de la animacion
|
||||
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
|
||||
int speed; // Velocidad de la animación
|
||||
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
|
||||
bool completed; // Indica si ha finalizado la animación
|
||||
int currentFrame; // Frame actual
|
||||
int counter; // Contador para las animaciones
|
||||
};
|
||||
std::vector<t_animation> animation; // Vector con las diferentes animaciones
|
||||
int currentAnimation; // Animacion activa
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
|
||||
|
||||
// Destructor
|
||||
~AnimatedSprite();
|
||||
|
||||
// Calcula el frame correspondiente a la animación actual
|
||||
void animate();
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
void setCurrentFrame(int num);
|
||||
|
||||
// Establece el valor del contador
|
||||
void setAnimationCounter(std::string name, int num);
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void setAnimationSpeed(std::string name, int speed);
|
||||
void setAnimationSpeed(int index, int speed);
|
||||
|
||||
// Establece el frame al que vuelve la animación al finalizar
|
||||
void setAnimationLoop(std::string name, int loop);
|
||||
void setAnimationLoop(int index, int loop);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAnimationCompleted(std::string name, bool value);
|
||||
void setAnimationCompleted(int index, bool value);
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool animationIsCompleted();
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
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
|
||||
int getIndex(std::string name);
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
bool loadFromFile(std::string filePath);
|
||||
|
||||
// Carga la animación desde un vector
|
||||
bool loadFromVector(std::vector<std::string> *source);
|
||||
|
||||
// Establece la animacion actual
|
||||
void setCurrentAnimation(std::string name = "default");
|
||||
void setCurrentAnimation(int index = 0);
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update();
|
||||
|
||||
// OLD - Establece el rectangulo para un frame de una animación
|
||||
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
||||
|
||||
// OLD - Establece el contador para todas las animaciones
|
||||
void setAnimationCounter(int value);
|
||||
|
||||
// Reinicia la animación
|
||||
void resetAnimation();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -4,7 +4,7 @@
|
||||
Asset::Asset(std::string path)
|
||||
{
|
||||
executablePath = path;
|
||||
longest_name = 0;
|
||||
longestName = 0;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -16,13 +16,13 @@ Asset::~Asset()
|
||||
void Asset::add(std::string file, enum assetType type, bool required)
|
||||
{
|
||||
item_t temp;
|
||||
temp.file = executablePath + "/.." + file;
|
||||
temp.file = executablePath + file;
|
||||
temp.type = type;
|
||||
temp.required = required;
|
||||
fileList.push_back(temp);
|
||||
|
||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
||||
longest_name = SDL_max(longest_name, filename.size());
|
||||
longestName = SDL_max(longestName, filename.size());
|
||||
}
|
||||
|
||||
// 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");
|
||||
|
||||
// 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
|
||||
bool any = false;
|
||||
@@ -106,7 +106,7 @@ bool Asset::checkFile(std::string path)
|
||||
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());
|
||||
|
||||
return success;
|
||||
@@ -117,39 +117,39 @@ std::string Asset::getTypeName(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case bitmap:
|
||||
case t_bitmap:
|
||||
return "BITMAP";
|
||||
break;
|
||||
|
||||
case music:
|
||||
case t_music:
|
||||
return "MUSIC";
|
||||
break;
|
||||
|
||||
case sound:
|
||||
case t_sound:
|
||||
return "SOUND";
|
||||
break;
|
||||
|
||||
case font:
|
||||
case t_font:
|
||||
return "FONT";
|
||||
break;
|
||||
|
||||
case lang:
|
||||
case t_lang:
|
||||
return "LANG";
|
||||
break;
|
||||
|
||||
case data:
|
||||
case t_data:
|
||||
return "DATA";
|
||||
break;
|
||||
|
||||
case room:
|
||||
case t_room:
|
||||
return "ROOM";
|
||||
break;
|
||||
|
||||
case enemy:
|
||||
case t_enemy:
|
||||
return "ENEMY";
|
||||
break;
|
||||
|
||||
case item:
|
||||
case t_item:
|
||||
return "ITEM";
|
||||
break;
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
|
||||
enum assetType
|
||||
{
|
||||
bitmap,
|
||||
music,
|
||||
sound,
|
||||
font,
|
||||
lang,
|
||||
data,
|
||||
room,
|
||||
enemy,
|
||||
item,
|
||||
maxAssetType
|
||||
t_bitmap,
|
||||
t_music,
|
||||
t_sound,
|
||||
t_font,
|
||||
t_lang,
|
||||
t_data,
|
||||
t_room,
|
||||
t_enemy,
|
||||
t_item,
|
||||
t_maxAssetType
|
||||
};
|
||||
|
||||
// Clase Asset
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
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::string executablePath;
|
||||
@@ -5,16 +5,11 @@
|
||||
#ifndef 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
|
||||
#define BLOCK 8
|
||||
#define HALF_BLOCK 4
|
||||
|
||||
// Tamaño de la pantalla virtual
|
||||
// Tamaño de la pantalla de juego
|
||||
#define GAMECANVAS_WIDTH 320
|
||||
#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_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
|
||||
const color_t borderColor = {0x27, 0x27, 0x36};
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "const.h"
|
||||
#include "utils.h"
|
||||
#include "screen.h"
|
||||
#include "asset.h"
|
||||
#include "const.h"
|
||||
#include "screen.h"
|
||||
#include "text.h"
|
||||
#include <vector>
|
||||
#include "utils.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef DEBUG_H
|
||||
#define DEBUG_H
|
||||
@@ -8,35 +8,35 @@ Input::Input(std::string file)
|
||||
dbPath = file;
|
||||
|
||||
// Inicializa las variables
|
||||
for (int i = 0; i < 17; ++i)
|
||||
{
|
||||
keyBindings[i].scancode = 0;
|
||||
keyBindings[i].active = false;
|
||||
keyBindings_t kb;
|
||||
kb.scancode = 0;
|
||||
kb.active = false;
|
||||
keyBindings.resize(17, kb);
|
||||
|
||||
gameControllerBindings[i].button = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
gameControllerBindings[i].active = false;
|
||||
}
|
||||
GameControllerBindings_t gcb;
|
||||
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
gcb.active = false;
|
||||
gameControllerBindings.resize(17, gcb);
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
discoverGameController();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Input::~Input()
|
||||
{
|
||||
for (int i = 0; i < numGamepads; ++i)
|
||||
connectedControllers[i] = nullptr;
|
||||
}
|
||||
|
||||
// Asigna uno de los posibles inputs a una tecla del teclado
|
||||
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
|
||||
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
||||
{
|
||||
gameControllerBindings[input].button = button;
|
||||
gameControllerBindings.at(input).button = button;
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
@@ -48,24 +48,28 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
if (device == INPUT_USE_ANY)
|
||||
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 (mKeystates[keyBindings[input].scancode] != 0)
|
||||
if (keyStates[keyBindings.at(input).scancode] != 0)
|
||||
{
|
||||
successKeyboard = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
successKeyboard = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!keyBindings[input].active)
|
||||
if (!keyBindings.at(input).active)
|
||||
{
|
||||
if (mKeystates[keyBindings[input].scancode] != 0)
|
||||
if (keyStates[keyBindings.at(input).scancode] != 0)
|
||||
{
|
||||
keyBindings[input].active = true;
|
||||
keyBindings.at(input).active = true;
|
||||
successKeyboard = true;
|
||||
}
|
||||
else
|
||||
@@ -75,9 +79,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mKeystates[keyBindings[input].scancode] == 0)
|
||||
if (keyStates[keyBindings.at(input).scancode] == 0)
|
||||
{
|
||||
keyBindings[input].active = false;
|
||||
keyBindings.at(input).active = false;
|
||||
successKeyboard = false;
|
||||
}
|
||||
else
|
||||
@@ -93,18 +97,22 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
{
|
||||
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 (!gameControllerBindings.at(input).active)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
|
||||
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(input).button) != 0)
|
||||
{
|
||||
gameControllerBindings[input].active = true;
|
||||
gameControllerBindings.at(input).active = true;
|
||||
successGameController = true;
|
||||
}
|
||||
else
|
||||
@@ -114,9 +122,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) == 0)
|
||||
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(input).button) == 0)
|
||||
{
|
||||
gameControllerBindings[input].active = false;
|
||||
gameControllerBindings.at(input).active = false;
|
||||
successGameController = false;
|
||||
}
|
||||
else
|
||||
@@ -133,38 +141,39 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
// Comprueba si hay almenos un input activo
|
||||
bool Input::checkAnyInput(int device, int index)
|
||||
{
|
||||
bool successKeyboard = false;
|
||||
bool successGameController = false;
|
||||
|
||||
if (device == INPUT_USE_ANY)
|
||||
index = 0;
|
||||
|
||||
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
|
||||
{
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
|
||||
index = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 17; ++i)
|
||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
||||
{
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
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 ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
||||
{
|
||||
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY)
|
||||
{
|
||||
for (int i = 0; i < 17; ++i)
|
||||
for (int i = 0; i < (int)gameControllerBindings.size(); ++i)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[i].button) != 0)
|
||||
if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings.at(i).button) != 0)
|
||||
{
|
||||
successGameController |= true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (successKeyboard || successGameController);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
@@ -173,34 +182,42 @@ bool Input::discoverGameController()
|
||||
bool found = false;
|
||||
|
||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||
{
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0)
|
||||
{
|
||||
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;
|
||||
|
||||
// Cuenta el numero de mandos
|
||||
for (int i = 0; i < nJoysticks; ++i)
|
||||
{
|
||||
if (SDL_IsGameController(i))
|
||||
{
|
||||
numGamepads++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("** Checking for game controllers ...\n");
|
||||
printf("%i joysticks found, %i are gamepads\n\n", nJoysticks, numGamepads);
|
||||
printf("\nChecking for game controllers...\n");
|
||||
printf("%i joysticks found, %i are gamepads\n", nJoysticks, numGamepads);
|
||||
|
||||
if (numGamepads > 0)
|
||||
{
|
||||
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
|
||||
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||
{
|
||||
connectedControllers.push_back(pad);
|
||||
std::string separator(" #");
|
||||
const std::string separator(" #");
|
||||
std::string name = SDL_GameControllerNameForIndex(i);
|
||||
name.resize(25);
|
||||
name = name + separator + std::to_string(i);
|
||||
@@ -208,10 +225,11 @@ bool Input::discoverGameController()
|
||||
controllerNames.push_back(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// mGameController = connectedControllers[0];
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
}
|
||||
|
||||
@@ -222,18 +240,26 @@ bool Input::discoverGameController()
|
||||
bool Input::gameControllerFound()
|
||||
{
|
||||
if (numGamepads > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Obten el nombre de un mando de juego
|
||||
std::string Input::getControllerName(int index)
|
||||
{
|
||||
if (numGamepads > 0)
|
||||
return controllerNames[index];
|
||||
{
|
||||
return controllerNames.at(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// Obten el numero de mandos conectados
|
||||
@@ -41,19 +41,19 @@ private:
|
||||
Uint8 scancode; // Scancode asociado
|
||||
bool active; // Indica si está activo
|
||||
};
|
||||
keyBindings_t keyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
|
||||
struct GameControllerBindings_t
|
||||
{
|
||||
SDL_GameControllerButton button; // GameControllerButton asociado
|
||||
bool active; // Indica si está activo
|
||||
};
|
||||
GameControllerBindings_t gameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
|
||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
||||
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
||||
int numGamepads; // Numero de mandos conectados
|
||||
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
||||
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<std::string> controllerNames; // Vector con los nombres de los mandos
|
||||
int numGamepads; // Numero de mandos conectados
|
||||
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
bool discoverGameController();
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
|
||||
@@ -1,186 +1,191 @@
|
||||
|
||||
#include "ltexture.h"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
// Constructor
|
||||
LTexture::LTexture(SDL_Renderer *renderer, std::string path)
|
||||
{
|
||||
// Copia punteros
|
||||
this->renderer = renderer;
|
||||
this->path = path;
|
||||
|
||||
// Inicializa
|
||||
texture = NULL;
|
||||
width = 0;
|
||||
height = 0;
|
||||
|
||||
// Carga el fichero en la textura
|
||||
if (path != "")
|
||||
{
|
||||
loadFromFile(path, renderer);
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
LTexture::~LTexture()
|
||||
{
|
||||
// Libera memoria
|
||||
unload();
|
||||
}
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
{
|
||||
int req_format = STBI_rgb_alpha;
|
||||
int width, height, orig_format;
|
||||
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
||||
if (data == NULL)
|
||||
{
|
||||
SDL_Log("Loading image failed: %s", stbi_failure_reason());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int depth, pitch;
|
||||
Uint32 pixel_format;
|
||||
if (req_format == STBI_rgb)
|
||||
{
|
||||
depth = 24;
|
||||
pitch = 3 * width; // 3 bytes por pixel * pixels per linea
|
||||
pixel_format = SDL_PIXELFORMAT_RGB24;
|
||||
}
|
||||
else
|
||||
{ // STBI_rgb_alpha (RGBA)
|
||||
depth = 32;
|
||||
pitch = 4 * width;
|
||||
pixel_format = SDL_PIXELFORMAT_RGBA32;
|
||||
}
|
||||
|
||||
// Limpia
|
||||
unload();
|
||||
|
||||
// La textura final
|
||||
SDL_Texture *newTexture = NULL;
|
||||
|
||||
// Carga la imagen desde una ruta específica
|
||||
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
||||
if (loadedSurface == NULL)
|
||||
{
|
||||
printf("Unable to load image %s!\n", path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Crea la textura desde los pixels de la surface
|
||||
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
||||
if (newTexture == NULL)
|
||||
{
|
||||
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Obtiene las dimensiones de la imagen
|
||||
this->width = loadedSurface->w;
|
||||
this->height = loadedSurface->h;
|
||||
}
|
||||
|
||||
// Elimina la textura cargada
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
}
|
||||
|
||||
// Return success
|
||||
texture = newTexture;
|
||||
return texture != NULL;
|
||||
}
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess access)
|
||||
{
|
||||
// Crea una textura sin inicializar
|
||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||
if (texture == NULL)
|
||||
{
|
||||
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
return texture != NULL;
|
||||
}
|
||||
|
||||
// Libera la memoria de la textura
|
||||
void LTexture::unload()
|
||||
{
|
||||
// Libera la textura si existe
|
||||
if (texture != NULL)
|
||||
{
|
||||
SDL_DestroyTexture(texture);
|
||||
texture = NULL;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el color para la modulacion
|
||||
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
SDL_SetTextureColorMod(texture, red, green, blue);
|
||||
}
|
||||
|
||||
// Establece el blending
|
||||
void LTexture::setBlendMode(SDL_BlendMode blending)
|
||||
{
|
||||
SDL_SetTextureBlendMode(texture, blending);
|
||||
}
|
||||
|
||||
// Establece el alpha para la modulación
|
||||
void LTexture::setAlpha(Uint8 alpha)
|
||||
{
|
||||
SDL_SetTextureAlphaMod(texture, alpha);
|
||||
}
|
||||
|
||||
// Renderiza la textura en un punto específico
|
||||
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||
{
|
||||
// Establece el destini de renderizado en la pantalla
|
||||
SDL_Rect renderQuad = {x, y, width, height};
|
||||
|
||||
// Obtiene las dimesiones del clip de renderizado
|
||||
if (clip != NULL)
|
||||
{
|
||||
renderQuad.w = clip->w;
|
||||
renderQuad.h = clip->h;
|
||||
}
|
||||
|
||||
renderQuad.w = renderQuad.w * zoomW;
|
||||
renderQuad.h = renderQuad.h * zoomH;
|
||||
|
||||
// Renderiza a pantalla
|
||||
SDL_RenderCopyEx(renderer, texture, clip, &renderQuad, angle, center, flip);
|
||||
}
|
||||
|
||||
// Establece la textura como objetivo de renderizado
|
||||
void LTexture::setAsRenderTarget(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_SetRenderTarget(renderer, texture);
|
||||
}
|
||||
|
||||
// Obtiene el ancho de la imagen
|
||||
int LTexture::getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
// Obtiene el alto de la imagen
|
||||
int LTexture::getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
// Recarga la textura
|
||||
bool LTexture::reLoad()
|
||||
{
|
||||
return loadFromFile(path, renderer);
|
||||
|
||||
#include "ltexture.h"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
// Constructor
|
||||
LTexture::LTexture(SDL_Renderer *renderer, std::string path)
|
||||
{
|
||||
// Copia punteros
|
||||
this->renderer = renderer;
|
||||
this->path = path;
|
||||
|
||||
// Inicializa
|
||||
texture = nullptr;
|
||||
width = 0;
|
||||
height = 0;
|
||||
|
||||
// Carga el fichero en la textura
|
||||
if (path != "")
|
||||
{
|
||||
loadFromFile(path, renderer);
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
LTexture::~LTexture()
|
||||
{
|
||||
// Libera memoria
|
||||
unload();
|
||||
}
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
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 width, height, orig_format;
|
||||
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
||||
if (data == nullptr)
|
||||
{
|
||||
SDL_Log("Loading image failed: %s", stbi_failure_reason());
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Image loaded: %s\n", filename.c_str());
|
||||
}
|
||||
|
||||
int depth, pitch;
|
||||
Uint32 pixel_format;
|
||||
if (req_format == STBI_rgb)
|
||||
{
|
||||
depth = 24;
|
||||
pitch = 3 * width; // 3 bytes por pixel * pixels per linea
|
||||
pixel_format = SDL_PIXELFORMAT_RGB24;
|
||||
}
|
||||
else
|
||||
{ // STBI_rgb_alpha (RGBA)
|
||||
depth = 32;
|
||||
pitch = 4 * width;
|
||||
pixel_format = SDL_PIXELFORMAT_RGBA32;
|
||||
}
|
||||
|
||||
// Limpia
|
||||
unload();
|
||||
|
||||
// La textura final
|
||||
SDL_Texture *newTexture = nullptr;
|
||||
|
||||
// Carga la imagen desde una ruta específica
|
||||
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
||||
if (loadedSurface == nullptr)
|
||||
{
|
||||
printf("Unable to load image %s!\n", path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Crea la textura desde los pixels de la surface
|
||||
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
||||
if (newTexture == nullptr)
|
||||
{
|
||||
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Obtiene las dimensiones de la imagen
|
||||
this->width = loadedSurface->w;
|
||||
this->height = loadedSurface->h;
|
||||
}
|
||||
|
||||
// Elimina la textura cargada
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
}
|
||||
|
||||
// Return success
|
||||
texture = newTexture;
|
||||
return texture != nullptr;
|
||||
}
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess access)
|
||||
{
|
||||
// Crea una textura sin inicializar
|
||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||
if (texture == nullptr)
|
||||
{
|
||||
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
return texture != nullptr;
|
||||
}
|
||||
|
||||
// Libera la memoria de la textura
|
||||
void LTexture::unload()
|
||||
{
|
||||
// Libera la textura si existe
|
||||
if (texture != nullptr)
|
||||
{
|
||||
SDL_DestroyTexture(texture);
|
||||
texture = nullptr;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el color para la modulacion
|
||||
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
SDL_SetTextureColorMod(texture, red, green, blue);
|
||||
}
|
||||
|
||||
// Establece el blending
|
||||
void LTexture::setBlendMode(SDL_BlendMode blending)
|
||||
{
|
||||
SDL_SetTextureBlendMode(texture, blending);
|
||||
}
|
||||
|
||||
// Establece el alpha para la modulación
|
||||
void LTexture::setAlpha(Uint8 alpha)
|
||||
{
|
||||
SDL_SetTextureAlphaMod(texture, alpha);
|
||||
}
|
||||
|
||||
// Renderiza la textura en un punto específico
|
||||
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||
{
|
||||
// Establece el destino de renderizado en la pantalla
|
||||
SDL_Rect renderQuad = {x, y, width, height};
|
||||
|
||||
// Obtiene las dimesiones del clip de renderizado
|
||||
if (clip != nullptr)
|
||||
{
|
||||
renderQuad.w = clip->w;
|
||||
renderQuad.h = clip->h;
|
||||
}
|
||||
|
||||
renderQuad.w = renderQuad.w * zoomW;
|
||||
renderQuad.h = renderQuad.h * zoomH;
|
||||
|
||||
// Renderiza a pantalla
|
||||
SDL_RenderCopyEx(renderer, texture, clip, &renderQuad, angle, center, flip);
|
||||
}
|
||||
|
||||
// Establece la textura como objetivo de renderizado
|
||||
void LTexture::setAsRenderTarget(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_SetRenderTarget(renderer, texture);
|
||||
}
|
||||
|
||||
// Obtiene el ancho de la imagen
|
||||
int LTexture::getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
// Obtiene el alto de la imagen
|
||||
int LTexture::getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
// Recarga la textura
|
||||
bool LTexture::reLoad()
|
||||
{
|
||||
return loadFromFile(path, renderer);
|
||||
}
|
||||
@@ -1,61 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#ifndef LTEXTURE_H
|
||||
#define LTEXTURE_H
|
||||
|
||||
// Clase LTexture
|
||||
class LTexture
|
||||
{
|
||||
private:
|
||||
SDL_Texture *texture; // La textura
|
||||
SDL_Renderer *renderer; // Renderizador donde dibujar la textura
|
||||
int width; // Ancho de la imagen
|
||||
int height; // Alto de la imagen
|
||||
std::string path; // Ruta de la imagen de la textura
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
LTexture(SDL_Renderer *renderer, std::string path = "");
|
||||
|
||||
// Destructor
|
||||
~LTexture();
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool loadFromFile(std::string path, SDL_Renderer *renderer);
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||
|
||||
// Libera la memoria de la textura
|
||||
void unload();
|
||||
|
||||
// Establece el color para la modulacion
|
||||
void setColor(Uint8 red, Uint8 green, Uint8 blue);
|
||||
|
||||
// Establece el blending
|
||||
void setBlendMode(SDL_BlendMode blending);
|
||||
|
||||
// Establece el alpha para la modulación
|
||||
void setAlpha(Uint8 alpha);
|
||||
|
||||
// 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);
|
||||
|
||||
// Establece la textura como objetivo de renderizado
|
||||
void setAsRenderTarget(SDL_Renderer *renderer);
|
||||
|
||||
// Obtiene el ancho de la imagen
|
||||
int getWidth();
|
||||
|
||||
// Obtiene el alto de la imagen
|
||||
int getHeight();
|
||||
|
||||
// Recarga la textura
|
||||
bool reLoad();
|
||||
};
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#ifndef LTEXTURE_H
|
||||
#define LTEXTURE_H
|
||||
|
||||
// Clase LTexture
|
||||
class LTexture
|
||||
{
|
||||
private:
|
||||
SDL_Texture *texture; // La textura
|
||||
SDL_Renderer *renderer; // Renderizador donde dibujar la textura
|
||||
int width; // Ancho de la imagen
|
||||
int height; // Alto de la imagen
|
||||
std::string path; // Ruta de la imagen de la textura
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
LTexture(SDL_Renderer *renderer, std::string path = "");
|
||||
|
||||
// Destructor
|
||||
~LTexture();
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool loadFromFile(std::string path, SDL_Renderer *renderer);
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||
|
||||
// Libera la memoria de la textura
|
||||
void unload();
|
||||
|
||||
// Establece el color para la modulacion
|
||||
void setColor(Uint8 red, Uint8 green, Uint8 blue);
|
||||
|
||||
// Establece el blending
|
||||
void setBlendMode(SDL_BlendMode blending);
|
||||
|
||||
// Establece el alpha para la modulación
|
||||
void setAlpha(Uint8 alpha);
|
||||
|
||||
// Renderiza la textura en un punto específico
|
||||
void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = nullptr, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = nullptr, SDL_RendererFlip flip = SDL_FLIP_NONE);
|
||||
|
||||
// Establece la textura como objetivo de renderizado
|
||||
void setAsRenderTarget(SDL_Renderer *renderer);
|
||||
|
||||
// Obtiene el ancho de la imagen
|
||||
int getWidth();
|
||||
|
||||
// Obtiene el alto de la imagen
|
||||
int getHeight();
|
||||
|
||||
// Recarga la textura
|
||||
bool reLoad();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -4,20 +4,63 @@
|
||||
// Constructor
|
||||
Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file)
|
||||
{
|
||||
// Copia punteros
|
||||
this->renderer = renderer;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
|
||||
// Inicializa punteros
|
||||
soundMove = nullptr;
|
||||
soundAccept = 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 != "")
|
||||
{
|
||||
load(file);
|
||||
}
|
||||
reorganize();
|
||||
|
||||
// Deja el cursor en el primer elemento
|
||||
reset();
|
||||
}
|
||||
|
||||
Menu::~Menu()
|
||||
@@ -56,7 +99,7 @@ bool Menu::load(std::string file_path)
|
||||
// Indica si se ha creado ya el objeto de texto
|
||||
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::ifstream file(file_path);
|
||||
|
||||
@@ -78,7 +121,7 @@ bool Menu::load(std::string file_path)
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
// Lee la siguiente linea
|
||||
std::getline(file, line);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
@@ -118,7 +161,7 @@ bool Menu::load(std::string file_path)
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
printf("Closing file %s\n\n", filename.c_str());
|
||||
printf("Closing file %s\n", filename.c_str());
|
||||
file.close();
|
||||
}
|
||||
// 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
|
||||
{
|
||||
success = false;
|
||||
@@ -309,48 +353,6 @@ bool Menu::setVars(std::string var, std::string value)
|
||||
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
|
||||
void Menu::loadAudioFile(std::string file, int sound)
|
||||
{
|
||||
@@ -403,7 +405,8 @@ void Menu::updateSelector()
|
||||
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
|
||||
{
|
||||
@@ -431,7 +434,8 @@ void Menu::updateSelector()
|
||||
selector.resizing = false;
|
||||
}
|
||||
}
|
||||
if (selector.incH < 0) // Decrece
|
||||
|
||||
else if (selector.incH < 0) // Decrece
|
||||
{
|
||||
if (selector.h < selector.targetH) // Ha llegado al destino
|
||||
{
|
||||
@@ -454,7 +458,7 @@ void Menu::setSelectorPos(int index)
|
||||
if (index < (int)item.size())
|
||||
{
|
||||
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.x = rectBG.rect.x;
|
||||
selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index);
|
||||
@@ -482,10 +486,17 @@ void Menu::reset()
|
||||
{
|
||||
itemSelected = MENU_NO_OPTION;
|
||||
selector.index = 0;
|
||||
selector.originY = selector.targetY = selector.y = item[0].rect.y;
|
||||
selector.originH = selector.targetH = item[0].rect.h;
|
||||
selector.originY = selector.targetY = selector.y = item.at(0).rect.y;
|
||||
selector.originH = selector.targetH = item.at(0).rect.h;
|
||||
selector.moving = 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
|
||||
@@ -513,18 +524,18 @@ void Menu::reorganize()
|
||||
bool Menu::increaseSelectorIndex()
|
||||
{
|
||||
// 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);
|
||||
|
||||
// Calcula cual es el siguiente elemento
|
||||
++selector.index %= item.size();
|
||||
while (!item[selector.index].selectable)
|
||||
while (!item.at(selector.index).selectable)
|
||||
{
|
||||
++selector.index %= item.size();
|
||||
}
|
||||
|
||||
// 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.targetH = getSelectorHeight(selector.index);
|
||||
@@ -543,24 +554,24 @@ bool Menu::increaseSelectorIndex()
|
||||
bool Menu::decreaseSelectorIndex()
|
||||
{
|
||||
// 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);
|
||||
|
||||
// Calcula cual es el siguiente elemento
|
||||
if (selector.index == 0)
|
||||
{
|
||||
selector.index = item.size();
|
||||
selector.index = item.size() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
selector.index--;
|
||||
}
|
||||
|
||||
while (!item[selector.index].selectable)
|
||||
while (!item.at(selector.index).selectable)
|
||||
{
|
||||
if (selector.index == 0)
|
||||
{
|
||||
selector.index = item.size();
|
||||
selector.index = item.size() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -569,7 +580,7 @@ bool Menu::decreaseSelectorIndex()
|
||||
}
|
||||
|
||||
// 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.targetH = getSelectorHeight(selector.index);
|
||||
@@ -603,8 +614,6 @@ void Menu::render()
|
||||
|
||||
// Renderiza el rectangulo del selector
|
||||
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_RenderFillRect(renderer, &temp);
|
||||
|
||||
@@ -621,40 +630,74 @@ void Menu::render()
|
||||
if (i == selector.index)
|
||||
{
|
||||
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
|
||||
// No seleccionable
|
||||
{
|
||||
if ((item[i].linkedUp) && (i == selector.index + 1))
|
||||
{ // No seleccionable
|
||||
if ((item.at(i).linkedUp) && (i == selector.index + 1))
|
||||
{
|
||||
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
|
||||
{
|
||||
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
|
||||
void Menu::setRectSize()
|
||||
void Menu::setRectSize(int w, int h)
|
||||
{
|
||||
rectBG.rect.w = findWidth() + text->getCharacterSize();
|
||||
rectBG.rect.h = findHeight() + text->getCharacterSize();
|
||||
// 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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
else
|
||||
{ // Si se pasa un valor, se aplica
|
||||
rectBG.rect.h = h;
|
||||
}
|
||||
|
||||
// La posición X es la del menú menos medio caracter
|
||||
rectBG.rect.x = x - (text->getCharacterSize() / 2);
|
||||
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);
|
||||
}
|
||||
|
||||
// La posición Y es la del menu menos la altura de medio caracter
|
||||
rectBG.rect.y = y - (text->getCharacterSize() / 2);
|
||||
@@ -687,10 +730,28 @@ void Menu::setSelectorTextColor(color_t color)
|
||||
void Menu::centerMenuOnX(int value)
|
||||
{
|
||||
isCenteredOnX = true;
|
||||
centerX = value;
|
||||
if (value != 0)
|
||||
{
|
||||
centerX = value;
|
||||
}
|
||||
else if (centerX == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Establece la nueva posición centrada en funcion del elemento más ancho
|
||||
x = (value) - (findWidth() / 2);
|
||||
// Establece la nueva posición centrada en funcion del elemento más ancho o del ancho fijo del menu
|
||||
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
|
||||
for (auto &i : item)
|
||||
@@ -700,6 +761,12 @@ void Menu::centerMenuOnX(int value)
|
||||
|
||||
// Recalcula el rectangulo de fondo
|
||||
setRectSize();
|
||||
|
||||
// Vuelve a centrar los elementos si fuera el caso
|
||||
if (areElementsCenteredOnX)
|
||||
{
|
||||
centerMenuElementsOnX();
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -751,13 +817,14 @@ void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool gre
|
||||
temp.linkedDown = linkedDown;
|
||||
|
||||
item.push_back(temp);
|
||||
|
||||
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
|
||||
void Menu::setItemCaption(int index, std::string text)
|
||||
{
|
||||
item[index].label = text;
|
||||
item[index].rect.w = this->text->lenght(item[index].label);
|
||||
item[index].rect.h = this->text->getCharacterSize();
|
||||
item.at(index).label = text;
|
||||
item.at(index).rect.w = this->text->lenght(item.at(index).label);
|
||||
item.at(index).rect.h = this->text->getCharacterSize();
|
||||
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
|
||||
@@ -850,41 +914,69 @@ int Menu::findHeight()
|
||||
// Recoloca los elementos del menu en el eje Y
|
||||
void Menu::replaceElementsOnY()
|
||||
{
|
||||
item[0].rect.y = y;
|
||||
item.at(0).rect.y = y;
|
||||
|
||||
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
|
||||
void Menu::setSelectable(int index, bool value)
|
||||
{
|
||||
item[index].selectable = value;
|
||||
item.at(index).selectable = value;
|
||||
}
|
||||
|
||||
// Establece el estado agrisado de un item
|
||||
void Menu::setGreyed(int index, bool value)
|
||||
{
|
||||
item[index].greyed = value;
|
||||
item.at(index).greyed = value;
|
||||
}
|
||||
|
||||
// Establece el estado de enlace de un item
|
||||
void Menu::setLinkedDown(int index, bool value)
|
||||
{
|
||||
item[index].linkedDown = value;
|
||||
item.at(index).linkedDown = value;
|
||||
}
|
||||
|
||||
// Calcula la altura del selector
|
||||
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
|
||||
{
|
||||
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
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <vector>
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "asset.h"
|
||||
#include "input.h"
|
||||
#include "utils.h"
|
||||
#include "jail_audio.h"
|
||||
#include <sstream>
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "utils.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#ifndef MENU_H
|
||||
#define MENU_H
|
||||
@@ -68,6 +68,13 @@ private:
|
||||
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
|
||||
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
|
||||
@@ -85,10 +92,6 @@ private:
|
||||
JA_Sound soundAccept; // Sonido al aceptar o elegir una opción del menu
|
||||
JA_Sound soundCancel; // Sonido al cancelar el menu
|
||||
JA_Sound soundMove; // Sonido al mover el selector
|
||||
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
||||
Text *text; // Texto para poder escribir los items del menu
|
||||
Input *input; // Gestor de eventos de entrada de teclado o gamepad
|
||||
Asset *asset; // Objeto para gestionar los ficheros de recursos
|
||||
color_t colorGreyed; // Color para los elementos agrisados
|
||||
rectangle_t rectBG; // Rectangulo de fondo del menu
|
||||
std::vector<item_t> item; // Estructura para cada elemento del menu
|
||||
@@ -105,12 +108,6 @@ private:
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setItem(item_t *item, std::string var, std::string value);
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
|
||||
// Establece el rectangulo de fondo del menu
|
||||
void setRectSize();
|
||||
|
||||
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
||||
void reorganize();
|
||||
|
||||
@@ -143,7 +140,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file="");
|
||||
Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file = "");
|
||||
|
||||
// Destructor
|
||||
~Menu();
|
||||
@@ -179,7 +176,7 @@ public:
|
||||
void setSelectorTextColor(color_t color);
|
||||
|
||||
// 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
|
||||
void centerMenuOnY(int value);
|
||||
@@ -208,7 +205,20 @@ public:
|
||||
// Establece el estado de enlace de un item
|
||||
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
|
||||
@@ -45,7 +45,7 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
|
||||
spriteClip = {0, 0, w, h};
|
||||
|
||||
// Establece el centro de rotación
|
||||
center = {0, 0};
|
||||
center = nullptr;
|
||||
|
||||
// Establece el tipo de volteado
|
||||
currentFlip = SDL_FLIP_NONE;
|
||||
@@ -73,7 +73,7 @@ void MovingSprite::clear()
|
||||
|
||||
angle = 0.0; // Angulo para dibujarlo
|
||||
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
|
||||
rotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
||||
counter = 0; // Contador interno
|
||||
@@ -101,7 +101,9 @@ void MovingSprite::move()
|
||||
void MovingSprite::render()
|
||||
{
|
||||
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
|
||||
@@ -158,11 +160,13 @@ double MovingSprite::getAngle()
|
||||
return angle;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void MovingSprite::setPos(SDL_Rect rect)
|
||||
// Establece la posición y el tamaño del objeto
|
||||
void MovingSprite::setRect(SDL_Rect rect)
|
||||
{
|
||||
x = (float)rect.x;
|
||||
y = (float)rect.y;
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
@@ -265,7 +269,14 @@ void MovingSprite::setRotate(bool value)
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateSpeed(int value)
|
||||
{
|
||||
rotateSpeed = value;
|
||||
if (value < 1)
|
||||
{
|
||||
rotateSpeed = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
rotateSpeed = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
@@ -324,15 +335,6 @@ SDL_Rect MovingSprite::getRect()
|
||||
return rect;
|
||||
}
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void MovingSprite::setRect(SDL_Rect rect)
|
||||
{
|
||||
x = (float)rect.x;
|
||||
y = (float)rect.y;
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
}
|
||||
|
||||
// Deshace el último movimiento
|
||||
void MovingSprite::undoMove()
|
||||
{
|
||||
@@ -1,173 +1,170 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "sprite.h"
|
||||
|
||||
#ifndef MOVINGSPRITE_H
|
||||
#define MOVINGSPRITE_H
|
||||
|
||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||
class MovingSprite : public Sprite
|
||||
{
|
||||
protected:
|
||||
float x; // Posición en el eje X
|
||||
float y; // Posición en el eje Y
|
||||
|
||||
float xPrev; // Posición anterior en el eje X
|
||||
float yPrev; // Posición anterior en el eje Y
|
||||
|
||||
float vx; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
float vy; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
|
||||
float ax; // Aceleración en el eje X. Variación de la velocidad
|
||||
float ay; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
float zoomW; // Zoom aplicado a la anchura
|
||||
float zoomH; // Zoom aplicado a la altura
|
||||
|
||||
double angle; // Angulo para dibujarlo
|
||||
bool rotateEnabled; // Indica si ha de rotar
|
||||
int rotateSpeed; // Velocidad de giro
|
||||
double rotateAmount; // Cantidad de grados a girar en cada iteración
|
||||
int counter; // Contador interno
|
||||
SDL_Point center; // Centro de rotación
|
||||
SDL_RendererFlip currentFlip; // Indica como se voltea el sprite
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
|
||||
// Destructor
|
||||
~MovingSprite();
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
|
||||
// Rota el sprite
|
||||
void rotate();
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
void update();
|
||||
|
||||
// Reinicia todas las variables
|
||||
void clear();
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getPosX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getPosY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getVelX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getVelY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getAccelX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getAccelY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getZoomW();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getZoomH();
|
||||
|
||||
// Obten el valor de la variable
|
||||
double getAngle();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool getRotate();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 getRotateSpeed();
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomW(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomH(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAngle(double vaue);
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void incAngle(double value);
|
||||
|
||||
// Decrementa el valor de la variable
|
||||
void decAngle(double value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotate(bool value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateSpeed(int value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateAmount(double value);
|
||||
|
||||
// Quita el efecto de rotación y deja el sprite en su angulo inicial.
|
||||
void disableRotate();
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void switchRotate();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setFlip(SDL_RendererFlip flip);
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void flip();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip getFlip();
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
|
||||
// Deshace el último movimiento
|
||||
void undoMove();
|
||||
|
||||
// Deshace el último movimiento en el eje X
|
||||
void undoMoveX();
|
||||
|
||||
// Deshace el último movimiento en el eje Y
|
||||
void undoMoveY();
|
||||
|
||||
// Pone a cero las velocidades de desplacamiento
|
||||
void clearVel();
|
||||
|
||||
// Devuelve el incremento en el eje X en pixels
|
||||
int getIncX();
|
||||
};
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "sprite.h"
|
||||
|
||||
#ifndef MOVINGSPRITE_H
|
||||
#define MOVINGSPRITE_H
|
||||
|
||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||
class MovingSprite : public Sprite
|
||||
{
|
||||
protected:
|
||||
float x; // Posición en el eje X
|
||||
float y; // Posición en el eje Y
|
||||
|
||||
float xPrev; // Posición anterior en el eje X
|
||||
float yPrev; // Posición anterior en el eje Y
|
||||
|
||||
float vx; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||
float vy; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||
|
||||
float ax; // Aceleración en el eje X. Variación de la velocidad
|
||||
float ay; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
float zoomW; // Zoom aplicado a la anchura
|
||||
float zoomH; // Zoom aplicado a la altura
|
||||
|
||||
double angle; // Angulo para dibujarlo
|
||||
bool rotateEnabled; // Indica si ha de rotar
|
||||
int rotateSpeed; // Velocidad de giro
|
||||
double rotateAmount; // Cantidad de grados a girar en cada iteración
|
||||
int counter; // Contador interno
|
||||
SDL_Point *center; // Centro de rotación
|
||||
SDL_RendererFlip currentFlip; // Indica como se voltea el sprite
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
|
||||
// Destructor
|
||||
~MovingSprite();
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
|
||||
// Rota el sprite
|
||||
void rotate();
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
void update();
|
||||
|
||||
// Reinicia todas las variables
|
||||
void clear();
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getPosX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getPosY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getVelX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getVelY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getAccelX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getAccelY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getZoomW();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getZoomH();
|
||||
|
||||
// Obten el valor de la variable
|
||||
double getAngle();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool getRotate();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 getRotateSpeed();
|
||||
|
||||
// Establece la posición y el tamaño del objeto
|
||||
void setRect(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomW(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomH(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAngle(double vaue);
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void incAngle(double value);
|
||||
|
||||
// Decrementa el valor de la variable
|
||||
void decAngle(double value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotate(bool value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateSpeed(int value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateAmount(double value);
|
||||
|
||||
// Quita el efecto de rotación y deja el sprite en su angulo inicial.
|
||||
void disableRotate();
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void switchRotate();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setFlip(SDL_RendererFlip flip);
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void flip();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip getFlip();
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
|
||||
// Deshace el último movimiento
|
||||
void undoMove();
|
||||
|
||||
// Deshace el último movimiento en el eje X
|
||||
void undoMoveX();
|
||||
|
||||
// Deshace el último movimiento en el eje Y
|
||||
void undoMoveY();
|
||||
|
||||
// Pone a cero las velocidades de desplacamiento
|
||||
void clearVel();
|
||||
|
||||
// Devuelve el incremento en el eje X en pixels
|
||||
int getIncX();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
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());
|
||||
}
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options->fullScreenMode);
|
||||
@@ -59,14 +61,14 @@ void Screen::start()
|
||||
void Screen::blit()
|
||||
{
|
||||
// Vuelve a dejar el renderizador en modo normal
|
||||
SDL_SetRenderTarget(renderer, NULL);
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
|
||||
// Borra el contenido previo
|
||||
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// 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
|
||||
SDL_RenderPresent(renderer);
|
||||
@@ -344,7 +346,7 @@ void Screen::renderSpectrumFade()
|
||||
const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght;
|
||||
const int max = spectrumColor.size() - 1;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ Sprite::Sprite(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *rend
|
||||
this->texture = texture;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip = {x, y, w, h};
|
||||
spriteClip = {0, 0, w, h};
|
||||
|
||||
// Inicializa variables
|
||||
enabled = true;
|
||||
@@ -41,7 +41,7 @@ Sprite::Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer)
|
||||
this->texture = texture;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip = {x, y, w, h};
|
||||
spriteClip = {0, 0, w, h};
|
||||
|
||||
// Inicializa variables
|
||||
enabled = true;
|
||||
@@ -148,6 +148,12 @@ void Sprite::setTexture(LTexture *texture)
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Renderer *Sprite::getRenderer()
|
||||
{
|
||||
return renderer;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
@@ -1,93 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "ltexture.h"
|
||||
|
||||
#ifndef SPRITE_H
|
||||
#define SPRITE_H
|
||||
|
||||
// Clase sprite
|
||||
class Sprite
|
||||
{
|
||||
protected:
|
||||
int x; // Posición en el eje X donde dibujar el sprite
|
||||
int y; // Posición en el eje Y donde dibujar el sprite
|
||||
int w; // Ancho del sprite
|
||||
int h; // Alto del sprite
|
||||
|
||||
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
||||
LTexture *texture; // Textura donde estan todos los dibujos del sprite
|
||||
SDL_Rect spriteClip; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
|
||||
bool enabled; // Indica si el sprite esta habilitado
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Sprite();
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getWidth();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getHeight();
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(int x);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(int y);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setWidth(int w);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setHeight(int h);
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect getSpriteClip();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpriteClip(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpriteClip(int x, int y, int w, int h);
|
||||
|
||||
// Obten el valor de la variable
|
||||
LTexture *getTexture();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setTexture(LTexture *texture);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRenderer(SDL_Renderer *renderer);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setEnabled(bool value);
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool isEnabled();
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
};
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "ltexture.h"
|
||||
|
||||
#ifndef SPRITE_H
|
||||
#define SPRITE_H
|
||||
|
||||
// Clase sprite
|
||||
class Sprite
|
||||
{
|
||||
protected:
|
||||
int x; // Posición en el eje X donde dibujar el sprite
|
||||
int y; // Posición en el eje Y donde dibujar el sprite
|
||||
int w; // Ancho del sprite
|
||||
int h; // Alto del sprite
|
||||
|
||||
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
||||
LTexture *texture; // Textura donde estan todos los dibujos del sprite
|
||||
SDL_Rect spriteClip; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
|
||||
bool enabled; // Indica si el sprite esta habilitado
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
Sprite(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Sprite();
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getWidth();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getHeight();
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(int x);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(int y);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setWidth(int w);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setHeight(int h);
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect getSpriteClip();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpriteClip(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpriteClip(int x, int y, int w, int h);
|
||||
|
||||
// Obten el valor de la variable
|
||||
LTexture *getTexture();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setTexture(LTexture *texture);
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Renderer *getRenderer();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRenderer(SDL_Renderer *renderer);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setEnabled(bool value);
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool isEnabled();
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -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/
|
||||
//
|
||||
// Original version written by Sean Barrett in 2007.
|
||||
@@ -29,15 +29,12 @@
|
||||
// Bernhard Wodo Evan Balster github:alxprd
|
||||
// Tom Beaumont Ingo Leitgeb Nicolas Guillemot
|
||||
// Phillip Bennefall Rohit Thiago Goulart
|
||||
// github:manxorist Saga Musix github:infatum
|
||||
// github:manxorist saga musix github:infatum
|
||||
// Timur Gagiev Maxwell Koo Peter Waller
|
||||
// github:audinowho Dougall Johnson David Reid
|
||||
// github:Clownacy Pedro J. Estebanez Remi Verschelde
|
||||
// AnthoFoxo github:morlat Gabriel Ravier
|
||||
//
|
||||
// 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.19 - 2020-02-05 - warnings
|
||||
// 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
|
||||
// the first channel, and (*output)[1][0] contains the first sample from
|
||||
// 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);
|
||||
// inform stb_vorbis that your next datablock will not be contiguous with
|
||||
@@ -588,7 +579,7 @@ enum STBVorbisError
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#if defined(__linux__) || defined(__linux) || defined(__sun__) || defined(__EMSCRIPTEN__) || defined(__NEWLIB__)
|
||||
#if defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__) || defined(__NEWLIB__)
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
#else // STB_VORBIS_NO_CRT
|
||||
@@ -655,12 +646,6 @@ typedef signed int int32;
|
||||
|
||||
typedef float codetype;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STBV_NOTUSED(v) (void)(v)
|
||||
#else
|
||||
#define STBV_NOTUSED(v) (void)sizeof(v)
|
||||
#endif
|
||||
|
||||
// @NOTE
|
||||
//
|
||||
// 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 exp = (x & 0x7fe00000) >> 21;
|
||||
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
|
||||
for (k=0; k < n; ++k) if (len[k] < NO_CODE) break;
|
||||
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_entry(c, 0, k, m++, len[k], values);
|
||||
// add all available leaves
|
||||
@@ -1106,7 +1090,6 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values)
|
||||
uint32 res;
|
||||
int z = len[i], y;
|
||||
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,
|
||||
// which is what the specification calls for)
|
||||
// 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;
|
||||
if (z == 0) { return FALSE; }
|
||||
res = available[z];
|
||||
assert(z >= 0 && z < 32);
|
||||
available[z] = 0;
|
||||
add_entry(c, bit_reverse(res), i, m++, len[i], values);
|
||||
// propagate availability up the tree
|
||||
if (z != len[i]) {
|
||||
assert(len[i] >= 0 && len[i] < 32);
|
||||
for (y=len[i]; y > z; --y) {
|
||||
assert(available[y] == 0);
|
||||
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) {
|
||||
float k00,k11;
|
||||
float l00,l11;
|
||||
|
||||
k00 = z[-0] - z[ -8];
|
||||
k11 = z[-1] - z[ -9];
|
||||
l00 = z[-2] - z[-10];
|
||||
l11 = z[-3] - z[-11];
|
||||
z[ -0] = z[-0] + z[ -8];
|
||||
z[ -1] = z[-1] + z[ -9];
|
||||
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[-0] - z[-8];
|
||||
k11 = z[-1] - z[-9];
|
||||
z[-0] = z[-0] + z[-8];
|
||||
z[-1] = z[-1] + z[-9];
|
||||
z[-8] = k00;
|
||||
z[-9] = k11 ;
|
||||
|
||||
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];
|
||||
l00 = z[ -6] - z[-14];
|
||||
l11 = z[ -7] - z[-15];
|
||||
z[ -4] = z[ -4] + z[-12];
|
||||
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[ -7] = z[ -7] + z[-15];
|
||||
z[-12] = k11;
|
||||
z[-13] = -k00;
|
||||
z[-14] = (l11-l00) * A2;
|
||||
z[-15] = (l00+l11) * -A2;
|
||||
z[-14] = (k00+k11) * A2;
|
||||
z[-15] = (k00-k11) * A2;
|
||||
|
||||
iter_54(z);
|
||||
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) {
|
||||
j = g->sorted_order[q];
|
||||
#ifndef STB_VORBIS_NO_DEFER_FLOOR
|
||||
STBV_NOTUSED(step2_flag);
|
||||
if (finalY[j] >= 0)
|
||||
#else
|
||||
if (step2_flag[j])
|
||||
@@ -3186,7 +3171,6 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
||||
|
||||
// WINDOWING
|
||||
|
||||
STBV_NOTUSED(left_end);
|
||||
n = f->blocksize[m->blockflag];
|
||||
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
|
||||
// and decode the size of all current frames--could be done,
|
||||
// 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,
|
||||
// if we're lapping a large block then a small at the start?
|
||||
f->discard_samples_deferred = n - right_end;
|
||||
@@ -3658,11 +3642,9 @@ static int start_decoder(vorb *f)
|
||||
f->vendor[len] = (char)'\0';
|
||||
//user comments
|
||||
f->comment_list_length = get32_packet(f);
|
||||
f->comment_list = NULL;
|
||||
if (f->comment_list_length > 0)
|
||||
{
|
||||
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_length > 0) {
|
||||
f->comment_list = (char**)setup_malloc(f, sizeof(char*) * (f->comment_list_length));
|
||||
if (f->comment_list == NULL) return error(f, VORBIS_outofmem);
|
||||
}
|
||||
|
||||
for(i=0; i < f->comment_list_length; ++i) {
|
||||
@@ -3885,7 +3867,8 @@ static int start_decoder(vorb *f)
|
||||
unsigned int div=1;
|
||||
for (k=0; k < c->dimensions; ++k) {
|
||||
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;
|
||||
if (c->sequence_p)
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -4526,7 +4509,6 @@ stb_vorbis *stb_vorbis_open_pushdata(
|
||||
*error = VORBIS_need_more_data;
|
||||
else
|
||||
*error = p.error;
|
||||
vorbis_deinit(&p);
|
||||
return NULL;
|
||||
}
|
||||
f = vorbis_alloc(&p);
|
||||
@@ -4584,7 +4566,7 @@ static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last)
|
||||
header[i] = get8(f);
|
||||
if (f->eof) return 0;
|
||||
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)
|
||||
header[i] = 0;
|
||||
crc = 0;
|
||||
@@ -4988,7 +4970,7 @@ unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f)
|
||||
// set. whoops!
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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 *f, p;
|
||||
if (!data) {
|
||||
if (error) *error = VORBIS_unexpected_eof;
|
||||
return NULL;
|
||||
}
|
||||
if (data == NULL) return NULL;
|
||||
vorbis_init(&p, alloc);
|
||||
p.stream = (uint8 *) data;
|
||||
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)
|
||||
{
|
||||
#define STB_BUFFER_SIZE 32
|
||||
float buffer[STB_BUFFER_SIZE];
|
||||
int i,j,o,n = STB_BUFFER_SIZE;
|
||||
#define BUFFER_SIZE 32
|
||||
float buffer[BUFFER_SIZE];
|
||||
int i,j,o,n = BUFFER_SIZE;
|
||||
check_endianness();
|
||||
for (o = 0; o < len; o += STB_BUFFER_SIZE) {
|
||||
for (o = 0; o < len; o += BUFFER_SIZE) {
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
if (o + n > len) n = len - o;
|
||||
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;
|
||||
}
|
||||
}
|
||||
#undef STB_BUFFER_SIZE
|
||||
}
|
||||
|
||||
static void compute_stereo_samples(short *output, int num_c, float **data, int d_offset, int len)
|
||||
{
|
||||
#define STB_BUFFER_SIZE 32
|
||||
float buffer[STB_BUFFER_SIZE];
|
||||
int i,j,o,n = STB_BUFFER_SIZE >> 1;
|
||||
#define BUFFER_SIZE 32
|
||||
float buffer[BUFFER_SIZE];
|
||||
int i,j,o,n = BUFFER_SIZE >> 1;
|
||||
// o is the offset in the source data
|
||||
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
|
||||
int o2 = o << 1;
|
||||
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;
|
||||
}
|
||||
}
|
||||
#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)
|
||||
@@ -5311,6 +5288,8 @@ int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short
|
||||
float **outputs;
|
||||
int len = num_shorts / channels;
|
||||
int n=0;
|
||||
int z = f->channels;
|
||||
if (z > channels) z = channels;
|
||||
while (n < len) {
|
||||
int k = f->channel_buffer_end - f->channel_buffer_start;
|
||||
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;
|
||||
int n=0;
|
||||
int z = f->channels;
|
||||
if (z > channels) z = channels;
|
||||
while (n < len) {
|
||||
int k = f->channel_buffer_end - f->channel_buffer_start;
|
||||
if (n+k >= len) k = len - n;
|
||||
@@ -6,13 +6,12 @@
|
||||
// Constructor
|
||||
Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
|
||||
{
|
||||
texture = new LTexture(renderer, bitmapFile);
|
||||
sprite = new Sprite({0, 0, 0, 0}, texture, renderer);
|
||||
sprite->setTexture(texture);
|
||||
sprite->setRenderer(renderer);
|
||||
file = textFile;
|
||||
// Carga los offsets desde el fichero
|
||||
initOffsetFromFile(textFile);
|
||||
|
||||
init();
|
||||
// Crea los objetos
|
||||
texture = new LTexture(renderer, bitmapFile);
|
||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -22,35 +21,6 @@ Text::~Text()
|
||||
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
|
||||
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
|
||||
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);
|
||||
printf("Reading file %s\n", file.c_str());
|
||||
|
||||
if (rfile.is_open() && rfile.good())
|
||||
{
|
||||
@@ -164,7 +143,9 @@ void Text::initOffsetFromFile()
|
||||
{
|
||||
// Almacena solo las lineas impares
|
||||
if (line_read % 2 == 1)
|
||||
{
|
||||
offset[index++].w = std::stoi(buffer);
|
||||
}
|
||||
|
||||
// Limpia el buffer
|
||||
buffer.clear();
|
||||
@@ -172,14 +153,21 @@ void Text::initOffsetFromFile()
|
||||
};
|
||||
|
||||
// Cierra el fichero
|
||||
printf("Closing file %s\n\n", file.c_str());
|
||||
printf("Text loaded: %s\n", filename.c_str());
|
||||
rfile.close();
|
||||
}
|
||||
|
||||
// El fichero no se puede abrir
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include "sprite.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef TEXT_H
|
||||
#define TEXT_H
|
||||
|
||||
#define TXT_COLOR 1
|
||||
#define TXT_SHADOW 2
|
||||
#define TXT_CENTER 4
|
||||
#define TXT_STROKE 8
|
||||
|
||||
// Clase texto. Pinta texto en pantalla a partir de un bitmap
|
||||
class Text
|
||||
{
|
||||
private:
|
||||
Sprite *sprite; // Objeto con los graficos para el texto
|
||||
|
||||
struct Offset
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
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
|
||||
int boxHeight; // Altura de la caja de cada caracter en el png
|
||||
std::string file; // Fichero con los descriptores de la fuente
|
||||
LTexture *texture; // Textura con los bitmaps del texto
|
||||
|
||||
// Inicializador
|
||||
void init();
|
||||
|
||||
// Inicializa el vector de offsets desde un fichero
|
||||
void initOffsetFromFile();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Text();
|
||||
|
||||
// Escribe el texto en pantalla
|
||||
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto con colores
|
||||
void writeColored(int x, int y, std::string text, color_t color, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto con sombra
|
||||
void writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto centrado en un punto x
|
||||
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe texto con extras
|
||||
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = {255, 255, 255}, Uint8 shadowDistance = 1, color_t shadowColor = {0, 0, 0}, int lenght = -1);
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
int lenght(std::string text, int kerning = 1);
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
int getCharacterSize();
|
||||
|
||||
// Recarga la textura
|
||||
void reLoadTexture();
|
||||
};
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#include "sprite.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef TEXT_H
|
||||
#define TEXT_H
|
||||
|
||||
#define TXT_COLOR 1
|
||||
#define TXT_SHADOW 2
|
||||
#define TXT_CENTER 4
|
||||
#define TXT_STROKE 8
|
||||
|
||||
// Clase texto. Pinta texto en pantalla a partir de un bitmap
|
||||
class Text
|
||||
{
|
||||
private:
|
||||
struct offset_t
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
};
|
||||
|
||||
// Objetos
|
||||
Sprite *sprite; // Objeto con los graficos para el texto
|
||||
LTexture *texture; // Textura con los bitmaps del texto
|
||||
|
||||
// Variables
|
||||
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
|
||||
void initOffsetFromFile(std::string file);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Text();
|
||||
|
||||
// Escribe el texto en pantalla
|
||||
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto con colores
|
||||
void writeColored(int x, int y, std::string text, color_t color, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto con sombra
|
||||
void writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe el texto centrado en un punto x
|
||||
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||
|
||||
// Escribe texto con extras
|
||||
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = {255, 255, 255}, Uint8 shadowDistance = 1, color_t shadowColor = {0, 0, 0}, int lenght = -1);
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
int lenght(std::string text, int kerning = 1);
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
int getCharacterSize();
|
||||
|
||||
// Recarga la textura
|
||||
void reLoadTexture();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -350,91 +350,91 @@ void Director::initInput()
|
||||
bool Director::setFileList()
|
||||
{
|
||||
// Ficheros del mapa
|
||||
asset->add("/data/map/01.map", data);
|
||||
asset->add("/data/map/01.tmx", data);
|
||||
asset->add("/data/map/01.ene", data);
|
||||
asset->add("/data/map/02.map", data);
|
||||
asset->add("/data/map/02.tmx", data);
|
||||
asset->add("/data/map/02.ene", data);
|
||||
asset->add("/data/map/03.map", data);
|
||||
asset->add("/data/map/03.tmx", data);
|
||||
asset->add("/data/map/03.ene", data);
|
||||
asset->add("/data/map/04.map", data);
|
||||
asset->add("/data/map/04.tmx", data);
|
||||
asset->add("/data/map/05.map", data);
|
||||
asset->add("/data/map/05.tmx", data);
|
||||
asset->add("/data/map/06.map", data);
|
||||
asset->add("/data/map/06.tmx", data);
|
||||
asset->add("/data/map/07.map", data);
|
||||
asset->add("/data/map/07.tmx", data);
|
||||
asset->add("/data/map/08.map", data);
|
||||
asset->add("/data/map/08.tmx", data);
|
||||
asset->add("/data/map/09.map", data);
|
||||
asset->add("/data/map/09.tmx", data);
|
||||
asset->add("/data/map/10.map", data);
|
||||
asset->add("/data/map/10.tmx", data);
|
||||
asset->add("/data/map/tiles_surface.png", bitmap);
|
||||
asset->add("/data/map/01.map", t_data);
|
||||
asset->add("/data/map/01.tmx", t_data);
|
||||
asset->add("/data/map/01.ene", t_data);
|
||||
asset->add("/data/map/02.map", t_data);
|
||||
asset->add("/data/map/02.tmx", t_data);
|
||||
asset->add("/data/map/02.ene", t_data);
|
||||
asset->add("/data/map/03.map", t_data);
|
||||
asset->add("/data/map/03.tmx", t_data);
|
||||
asset->add("/data/map/03.ene", t_data);
|
||||
asset->add("/data/map/04.map", t_data);
|
||||
asset->add("/data/map/04.tmx", t_data);
|
||||
asset->add("/data/map/05.map", t_data);
|
||||
asset->add("/data/map/05.tmx", t_data);
|
||||
asset->add("/data/map/06.map", t_data);
|
||||
asset->add("/data/map/06.tmx", t_data);
|
||||
asset->add("/data/map/07.map", t_data);
|
||||
asset->add("/data/map/07.tmx", t_data);
|
||||
asset->add("/data/map/08.map", t_data);
|
||||
asset->add("/data/map/08.tmx", t_data);
|
||||
asset->add("/data/map/09.map", t_data);
|
||||
asset->add("/data/map/09.tmx", t_data);
|
||||
asset->add("/data/map/10.map", t_data);
|
||||
asset->add("/data/map/10.tmx", t_data);
|
||||
asset->add("/data/map/tiles_surface.png", t_bitmap);
|
||||
|
||||
// Ficheros de configuración
|
||||
asset->add("/data/config/config.txt", data, false);
|
||||
asset->add("/data/input/gamecontrollerdb.txt", data);
|
||||
asset->add("/data/config/config.txt", t_data, false);
|
||||
asset->add("/data/input/gamecontrollerdb.txt", t_data);
|
||||
|
||||
// Ficheros del jugador
|
||||
asset->add("/data/player/player.png", bitmap);
|
||||
asset->add("/data/player/player.ani", data);
|
||||
asset->add("/data/player/player.png", t_bitmap);
|
||||
asset->add("/data/player/player.ani", t_data);
|
||||
|
||||
// Ficheros de sonido
|
||||
asset->add("/data/sound/sound_player_coin.wav", sound);
|
||||
asset->add("/data/sound/sound_player_death.wav", sound);
|
||||
asset->add("/data/sound/sound_drop_enemy.wav", sound);
|
||||
asset->add("/data/sound/sound_drop_splat.wav", sound);
|
||||
asset->add("/data/sound/sound_player_jump.wav", sound);
|
||||
asset->add("/data/sound/sound_menu_logo.wav", sound);
|
||||
asset->add("/data/sound/sound_menu_start.wav", sound);
|
||||
asset->add("/data/sound/sound_menu_select.wav", sound);
|
||||
asset->add("/data/sound/sound_menu_cancel.wav", sound);
|
||||
asset->add("/data/sound/sound_menu_move.wav", sound);
|
||||
asset->add("/data/sound/sound_player_coin.wav", t_sound);
|
||||
asset->add("/data/sound/sound_player_death.wav", t_sound);
|
||||
asset->add("/data/sound/sound_drop_enemy.wav", t_sound);
|
||||
asset->add("/data/sound/sound_drop_splat.wav", t_sound);
|
||||
asset->add("/data/sound/sound_player_jump.wav", t_sound);
|
||||
asset->add("/data/sound/sound_menu_logo.wav", t_sound);
|
||||
asset->add("/data/sound/sound_menu_start.wav", t_sound);
|
||||
asset->add("/data/sound/sound_menu_select.wav", t_sound);
|
||||
asset->add("/data/sound/sound_menu_cancel.wav", t_sound);
|
||||
asset->add("/data/sound/sound_menu_move.wav", t_sound);
|
||||
|
||||
// Ficheros con musica
|
||||
asset->add("/data/music/music_title.ogg", music);
|
||||
asset->add("/data/music/music_surface.ogg", music);
|
||||
asset->add("/data/music/music_volcano.ogg", music);
|
||||
asset->add("/data/music/music_title.ogg", t_music);
|
||||
asset->add("/data/music/music_surface.ogg", t_music);
|
||||
asset->add("/data/music/music_volcano.ogg", t_music);
|
||||
|
||||
// Ficheros de fuentes de texto
|
||||
asset->add("/data/font/debug.png", font);
|
||||
asset->add("/data/font/debug.txt", font);
|
||||
asset->add("/data/font/dogica.png", font);
|
||||
asset->add("/data/font/dogica.txt", font);
|
||||
asset->add("/data/font/smb2.png", font);
|
||||
asset->add("/data/font/smb2.txt", font);
|
||||
asset->add("/data/font/debug.png", t_font);
|
||||
asset->add("/data/font/debug.txt", t_font);
|
||||
asset->add("/data/font/dogica.png", t_font);
|
||||
asset->add("/data/font/dogica.txt", t_font);
|
||||
asset->add("/data/font/smb2.png", t_font);
|
||||
asset->add("/data/font/smb2.txt", t_font);
|
||||
|
||||
// Ficheros de enemigos
|
||||
asset->add("/data/actors/enemies/walking_eye.png", bitmap);
|
||||
asset->add("/data/actors/enemies/walking_eye.ani", data);
|
||||
asset->add("/data/actors/enemies/bug.png", bitmap);
|
||||
asset->add("/data/actors/enemies/bug.ani", data);
|
||||
asset->add("/data/actors/enemies/flying_eye.png", bitmap);
|
||||
asset->add("/data/actors/enemies/flying_eye.ani", data);
|
||||
asset->add("/data/actors/enemies/flying_eye_horn.png", bitmap);
|
||||
asset->add("/data/actors/enemies/flying_eye_horn.ani", data);
|
||||
asset->add("/data/actors/enemies/manzana.png", bitmap);
|
||||
asset->add("/data/actors/enemies/manzana.ani", data);
|
||||
asset->add("/data/actors/enemies/walking_eye.png", t_bitmap);
|
||||
asset->add("/data/actors/enemies/walking_eye.ani", t_data);
|
||||
asset->add("/data/actors/enemies/bug.png", t_bitmap);
|
||||
asset->add("/data/actors/enemies/bug.ani", t_data);
|
||||
asset->add("/data/actors/enemies/flying_eye.png", t_bitmap);
|
||||
asset->add("/data/actors/enemies/flying_eye.ani", t_data);
|
||||
asset->add("/data/actors/enemies/flying_eye_horn.png", t_bitmap);
|
||||
asset->add("/data/actors/enemies/flying_eye_horn.ani", t_data);
|
||||
asset->add("/data/actors/enemies/manzana.png", t_bitmap);
|
||||
asset->add("/data/actors/enemies/manzana.ani", t_data);
|
||||
|
||||
// Ficheros de actores
|
||||
asset->add("/data/actors/moving_platform.png", bitmap);
|
||||
asset->add("/data/actors/moving_platform.ani", data);
|
||||
asset->add("/data/actors/items/diamond.png", bitmap);
|
||||
asset->add("/data/actors/items/diamond.ani", data);
|
||||
asset->add("/data/actors/moving_platform.png", t_bitmap);
|
||||
asset->add("/data/actors/moving_platform.ani", t_data);
|
||||
asset->add("/data/actors/items/diamond.png", t_bitmap);
|
||||
asset->add("/data/actors/items/diamond.ani", t_data);
|
||||
|
||||
// Ficheros del logo
|
||||
asset->add("/data/logo/logo.png", bitmap);
|
||||
asset->add("/data/logo/logo.png", t_bitmap);
|
||||
|
||||
// Ficheros de la intro
|
||||
asset->add("/data/intro/intro.png", bitmap);
|
||||
asset->add("/data/intro/intro.ani", data);
|
||||
asset->add("/data/intro/intro.png", t_bitmap);
|
||||
asset->add("/data/intro/intro.ani", t_data);
|
||||
|
||||
// Ficheros de menu
|
||||
asset->add("/data/menu/title.men", data);
|
||||
asset->add("/data/menu/title.men", t_data);
|
||||
|
||||
return asset->check();
|
||||
}
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string>
|
||||
#include "asset.h"
|
||||
#include "jail_audio.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/const.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 "input.h"
|
||||
#include "utils.h"
|
||||
#include "screen.h"
|
||||
#include "logo.h"
|
||||
#include "intro.h"
|
||||
#include "logo.h"
|
||||
#include "title.h"
|
||||
#include "debug.h"
|
||||
#include "const.h"
|
||||
#include <string>
|
||||
|
||||
#ifndef PROG_H
|
||||
#define PROG_H
|
||||
|
||||
// Textos
|
||||
#define WINDOW_CAPTION "Volcano"
|
||||
|
||||
class Director
|
||||
{
|
||||
private:
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "asset.h"
|
||||
#include "animatedsprite.h"
|
||||
#include "common/animatedsprite.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/utils.h"
|
||||
#include <string>
|
||||
|
||||
#ifndef ENEMY_H
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "asset.h"
|
||||
#include "enemy.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/utils.h"
|
||||
#include "enemy_path.h"
|
||||
#include "enemy.h"
|
||||
#include "map.h"
|
||||
#include "player.h"
|
||||
#include <string>
|
||||
|
||||
@@ -35,7 +35,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, D
|
||||
ticksSpeed = 15;
|
||||
|
||||
section.name = SECTION_PROG_GAME;
|
||||
section.subsection = SUBSECTION_GAME_PLAY;
|
||||
section.subsection = 0;
|
||||
|
||||
musicEnabled = !debug->getEnabled();
|
||||
|
||||
@@ -69,7 +69,7 @@ section_t Game::run()
|
||||
while (section.name == SECTION_PROG_GAME)
|
||||
{
|
||||
// Sección juego jugando
|
||||
if (section.subsection == SUBSECTION_GAME_PLAY)
|
||||
if (section.subsection == 0)
|
||||
{
|
||||
update();
|
||||
render();
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "asset.h"
|
||||
#include "screen.h"
|
||||
#include "input.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/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 "player.h"
|
||||
#include "item_tracker.h"
|
||||
#include "enemy_engine.h"
|
||||
#include "text.h"
|
||||
#include "scoreboard.h"
|
||||
#include "debug.h"
|
||||
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "const.h"
|
||||
#include "asset.h"
|
||||
#include "utils.h"
|
||||
#include "screen.h"
|
||||
#include "animatedsprite.h"
|
||||
#include "jail_audio.h"
|
||||
#include "common/animatedsprite.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/const.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/utils.h"
|
||||
|
||||
#ifndef INTRO_H
|
||||
#define INTRO_H
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "common/utils.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "const.h"
|
||||
#include "utils.h"
|
||||
#include "sprite.h"
|
||||
#include "screen.h"
|
||||
#include "asset.h"
|
||||
#include "jail_audio.h"
|
||||
#include "const.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/const.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/utils.h"
|
||||
|
||||
#ifndef LOGO_H
|
||||
#define LOGO_H
|
||||
|
||||
14
source/map.h
14
source/map.h
@@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#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_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 <vector>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#ifndef MAP_H
|
||||
#define MAP_H
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#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 "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
|
||||
#define PLAYER_H
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "text.h"
|
||||
#include "asset.h"
|
||||
#include "sprite.h"
|
||||
#include "const.h"
|
||||
#include "input.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/const.h"
|
||||
#include "common/input.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/text.h"
|
||||
#include "common/utils.h"
|
||||
#include <string>
|
||||
|
||||
#ifndef SCOREBOARD_H
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "const.h"
|
||||
#include "asset.h"
|
||||
#include "utils.h"
|
||||
#include "input.h"
|
||||
#include "screen.h"
|
||||
#include "text.h"
|
||||
#include "menu.h"
|
||||
#include "animatedsprite.h"
|
||||
#include "jail_audio.h"
|
||||
#include "common/animatedsprite.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/const.h"
|
||||
#include "common/input.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/menu.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/text.h"
|
||||
#include "common/utils.h"
|
||||
|
||||
#ifndef TITLE_H
|
||||
#define TITLE_H
|
||||
|
||||
#define TEXT_COPYRIGHT "2016,2022 JAILDESIGNER & JAILBROTHER"
|
||||
#define VERSION "0.6"
|
||||
|
||||
// Clase Intro
|
||||
class Title
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user