esqueleto nivel 1
This commit is contained in:
119
source/utils/utils.hpp
Normal file
119
source/utils/utils.hpp
Normal file
@@ -0,0 +1,119 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdint> // Para uint8_t
|
||||
#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{0};
|
||||
int y{0};
|
||||
int r{0};
|
||||
};
|
||||
|
||||
// Estructura para definir una linea horizontal
|
||||
struct LineHorizontal {
|
||||
int x1{0}, x2{0}, y{0};
|
||||
};
|
||||
|
||||
// Estructura para definir una linea vertical
|
||||
struct LineVertical {
|
||||
int x{0}, y1{0}, y2{0};
|
||||
};
|
||||
|
||||
// Estructura para definir una linea diagonal
|
||||
struct LineDiagonal {
|
||||
int x1{0}, y1{0}, x2{0}, y2{0};
|
||||
};
|
||||
|
||||
// Estructura para definir una linea
|
||||
struct Line {
|
||||
int x1{0}, y1{0}, x2{0}, y2{0};
|
||||
};
|
||||
|
||||
// Estructura para definir un color
|
||||
struct Color {
|
||||
Uint8 r{0};
|
||||
Uint8 g{0};
|
||||
Uint8 b{0};
|
||||
|
||||
// Constructor
|
||||
Color(Uint8 red, Uint8 green, Uint8 blue)
|
||||
: r(red),
|
||||
g(green),
|
||||
b(blue) {}
|
||||
};
|
||||
|
||||
// COLISIONES Y GEOMETRÍA
|
||||
auto distanceSquared(int x1, int y1, int x2, int y2) -> double; // Distancia² entre dos puntos
|
||||
auto checkCollision(const Circle& a, const Circle& b) -> bool; // Colisión círculo-círculo
|
||||
auto checkCollision(const Circle& a, const SDL_FRect& rect) -> bool; // Colisión círculo-rectángulo
|
||||
auto checkCollision(const SDL_FRect& a, const SDL_FRect& b) -> bool; // Colisión rectángulo-rectángulo
|
||||
auto checkCollision(const SDL_FPoint& p, const SDL_FRect& r) -> bool; // Colisión punto-rectángulo
|
||||
auto checkCollision(const LineHorizontal& l, const SDL_FRect& r) -> bool; // Colisión línea horizontal-rectángulo
|
||||
auto checkCollision(const LineVertical& l, const SDL_FRect& r) -> bool; // Colisión línea vertical-rectángulo
|
||||
auto checkCollision(const LineHorizontal& l, const SDL_FPoint& p) -> bool; // Colisión línea horizontal-punto
|
||||
auto checkCollision(const Line& l1, const Line& l2) -> SDL_Point; // Colisión línea-línea (intersección)
|
||||
auto checkCollision(const LineDiagonal& l1, const LineVertical& l2) -> SDL_Point; // Colisión diagonal-vertical
|
||||
auto checkCollision(const SDL_FPoint& p, const LineDiagonal& l) -> bool; // Colisión punto-diagonal
|
||||
void normalizeLine(LineDiagonal& l); // Normaliza línea diagonal (x1 < x2)
|
||||
|
||||
// CONVERSIONES DE TIPOS SDL
|
||||
auto toSDLRect(const SDL_FRect& frect) -> SDL_Rect; // Convierte SDL_FRect a SDL_Rect
|
||||
auto toSDLPoint(const SDL_FPoint& fpoint) -> SDL_Point; // Convierte SDL_FPoint a SDL_Point
|
||||
|
||||
// CONVERSIONES DE STRING
|
||||
auto stringToColor(const std::string& str) -> Uint8; // String a índice de paleta
|
||||
auto safeStoi(const std::string& value, int default_value = 0) -> int; // String a int seguro (sin excepciones)
|
||||
auto stringToBool(const std::string& str) -> bool; // String a bool (true/1/yes/on)
|
||||
auto boolToString(bool value) -> std::string; // Bool a string (1/0)
|
||||
auto toLower(const std::string& str) -> std::string; // String a minúsculas
|
||||
auto toUpper(const std::string& str) -> std::string; // String a mayúsculas
|
||||
|
||||
// OPERACIONES CON STRINGS
|
||||
auto stringInVector(const std::vector<std::string>& vec, const std::string& str) -> bool; // Busca string en vector
|
||||
auto spaceBetweenLetters(const std::string& input) -> std::string; // Añade espacios entre letras
|
||||
|
||||
// OPERACIONES CON COLORES
|
||||
auto colorAreEqual(Color color1, Color color2) -> bool; // Compara dos colores RGB
|
||||
|
||||
// OPERACIONES CON FICHEROS
|
||||
auto loadFileBytes(const std::string& path) -> std::vector<uint8_t>; // Carga un fichero como bytes
|
||||
auto getFileName(const std::string& path) -> std::string; // Extrae nombre de fichero de ruta
|
||||
auto getPath(const std::string& full_path) -> std::string; // Extrae directorio de ruta completa
|
||||
|
||||
// RENDERIZADO
|
||||
void fillTextureWithColor(SDL_Renderer* renderer, SDL_Texture* texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a); // Rellena textura
|
||||
|
||||
// OUTPUT Y UTILIDADES DE CONSOLA
|
||||
void printWithDots(const std::string& text1, const std::string& text2, const std::string& text3); // Imprime línea con puntos
|
||||
Reference in New Issue
Block a user