forked from jaildesigner-jailgames/jaildoctors_dilemma
creada carpeta source2
This commit is contained in:
171
source2/Utils/utils.h
Normal file
171
source2/Utils/utils.h
Normal file
@@ -0,0 +1,171 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
enum class PaletteColor : Uint8 {
|
||||
BLACK = 0,
|
||||
BRIGHT_BLACK = 1,
|
||||
|
||||
BLUE = 2,
|
||||
BRIGHT_BLUE = 3,
|
||||
|
||||
RED = 4,
|
||||
BRIGHT_RED = 5,
|
||||
|
||||
MAGENTA = 6,
|
||||
BRIGHT_MAGENTA = 7,
|
||||
|
||||
GREEN = 8,
|
||||
BRIGHT_GREEN = 9,
|
||||
|
||||
CYAN = 10,
|
||||
BRIGHT_CYAN = 11,
|
||||
|
||||
YELLOW = 12,
|
||||
BRIGHT_YELLOW = 13,
|
||||
|
||||
WHITE = 14,
|
||||
BRIGHT_WHITE = 15,
|
||||
|
||||
TRANSPARENT = 255,
|
||||
};
|
||||
|
||||
// Estructura para definir un circulo
|
||||
struct Circle {
|
||||
int x;
|
||||
int y;
|
||||
int r;
|
||||
};
|
||||
|
||||
// Estructura para definir una linea horizontal
|
||||
struct LineHorizontal {
|
||||
int x1, x2, y;
|
||||
};
|
||||
|
||||
// Estructura para definir una linea vertical
|
||||
struct LineVertical {
|
||||
int x, y1, y2;
|
||||
};
|
||||
|
||||
// Estructura para definir una linea diagonal
|
||||
struct LineDiagonal {
|
||||
int x1, y1, x2, y2;
|
||||
};
|
||||
|
||||
// Estructura para definir una linea
|
||||
struct Line {
|
||||
int x1, y1, x2, y2;
|
||||
};
|
||||
|
||||
// Estructura para definir un color
|
||||
struct Color {
|
||||
Uint8 r;
|
||||
Uint8 g;
|
||||
Uint8 b;
|
||||
|
||||
// Constructor por defecto
|
||||
Color()
|
||||
: r(0),
|
||||
g(0),
|
||||
b(0) {}
|
||||
|
||||
// Constructor
|
||||
Color(Uint8 red, Uint8 green, Uint8 blue)
|
||||
: r(red),
|
||||
g(green),
|
||||
b(blue) {}
|
||||
};
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
double distanceSquared(int x1, int y1, int x2, int y2);
|
||||
|
||||
// Detector de colisiones entre dos circulos
|
||||
bool checkCollision(const Circle& a, const Circle& b);
|
||||
|
||||
// Detector de colisiones entre un circulo y un rectangulo
|
||||
bool checkCollision(const Circle& a, const SDL_FRect& b);
|
||||
|
||||
// Detector de colisiones entre un dos rectangulos
|
||||
bool checkCollision(const SDL_FRect& a, const SDL_FRect& b);
|
||||
|
||||
// Detector de colisiones entre un punto y un rectangulo
|
||||
bool checkCollision(const SDL_FPoint& p, const SDL_FRect& r);
|
||||
|
||||
// Detector de colisiones entre una linea horizontal y un rectangulo
|
||||
bool checkCollision(const LineHorizontal& l, const SDL_FRect& r);
|
||||
|
||||
// Detector de colisiones entre una linea vertical y un rectangulo
|
||||
bool checkCollision(const LineVertical& l, const SDL_FRect& r);
|
||||
|
||||
// Detector de colisiones entre una linea horizontal y un punto
|
||||
bool checkCollision(const LineHorizontal& l, const SDL_FPoint& p);
|
||||
|
||||
// Detector de colisiones entre dos lineas
|
||||
SDL_Point checkCollision(const Line& l1, const Line& l2);
|
||||
|
||||
// Detector de colisiones entre dos lineas
|
||||
SDL_Point checkCollision(const LineDiagonal& l1, const LineVertical& l2);
|
||||
|
||||
// Detector de colisiones entre un punto y una linea diagonal
|
||||
bool checkCollision(const SDL_FPoint& p, const LineDiagonal& l);
|
||||
|
||||
// Normaliza una linea diagonal
|
||||
void normalizeLine(LineDiagonal& l);
|
||||
|
||||
// Devuelve un Color a partir de un string
|
||||
Uint8 stringToColor(const std::string& str);
|
||||
|
||||
// Convierte una cadena a un entero de forma segura
|
||||
int safeStoi(const std::string& value, int defaultValue = 0);
|
||||
|
||||
// Convierte una cadena a un booleano
|
||||
bool stringToBool(const std::string& str);
|
||||
|
||||
// Convierte un booleano a una cadena
|
||||
std::string boolToString(bool value);
|
||||
|
||||
// Compara dos colores
|
||||
bool colorAreEqual(Color color1, Color color2);
|
||||
|
||||
// Convierte una cadena a minusculas
|
||||
std::string toLower(const std::string& str);
|
||||
|
||||
// Convierte una cadena a mayúsculas
|
||||
std::string toUpper(const std::string& str);
|
||||
|
||||
// Obtiene el nombre de un fichero a partir de una ruta
|
||||
std::string getFileName(const std::string& path);
|
||||
|
||||
// Obtiene la ruta eliminando el nombre del fichero
|
||||
std::string getPath(const std::string& full_path);
|
||||
|
||||
// Imprime por pantalla una linea de texto de tamaño fijo rellena con puntos
|
||||
void printWithDots(const std::string& text1, const std::string& text2, const std::string& text3);
|
||||
|
||||
// Comprueba si una vector contiene una cadena
|
||||
bool stringInVector(const std::vector<std::string>& vec, const std::string& str);
|
||||
|
||||
// Hace sonar la música
|
||||
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);
|
||||
|
||||
inline SDL_Rect toSDLRect(const SDL_FRect& frect) {
|
||||
SDL_Rect rect;
|
||||
rect.x = static_cast<int>(frect.x);
|
||||
rect.y = static_cast<int>(frect.y);
|
||||
rect.w = static_cast<int>(frect.w);
|
||||
rect.h = static_cast<int>(frect.h);
|
||||
return rect;
|
||||
}
|
||||
|
||||
inline SDL_Point toSDLPoint(const SDL_FPoint& fpoint) {
|
||||
SDL_Point point;
|
||||
point.x = static_cast<int>(fpoint.x);
|
||||
point.y = static_cast<int>(fpoint.y);
|
||||
return point;
|
||||
}
|
||||
Reference in New Issue
Block a user