revisió de capçaleres
This commit is contained in:
156
source/utils.h
156
source/utils.h
@@ -8,33 +8,27 @@
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
// Constantes
|
||||
// --- Constantes ---
|
||||
constexpr int BLOCK = 8;
|
||||
constexpr int TOTAL_DEMO_DATA = 2000;
|
||||
|
||||
// Variables para que los argumentos del programa tengan mas peso que los definidos en otros lugares
|
||||
// --- Estructuras y tipos ---
|
||||
struct Overrides
|
||||
{
|
||||
std::string param_file; // Fichero de parametros a utilizar
|
||||
bool clear_hi_score_table; // Reinicia la tabla de records
|
||||
bool set_v_sync; // Establece el vsync
|
||||
|
||||
// Constructor por defecto
|
||||
Overrides()
|
||||
: param_file(""), clear_hi_score_table(false), set_v_sync(false) {}
|
||||
};
|
||||
|
||||
extern Overrides overrides;
|
||||
|
||||
// Estructura para definir un circulo
|
||||
struct Circle
|
||||
{
|
||||
int x, y, r;
|
||||
|
||||
// Constructor por defecto
|
||||
Circle() : x(0), y(0), r(0) {}
|
||||
|
||||
// Constructor
|
||||
Circle(int xCoord, int yCoord, int radius)
|
||||
: x(xCoord), y(yCoord), r(radius) {}
|
||||
};
|
||||
@@ -46,13 +40,7 @@ struct Color
|
||||
constexpr Color() : r(0), g(0), b(0) {}
|
||||
explicit constexpr Color(int red, int green, int blue) : r(red), g(green), b(blue) {}
|
||||
|
||||
// Método para obtener el color inverso
|
||||
constexpr Color getInverse() const
|
||||
{
|
||||
return Color(255 - r, 255 - g, 255 - b);
|
||||
}
|
||||
|
||||
// Método para aclarar el color
|
||||
constexpr Color getInverse() const { return Color(255 - r, 255 - g, 255 - b); }
|
||||
Color lighten(int amount = 50) const
|
||||
{
|
||||
return Color(
|
||||
@@ -60,8 +48,6 @@ struct Color
|
||||
std::min(255, g + amount),
|
||||
std::min(255, b + amount));
|
||||
}
|
||||
|
||||
// Método para oscurecer el color
|
||||
Color darken(int amount = 50) const
|
||||
{
|
||||
return Color(
|
||||
@@ -81,6 +67,7 @@ enum class NotifyPosition
|
||||
RIGHT,
|
||||
};
|
||||
|
||||
// Estructura para datos de la demo
|
||||
struct DemoKeys
|
||||
{
|
||||
Uint8 left;
|
||||
@@ -90,7 +77,6 @@ struct DemoKeys
|
||||
Uint8 fire_left;
|
||||
Uint8 fire_right;
|
||||
|
||||
// Constructor que inicializa todos los campos
|
||||
explicit DemoKeys(Uint8 l = 0, Uint8 r = 0, Uint8 ni = 0, Uint8 f = 0, Uint8 fl = 0, Uint8 fr = 0)
|
||||
: left(l), right(r), no_input(ni), fire(f), fire_left(fl), fire_right(fr) {}
|
||||
};
|
||||
@@ -105,10 +91,7 @@ struct Demo
|
||||
DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo
|
||||
std::vector<DemoData> data; // Vector con diferentes sets de datos con los movimientos para la demo
|
||||
|
||||
// Constructor por defecto
|
||||
Demo() : enabled(false), recording(false), counter(0), keys(), data() {}
|
||||
|
||||
// Constructor con parámetros
|
||||
Demo(bool e, bool r, int c, const DemoKeys &k, const std::vector<DemoData> &d)
|
||||
: enabled(e), recording(r), counter(c), keys(k), data(d) {}
|
||||
};
|
||||
@@ -122,83 +105,10 @@ struct Zone
|
||||
float third_quarter_x; // Anclaje al 75% del eje X
|
||||
float center_y; // Anclaje al 50% del eje Y
|
||||
float first_quarter_y; // Anclaje al 25% del eje Y
|
||||
float third_quarter_y; // Anclaje al 75% del eje X
|
||||
float third_quarter_y; // Anclaje al 75% del eje Y
|
||||
};
|
||||
|
||||
// Obtiene un color del vector de colores imitando al Coche Fantástico
|
||||
Color getColorLikeKnightRider(const std::vector<Color> &colors, int counter_);
|
||||
|
||||
// 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);
|
||||
|
||||
// Convierte una cadena en un valor booleano
|
||||
bool stringToBool(const std::string &str);
|
||||
|
||||
// Convierte un valor booleano en una cadena
|
||||
std::string boolToString(bool value);
|
||||
|
||||
// Convierte un valor booleano en una cadena "on" o "off"
|
||||
std::string boolToOnOff(bool value);
|
||||
|
||||
// Convierte una cadena a minusculas
|
||||
std::string toLower(const std::string &str);
|
||||
|
||||
// Dibuja un circulo
|
||||
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius);
|
||||
|
||||
// Aclara el color
|
||||
Color lightenColor(const Color &color, int amount);
|
||||
|
||||
// Oscurece el color
|
||||
Color DarkenColor(const Color &color, int amount);
|
||||
|
||||
// Quita los espacioes en un string
|
||||
std::string trim(const std::string &str);
|
||||
|
||||
// Función de suavizado
|
||||
double easeOutQuint(double t);
|
||||
double easeInQuint(double t);
|
||||
double easeInOutQuint(double t);
|
||||
double easeInQuad(double t);
|
||||
double easeOutQuad(double t);
|
||||
double easeInOutSine(double t);
|
||||
double easeInOut(double t);
|
||||
double easeInOutExpo(double t);
|
||||
double easeOutBounce(double t);
|
||||
double easeOutElastic(double t);
|
||||
double easeInElastic(double t);
|
||||
|
||||
// Comprueba si una vector contiene una cadena
|
||||
bool stringInVector(const std::vector<std::string> &vec, const std::string &str);
|
||||
|
||||
// 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);
|
||||
|
||||
// Carga el fichero de datos para la demo
|
||||
DemoData loadDemoDataFromFile(const std::string &file_path);
|
||||
|
||||
#ifdef RECORDING
|
||||
// Guarda el fichero de datos para la demo
|
||||
bool saveDemoFile(const std::string &file_path, const DemoData &dd);
|
||||
#endif
|
||||
|
||||
// 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);
|
||||
// --- Funciones utilitarias ---
|
||||
|
||||
// Colores
|
||||
extern const Color BG_COLOR;
|
||||
@@ -215,4 +125,56 @@ extern const Color ORANGE_SOFT_COLOR;
|
||||
extern const Color GREEN_COLOR;
|
||||
extern const Color BLUE_SKY_COLOR;
|
||||
extern const Color PINK_SKY_COLOR;
|
||||
extern const Color GREEN_SKY_COLOR;
|
||||
extern const Color GREEN_SKY_COLOR;
|
||||
|
||||
// Colores y gráficos
|
||||
Color getColorLikeKnightRider(const std::vector<Color> &colors, int counter_);
|
||||
|
||||
// Colisiones y geometría
|
||||
double distanceSquared(int x1, int y1, int x2, int y2);
|
||||
bool checkCollision(const Circle &a, const Circle &b);
|
||||
bool checkCollision(const Circle &a, const SDL_FRect &b);
|
||||
bool checkCollision(const SDL_FRect &a, const SDL_FRect &b);
|
||||
bool checkCollision(const SDL_FPoint &p, const SDL_FRect &r);
|
||||
|
||||
// Conversión y manipulación de cadenas
|
||||
bool stringToBool(const std::string &str);
|
||||
std::string boolToString(bool value);
|
||||
std::string boolToOnOff(bool value);
|
||||
std::string toLower(const std::string &str);
|
||||
std::string trim(const std::string &str);
|
||||
|
||||
// Dibujo
|
||||
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius);
|
||||
|
||||
// Manipulación de color
|
||||
Color lightenColor(const Color &color, int amount);
|
||||
Color DarkenColor(const Color &color, int amount);
|
||||
|
||||
// Funciones de suavizado (easing)
|
||||
double easeOutQuint(double t);
|
||||
double easeInQuint(double t);
|
||||
double easeInOutQuint(double t);
|
||||
double easeInQuad(double t);
|
||||
double easeOutQuad(double t);
|
||||
double easeInOutSine(double t);
|
||||
double easeInOut(double t);
|
||||
double easeInOutExpo(double t);
|
||||
double easeOutBounce(double t);
|
||||
double easeOutElastic(double t);
|
||||
double easeInElastic(double t);
|
||||
|
||||
// Utilidades varias
|
||||
bool stringInVector(const std::vector<std::string> &vec, const std::string &str); // Comprueba si un vector contiene una cadena
|
||||
void printWithDots(const std::string &text1, const std::string &text2, const std::string &text3); // Imprime una línea con puntos
|
||||
|
||||
// Demo
|
||||
DemoData loadDemoDataFromFile(const std::string &file_path);
|
||||
|
||||
#ifdef RECORDING
|
||||
bool saveDemoFile(const std::string &file_path, const DemoData &dd);
|
||||
#endif
|
||||
|
||||
// Ficheros y rutas
|
||||
std::string getFileName(const std::string &path); // Obtiene el nombre de un fichero a partir de una ruta
|
||||
std::string getPath(const std::string &full_path); // Obtiene la ruta eliminando el nombre del fichero
|
||||
Reference in New Issue
Block a user