Arreglos en la estructura i format del codi
This commit is contained in:
@@ -16,7 +16,8 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
resource_(Resource::get()),
|
||||
asset_(Asset::get()),
|
||||
data_(data)
|
||||
data_(data),
|
||||
clock_(ClockData())
|
||||
{
|
||||
const int TEXTURE_WIDTH_ = options.game.width;
|
||||
constexpr int TEXTURE_HEIGHT_ = 6 * BLOCK;
|
||||
@@ -48,10 +49,10 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||
items_color_ = stringToColor(options.video.palette, "white");
|
||||
|
||||
// Inicializa el vector de colores
|
||||
const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
||||
for (auto v : vColors)
|
||||
const std::vector<std::string> COLORS = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
||||
for (const auto &color : COLORS)
|
||||
{
|
||||
color_.push_back(stringToColor(options.video.palette, v));
|
||||
color_.push_back(stringToColor(options.video.palette, color));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,21 +14,21 @@ class Texture;
|
||||
|
||||
struct ScoreboardData
|
||||
{
|
||||
int items; // Lleva la cuenta de los objetos recogidos
|
||||
int lives; // Lleva la cuenta de las vidas restantes del jugador
|
||||
int rooms; // Lleva la cuenta de las habitaciones visitadas
|
||||
bool music; // Indica si ha de sonar la música durante el juego
|
||||
Color color; // Color para escribir el texto del marcador
|
||||
Uint32 ini_clock; // Tiempo inicial para calcular el tiempo transcurrido
|
||||
bool jail_is_open; // Indica si se puede entrar a la Jail
|
||||
int items; // Lleva la cuenta de los objetos recogidos
|
||||
int lives; // Lleva la cuenta de las vidas restantes del jugador
|
||||
int rooms; // Lleva la cuenta de las habitaciones visitadas
|
||||
bool music; // Indica si ha de sonar la música durante el juego
|
||||
Color color; // Color para escribir el texto del marcador
|
||||
Uint32 ini_clock; // Tiempo inicial para calcular el tiempo transcurrido
|
||||
bool jail_is_open; // Indica si se puede entrar a la Jail
|
||||
|
||||
// Constructor por defecto
|
||||
ScoreboardData()
|
||||
: items(0), lives(0), rooms(0), music(true), color({0, 0, 0}), ini_clock(0), jail_is_open(false) {}
|
||||
// Constructor por defecto
|
||||
ScoreboardData()
|
||||
: items(0), lives(0), rooms(0), music(true), color({0, 0, 0}), ini_clock(0), jail_is_open(false) {}
|
||||
|
||||
// Constructor parametrizado
|
||||
ScoreboardData(int items, int lives, int rooms, bool music, Color color, Uint32 ini_clock, bool jail_is_open)
|
||||
: items(items), lives(lives), rooms(rooms), music(music), color(color), ini_clock(ini_clock), jail_is_open(jail_is_open) {}
|
||||
// Constructor parametrizado
|
||||
ScoreboardData(int items, int lives, int rooms, bool music, Color color, Uint32 ini_clock, bool jail_is_open)
|
||||
: items(items), lives(lives), rooms(rooms), music(music), color(color), ini_clock(ini_clock), jail_is_open(jail_is_open) {}
|
||||
};
|
||||
|
||||
class Scoreboard
|
||||
@@ -40,6 +40,14 @@ private:
|
||||
int minutes;
|
||||
int seconds;
|
||||
std::string separator;
|
||||
|
||||
// Constructor por defecto
|
||||
ClockData()
|
||||
: hours(0), minutes(0), seconds(0), separator(":") {}
|
||||
|
||||
// Constructor parametrizado
|
||||
ClockData(int h, int m, int s, const std::string &sep)
|
||||
: hours(h), minutes(m), seconds(s), separator(sep) {}
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
|
||||
@@ -415,13 +415,4 @@ int Screen::getMaxZoom()
|
||||
options.window.zoom = std::min(options.window.zoom, max_zoom);
|
||||
|
||||
return max_zoom;
|
||||
}
|
||||
|
||||
// Renderiza un frame negro
|
||||
void Screen::renderBlackFrame()
|
||||
{
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
SDL_RenderPresent(renderer_);
|
||||
}
|
||||
@@ -58,9 +58,6 @@ private:
|
||||
// Ajusta el tamaño lógico del renderizador
|
||||
void adjustRenderLogicalSize();
|
||||
|
||||
// Renderiza un frame negro
|
||||
void renderBlackFrame();
|
||||
|
||||
// Constructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
||||
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
#include "stats.h"
|
||||
#include <fstream> // for basic_ostream, basic_ifstream, basic_istream
|
||||
#include <sstream> // for basic_stringstream
|
||||
#include "options.h" // for Options, OptionsStats, options
|
||||
#include <fstream> // for basic_ostream, basic_ifstream, basic_istream
|
||||
#include <sstream> // for basic_stringstream
|
||||
#include "options.h" // for Options, OptionsStats, options
|
||||
|
||||
// Constructor
|
||||
Stats::Stats(std::string file, std::string buffer)
|
||||
{
|
||||
bufferPath = buffer;
|
||||
filePath = file;
|
||||
bufferList.clear();
|
||||
list.clear();
|
||||
dictionary.clear();
|
||||
}
|
||||
Stats::Stats(const std::string &file, const std::string &buffer)
|
||||
: bufferPath(buffer),
|
||||
filePath(file) {}
|
||||
|
||||
// Destructor
|
||||
Stats::~Stats()
|
||||
@@ -43,7 +38,7 @@ void Stats::init()
|
||||
}
|
||||
|
||||
// Añade una muerte a las estadisticas
|
||||
void Stats::addDeath(std::string name)
|
||||
void Stats::addDeath(const std::string &name)
|
||||
{
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
const int index = findByName(name, bufferList);
|
||||
@@ -64,7 +59,7 @@ void Stats::addDeath(std::string name)
|
||||
}
|
||||
|
||||
// Añade una visita a las estadisticas
|
||||
void Stats::addVisit(std::string name)
|
||||
void Stats::addVisit(const std::string &name)
|
||||
{
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
const int index = findByName(name, bufferList);
|
||||
@@ -85,11 +80,11 @@ void Stats::addVisit(std::string name)
|
||||
}
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int Stats::findByName(std::string name, std::vector<stats_t> &list)
|
||||
int Stats::findByName(const std::string &name, const std::vector<stats_t> &list)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (auto l : list)
|
||||
for (const auto &l : list)
|
||||
{
|
||||
if (l.name == name)
|
||||
{
|
||||
@@ -102,7 +97,7 @@ int Stats::findByName(std::string name, std::vector<stats_t> &list)
|
||||
}
|
||||
|
||||
// Carga las estadisticas desde un fichero
|
||||
bool Stats::loadFromFile(std::string filePath, std::vector<stats_t> &list)
|
||||
bool Stats::loadFromFile(const std::string &file_path, std::vector<stats_t> &list)
|
||||
{
|
||||
list.clear();
|
||||
|
||||
@@ -110,12 +105,12 @@ bool Stats::loadFromFile(std::string filePath, std::vector<stats_t> &list)
|
||||
bool success = true;
|
||||
|
||||
// Variables para manejar el fichero
|
||||
std::string line;
|
||||
std::ifstream file(filePath);
|
||||
|
||||
std::ifstream file(file_path);
|
||||
|
||||
// Si el fichero se puede abrir
|
||||
if (file.good())
|
||||
{
|
||||
std::string line;
|
||||
// Procesa el fichero linea a linea
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
@@ -150,21 +145,21 @@ bool Stats::loadFromFile(std::string filePath, std::vector<stats_t> &list)
|
||||
else
|
||||
{
|
||||
// Crea el fichero con los valores por defecto
|
||||
saveToFile(filePath, list);
|
||||
saveToFile(file_path, list);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Guarda las estadisticas en un fichero
|
||||
void Stats::saveToFile(std::string filePath, std::vector<stats_t> &list)
|
||||
void Stats::saveToFile(const std::string &file_path, const std::vector<stats_t> &list)
|
||||
{
|
||||
// Crea y abre el fichero de texto
|
||||
std::ofstream file(filePath);
|
||||
std::ofstream file(file_path);
|
||||
|
||||
// Escribe en el fichero
|
||||
file << "# ROOM NAME;VISITS;DEATHS" << std::endl;
|
||||
for (auto item : list)
|
||||
for (const auto &item : list)
|
||||
{
|
||||
file << item.name << ";" << item.visited << ";" << item.died << std::endl;
|
||||
}
|
||||
@@ -177,7 +172,7 @@ void Stats::saveToFile(std::string filePath, std::vector<stats_t> &list)
|
||||
void Stats::checkWorstNightmare()
|
||||
{
|
||||
int deaths = 0;
|
||||
for (auto item : list)
|
||||
for (const auto &item : list)
|
||||
{
|
||||
if (item.died > deaths)
|
||||
{
|
||||
@@ -188,42 +183,16 @@ void Stats::checkWorstNightmare()
|
||||
}
|
||||
|
||||
// Añade una entrada al diccionario
|
||||
void Stats::addDictionary(std::string number, std::string name)
|
||||
void Stats::addDictionary(const std::string &number, const std::string &name)
|
||||
{
|
||||
dictionary.push_back({number, name});
|
||||
}
|
||||
|
||||
// Obtiene el nombre de una habitación a partir del número
|
||||
std::string Stats::numberToName(std::string number)
|
||||
{
|
||||
for (auto l : dictionary)
|
||||
{
|
||||
if (l.number == number)
|
||||
{
|
||||
return l.name;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Obtiene el número de una habitación a partir del nombre
|
||||
std::string Stats::nameToNumber(std::string name)
|
||||
{
|
||||
for (auto l : dictionary)
|
||||
{
|
||||
if (l.name == name)
|
||||
{
|
||||
return l.number;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Vuelca los datos del buffer en la lista de estadisticas
|
||||
void Stats::updateListFromBuffer()
|
||||
{
|
||||
// Actualiza list desde bufferList
|
||||
for (auto buffer : bufferList)
|
||||
for (const auto &buffer : bufferList)
|
||||
{
|
||||
int index = findByName(buffer.name, list);
|
||||
|
||||
|
||||
@@ -27,43 +27,37 @@ private:
|
||||
std::string filePath; // Fichero con las estadísticas completas
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int findByName(std::string name, std::vector<stats_t> &list);
|
||||
int findByName(const std::string &name, const std::vector<stats_t> &list);
|
||||
|
||||
// Carga las estadisticas desde un fichero
|
||||
bool loadFromFile(std::string filePath, std::vector<stats_t> &list);
|
||||
bool loadFromFile(const std::string &filePath, std::vector<stats_t> &list);
|
||||
|
||||
// Guarda las estadisticas en un fichero
|
||||
void saveToFile(std::string filePath, std::vector<stats_t> &list);
|
||||
void saveToFile(const std::string &filePath, const std::vector<stats_t> &list);
|
||||
|
||||
// Calcula cual es la habitación con más muertes
|
||||
void checkWorstNightmare();
|
||||
|
||||
// Obtiene el nombre de una habitación a partir del número
|
||||
std::string numberToName(std::string number);
|
||||
|
||||
// Obtiene el número de una habitación a partir del nombre
|
||||
std::string nameToNumber(std::string name);
|
||||
|
||||
// Vuelca los datos del buffer en la lista de estadisticas
|
||||
void updateListFromBuffer();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Stats(std::string file, std::string buffer);
|
||||
Stats(const std::string &file, const std::string &buffer);
|
||||
|
||||
// Destructor
|
||||
~Stats();
|
||||
|
||||
// Inicializador
|
||||
// Se debe llamar a este procedimiento una vez se haya creado el diccionario numero-nombre
|
||||
void init();
|
||||
void init();
|
||||
|
||||
// Añade una muerte a las estadisticas
|
||||
void addDeath(std::string name);
|
||||
void addDeath(const std::string &name);
|
||||
|
||||
// Añade una visita a las estadisticas
|
||||
void addVisit(std::string name);
|
||||
void addVisit(const std::string &name);
|
||||
|
||||
// Añade una entrada al diccionario
|
||||
void addDictionary(std::string number, std::string name);
|
||||
void addDictionary(const std::string &number, const std::string &name);
|
||||
};
|
||||
@@ -15,12 +15,10 @@ Surface::Surface(std::shared_ptr<SurfaceData> surface_dest, int w, int h)
|
||||
surface_(std::make_shared<SurfaceData>(w, h)),
|
||||
transparent_color_(0) {}
|
||||
|
||||
Surface::Surface(std::shared_ptr<SurfaceData> surface_dest, std::string file_path)
|
||||
Surface::Surface(std::shared_ptr<SurfaceData> surface_dest, const std::string &file_path)
|
||||
: surface_dest_(surface_dest),
|
||||
surface_(std::make_shared<SurfaceData>(loadSurface(Asset::get()->get(file_path)))),
|
||||
transparent_color_(0) {
|
||||
std::cout << "surface loaded: "<< surface_->width << "x" << surface_->height << std::endl;
|
||||
}
|
||||
transparent_color_(0) {}
|
||||
|
||||
Surface::~Surface() {}
|
||||
|
||||
@@ -137,7 +135,7 @@ void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
|
||||
{
|
||||
throw std::runtime_error("Surface source or destination is null.");
|
||||
}
|
||||
|
||||
|
||||
// Limitar la región para evitar accesos fuera de rango
|
||||
w = std::min(w, surface_->width - sx);
|
||||
h = std::min(h, surface_->height - sy);
|
||||
|
||||
@@ -74,7 +74,7 @@ private:
|
||||
public:
|
||||
// Constructor
|
||||
Surface(std::shared_ptr<SurfaceData> surface_dest, int w, int h);
|
||||
Surface(std::shared_ptr<SurfaceData> surface_dest, std::string file_path);
|
||||
Surface(std::shared_ptr<SurfaceData> surface_dest, const std::string &file_path);
|
||||
|
||||
// Destructor
|
||||
~Surface();
|
||||
|
||||
@@ -196,7 +196,7 @@ void Title::updateMarquee()
|
||||
// Dibuja la marquesina
|
||||
void Title::renderMarquee()
|
||||
{
|
||||
for (auto l : letters_)
|
||||
for (const auto &l : letters_)
|
||||
{
|
||||
if (l.enabled)
|
||||
{
|
||||
@@ -205,14 +205,6 @@ void Title::renderMarquee()
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja la linea de información inferior
|
||||
void Title::renderInfo()
|
||||
{
|
||||
const std::string version = "v.1.10";
|
||||
const int x = GAMECANVAS_WIDTH - info_text_->lenght(version) - 1;
|
||||
info_text_->write(x, 1, version);
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void Title::update()
|
||||
{
|
||||
@@ -319,40 +311,6 @@ void Title::run()
|
||||
}
|
||||
}
|
||||
|
||||
// Recarga las texturas
|
||||
void Title::reLoadTextures()
|
||||
{
|
||||
// Carga la textura adecuada
|
||||
if (options.video.palette == Palette::ZXSPECTRUM)
|
||||
{
|
||||
texture_ = resource_->getTexture("loading_screen_color.png");
|
||||
}
|
||||
else if (options.video.palette == Palette::ZXARNE)
|
||||
{
|
||||
texture_ = resource_->getTexture("loading_screen_color_zxarne.png");
|
||||
}
|
||||
|
||||
texture_->reLoad();
|
||||
}
|
||||
|
||||
// Cambia la paleta
|
||||
void Title::switchPalette()
|
||||
{
|
||||
if (options.video.palette == Palette::ZXSPECTRUM)
|
||||
{
|
||||
options.video.palette = Palette::ZXARNE;
|
||||
sprite_->setTexture(resource_->getTexture("loading_screen_color_zxarne.png"));
|
||||
}
|
||||
else
|
||||
{
|
||||
options.video.palette = Palette::ZXSPECTRUM;
|
||||
sprite_->setTexture(resource_->getTexture("loading_screen_color.png"));
|
||||
}
|
||||
|
||||
// Cambia el color del borde
|
||||
screen_->setBorderColor(stringToColor(options.video.palette, "bright_blue"));
|
||||
}
|
||||
|
||||
// Desplaza la lista de logros
|
||||
void Title::moveCheevosList(int direction)
|
||||
{
|
||||
@@ -432,7 +390,7 @@ void Title::createCheevosTexture()
|
||||
constexpr int LINE_X1 = (CHEEVOS_TEXTURE_WIDTH / 7) * 3;
|
||||
constexpr int LINE_X2 = LINE_X1 + ((CHEEVOS_TEXTURE_WIDTH / 7) * 1);
|
||||
|
||||
for (auto cheevo : cheevosList)
|
||||
for (const auto &cheevo : cheevosList)
|
||||
{
|
||||
cheevoColor = cheevo.completed ? CHEEVO_UNLOCKED_COLOR : CHEEVO_LOCKED_COLOR;
|
||||
pos += CHEEVOS_PADDING;
|
||||
|
||||
@@ -76,15 +76,6 @@ private:
|
||||
// Dibuja la marquesina
|
||||
void renderMarquee();
|
||||
|
||||
// Dibuja la linea de información inferior
|
||||
void renderInfo();
|
||||
|
||||
// Recarga las texturas
|
||||
void reLoadTextures();
|
||||
|
||||
// Cambia la paleta
|
||||
void switchPalette();
|
||||
|
||||
// Desplaza la lista de logros
|
||||
void moveCheevosList(int direction);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ double distanceSquared(int x1, int y1, int x2, int y2)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre dos circulos
|
||||
bool checkCollision(Circle &a, Circle &b)
|
||||
bool checkCollision(const Circle &a, const Circle &b)
|
||||
{
|
||||
// Calcula el radio total al cuadrado
|
||||
int totalRadiusSquared = a.r + b.r;
|
||||
@@ -38,7 +38,7 @@ bool checkCollision(Circle &a, Circle &b)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre un circulo y un rectangulo
|
||||
bool checkCollision(Circle &a, SDL_Rect &b)
|
||||
bool checkCollision(const Circle &a, const SDL_Rect &b)
|
||||
{
|
||||
// Closest point on collision box
|
||||
int cX, cY;
|
||||
@@ -83,7 +83,7 @@ bool checkCollision(Circle &a, SDL_Rect &b)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre dos rectangulos
|
||||
bool checkCollision(SDL_Rect &a, SDL_Rect &b)
|
||||
bool checkCollision(const SDL_Rect &a, const SDL_Rect &b)
|
||||
{
|
||||
// Calcula las caras del rectangulo a
|
||||
const int leftA = a.x;
|
||||
@@ -123,7 +123,7 @@ bool checkCollision(SDL_Rect &a, SDL_Rect &b)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre un punto y un rectangulo
|
||||
bool checkCollision(SDL_Point &p, SDL_Rect &r)
|
||||
bool checkCollision(const SDL_Point &p, const SDL_Rect &r)
|
||||
{
|
||||
// Comprueba si el punto está a la izquierda del rectangulo
|
||||
if (p.x < r.x)
|
||||
@@ -154,7 +154,7 @@ bool checkCollision(SDL_Point &p, SDL_Rect &r)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre una linea horizontal y un rectangulo
|
||||
bool checkCollision(h_line_t &l, SDL_Rect &r)
|
||||
bool checkCollision(const h_line_t &l, const SDL_Rect &r)
|
||||
{
|
||||
// Comprueba si la linea esta por encima del rectangulo
|
||||
if (l.y < r.y)
|
||||
@@ -185,7 +185,7 @@ bool checkCollision(h_line_t &l, SDL_Rect &r)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre una linea vertical y un rectangulo
|
||||
bool checkCollision(v_line_t &l, SDL_Rect &r)
|
||||
bool checkCollision(const v_line_t &l, const SDL_Rect &r)
|
||||
{
|
||||
// Comprueba si la linea esta por la izquierda del rectangulo
|
||||
if (l.x < r.x)
|
||||
@@ -216,7 +216,7 @@ bool checkCollision(v_line_t &l, SDL_Rect &r)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre una linea horizontal y un punto
|
||||
bool checkCollision(h_line_t &l, SDL_Point &p)
|
||||
bool checkCollision(const h_line_t &l, const SDL_Point &p)
|
||||
{
|
||||
// Comprueba si el punto esta sobre la linea
|
||||
if (p.y > l.y)
|
||||
@@ -247,7 +247,7 @@ bool checkCollision(h_line_t &l, SDL_Point &p)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre dos lineas
|
||||
SDL_Point checkCollision(line_t &l1, line_t &l2)
|
||||
SDL_Point checkCollision(const line_t &l1, const line_t &l2)
|
||||
{
|
||||
const float x1 = l1.x1;
|
||||
const float y1 = l1.y1;
|
||||
@@ -276,7 +276,7 @@ SDL_Point checkCollision(line_t &l1, line_t &l2)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre dos lineas
|
||||
SDL_Point checkCollision(d_line_t &l1, v_line_t &l2)
|
||||
SDL_Point checkCollision(const d_line_t &l1, const v_line_t &l2)
|
||||
{
|
||||
const float x1 = l1.x1;
|
||||
const float y1 = l1.y1;
|
||||
@@ -321,7 +321,7 @@ void normalizeLine(d_line_t &l)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre un punto y una linea diagonal
|
||||
bool checkCollision(SDL_Point &p, d_line_t &l)
|
||||
bool checkCollision(const SDL_Point &p, const d_line_t &l)
|
||||
{
|
||||
// Comprueba si el punto está en alineado con la linea
|
||||
if (abs(p.x - l.x1) != abs(p.y - l.y1))
|
||||
@@ -464,36 +464,26 @@ bool colorAreEqual(Color color1, Color color2)
|
||||
return (r && g && b);
|
||||
}
|
||||
|
||||
// Convierte una cadena a minusculas
|
||||
// Convierte una cadena a minúsculas
|
||||
std::string toLower(std::string str)
|
||||
{
|
||||
const char *original = str.c_str();
|
||||
char *lower = (char *)malloc(str.size() + 1);
|
||||
for (int i = 0; i < (int)str.size(); ++i)
|
||||
{
|
||||
char c = original[i];
|
||||
lower[i] = (c >= 65 && c <= 90) ? c + 32 : c;
|
||||
for (char& c : str) {
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
c += 32; // Convierte a minúscula
|
||||
}
|
||||
}
|
||||
lower[str.size()] = 0;
|
||||
std::string result(lower);
|
||||
free(lower);
|
||||
return result;
|
||||
return str;
|
||||
}
|
||||
|
||||
// Convierte una cadena a mayúsculas
|
||||
std::string toUpper(std::string str)
|
||||
{
|
||||
const char *original = str.c_str();
|
||||
char *upper = (char *)malloc(str.size() + 1);
|
||||
for (int i = 0; i < (int)str.size(); ++i)
|
||||
{
|
||||
char c = original[i];
|
||||
upper[i] = (c >= 97 && c <= 122) ? c - 32 : c;
|
||||
for (char& c : str) {
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
c -= 32; // Convierte a mayúscula
|
||||
}
|
||||
}
|
||||
upper[str.size()] = 0;
|
||||
std::string result(upper);
|
||||
free(upper);
|
||||
return result;
|
||||
return str;
|
||||
}
|
||||
|
||||
// Obtiene el nombre de un fichero a partir de una ruta completa
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string
|
||||
#include <vector>
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL.h> // for SDL_Texture
|
||||
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL.h> // for SDL_Texture
|
||||
|
||||
// Tipos de paleta
|
||||
enum class Palette : int
|
||||
@@ -66,34 +65,34 @@ struct Color
|
||||
double distanceSquared(int x1, int y1, int x2, int y2);
|
||||
|
||||
// Detector de colisiones entre dos circulos
|
||||
bool checkCollision(Circle &a, Circle &b);
|
||||
bool checkCollision(const Circle &a, const Circle &b);
|
||||
|
||||
// Detector de colisiones entre un circulo y un rectangulo
|
||||
bool checkCollision(Circle &a, SDL_Rect &b);
|
||||
bool checkCollision(const Circle &a, const SDL_Rect &b);
|
||||
|
||||
// Detector de colisiones entre un dos rectangulos
|
||||
bool checkCollision(SDL_Rect &a, SDL_Rect &b);
|
||||
bool checkCollision(const SDL_Rect &a, const SDL_Rect &b);
|
||||
|
||||
// Detector de colisiones entre un punto y un rectangulo
|
||||
bool checkCollision(SDL_Point &p, SDL_Rect &r);
|
||||
bool checkCollision(const SDL_Point &p, const SDL_Rect &r);
|
||||
|
||||
// Detector de colisiones entre una linea horizontal y un rectangulo
|
||||
bool checkCollision(h_line_t &l, SDL_Rect &r);
|
||||
bool checkCollision(const h_line_t &l, const SDL_Rect &r);
|
||||
|
||||
// Detector de colisiones entre una linea vertical y un rectangulo
|
||||
bool checkCollision(v_line_t &l, SDL_Rect &r);
|
||||
bool checkCollision(const v_line_t &l, const SDL_Rect &r);
|
||||
|
||||
// Detector de colisiones entre una linea horizontal y un punto
|
||||
bool checkCollision(h_line_t &l, SDL_Point &p);
|
||||
bool checkCollision(const h_line_t &l, const SDL_Point &p);
|
||||
|
||||
// Detector de colisiones entre dos lineas
|
||||
SDL_Point checkCollision(line_t &l1, line_t &l2);
|
||||
SDL_Point checkCollision(const line_t &l1, const line_t &l2);
|
||||
|
||||
// Detector de colisiones entre dos lineas
|
||||
SDL_Point checkCollision(d_line_t &l1, v_line_t &l2);
|
||||
SDL_Point checkCollision(const d_line_t &l1, const v_line_t &l2);
|
||||
|
||||
// Detector de colisiones entre un punto y una linea diagonal
|
||||
bool checkCollision(SDL_Point &p, d_line_t &l);
|
||||
bool checkCollision(const SDL_Point &p, const d_line_t &l);
|
||||
|
||||
// Normaliza una linea diagonal
|
||||
void normalizeLine(d_line_t &l);
|
||||
@@ -135,4 +134,4 @@ bool stringInVector(const std::vector<std::string> &vec, const std::string &str)
|
||||
void playMusic(const std::string &music_path);
|
||||
|
||||
// Rellena una textura de un color
|
||||
void fillTextureWithColor(SDL_Renderer* renderer, SDL_Texture* texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
void fillTextureWithColor(SDL_Renderer *renderer, SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
Reference in New Issue
Block a user