Arreglos en la estructura i format del codi

This commit is contained in:
2025-03-02 09:32:25 +01:00
parent 193dac708f
commit b1ba5e67dc
41 changed files with 611 additions and 739 deletions

View File

@@ -1,15 +1,16 @@
#include "utils.h"
#include <stdlib.h> // for free, malloc, abs
#include <algorithm> // for transform
#include <cctype> // for tolower
#include <cmath> // for round, abs
#include <exception> // for exception
#include <filesystem> // for path
#include <iostream> // for basic_ostream, cout, basic_ios, ios, endl
#include <unordered_map> // for unordered_map
#include <string> // for string
#include "jail_audio.h"
#include "resource.h"
#include <stdlib.h> // for abs
#include <algorithm> // for find, transform
#include <cctype> // for tolower
#include <cmath> // for round, abs
#include <exception> // for exception
#include <filesystem> // for path
#include <iostream> // for basic_ostream, cout, basic_ios, ios, endl
#include <string> // for basic_string, string, char_traits, allocator
#include <unordered_map> // for unordered_map, operator==, _Node_const_iter...
#include <utility> // for pair
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state, JA_PlayMusic
#include "resource.h" // for Resource
// Calcula el cuadrado de la distancia entre dos puntos
double distanceSquared(int x1, int y1, int x2, int y2)
@@ -154,7 +155,7 @@ bool checkCollision(const SDL_Point &p, const SDL_Rect &r)
}
// Detector de colisiones entre una linea horizontal y un rectangulo
bool checkCollision(const h_line_t &l, const SDL_Rect &r)
bool checkCollision(const LineHorizontal &l, const SDL_Rect &r)
{
// Comprueba si la linea esta por encima del rectangulo
if (l.y < r.y)
@@ -185,7 +186,7 @@ bool checkCollision(const h_line_t &l, const SDL_Rect &r)
}
// Detector de colisiones entre una linea vertical y un rectangulo
bool checkCollision(const v_line_t &l, const SDL_Rect &r)
bool checkCollision(const LineVertical &l, const SDL_Rect &r)
{
// Comprueba si la linea esta por la izquierda del rectangulo
if (l.x < r.x)
@@ -216,7 +217,7 @@ bool checkCollision(const v_line_t &l, const SDL_Rect &r)
}
// Detector de colisiones entre una linea horizontal y un punto
bool checkCollision(const h_line_t &l, const SDL_Point &p)
bool checkCollision(const LineHorizontal &l, const SDL_Point &p)
{
// Comprueba si el punto esta sobre la linea
if (p.y > l.y)
@@ -247,7 +248,7 @@ bool checkCollision(const h_line_t &l, const SDL_Point &p)
}
// Detector de colisiones entre dos lineas
SDL_Point checkCollision(const line_t &l1, const line_t &l2)
SDL_Point checkCollision(const Line &l1, const Line &l2)
{
const float x1 = l1.x1;
const float y1 = l1.y1;
@@ -276,7 +277,7 @@ SDL_Point checkCollision(const line_t &l1, const line_t &l2)
}
// Detector de colisiones entre dos lineas
SDL_Point checkCollision(const d_line_t &l1, const v_line_t &l2)
SDL_Point checkCollision(const LineDiagonal &l1, const LineVertical &l2)
{
const float x1 = l1.x1;
const float y1 = l1.y1;
@@ -305,7 +306,7 @@ SDL_Point checkCollision(const d_line_t &l1, const v_line_t &l2)
}
// Normaliza una linea diagonal
void normalizeLine(d_line_t &l)
void normalizeLine(LineDiagonal &l)
{
// Las lineas diagonales van de izquierda a derecha
// x2 mayor que x1
@@ -321,7 +322,7 @@ void normalizeLine(d_line_t &l)
}
// Detector de colisiones entre un punto y una linea diagonal
bool checkCollision(const SDL_Point &p, const d_line_t &l)
bool checkCollision(const SDL_Point &p, const LineDiagonal &l)
{
// Comprueba si el punto está en alineado con la linea
if (abs(p.x - l.x1) != abs(p.y - l.y1))
@@ -467,8 +468,10 @@ bool colorAreEqual(Color color1, Color color2)
// Convierte una cadena a minúsculas
std::string toLower(std::string str)
{
for (char& c : str) {
if (c >= 'A' && c <= 'Z') {
for (char &c : str)
{
if (c >= 'A' && c <= 'Z')
{
c += 32; // Convierte a minúscula
}
}
@@ -478,8 +481,10 @@ std::string toLower(std::string str)
// Convierte una cadena a mayúsculas
std::string toUpper(std::string str)
{
for (char& c : str) {
if (c >= 'a' && c <= 'z') {
for (char &c : str)
{
if (c >= 'a' && c <= 'z')
{
c -= 32; // Convierte a mayúscula
}
}
@@ -521,18 +526,18 @@ bool stringInVector(const std::vector<std::string> &vec, const std::string &str)
// Hace sonar la música
void playMusic(const std::string &music_path)
{
// Si la música no está sonando
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
{
JA_PlayMusic(Resource::get()->getMusic(music_path));
}
// Si la música no está sonando
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED)
{
JA_PlayMusic(Resource::get()->getMusic(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)
{
// Guardar el render target actual
SDL_Texture* previous_target = SDL_GetRenderTarget(renderer);
SDL_Texture *previous_target = SDL_GetRenderTarget(renderer);
// Establecer la textura como el render target
SDL_SetRenderTarget(renderer, texture);