forked from jaildesigner-jailgames/jaildoctors_dilemma
Redistribuits els .cpp en carpetes
Actualitzat cmake Modificats els include de SDL2 a SDL3
This commit is contained in:
111
source/utils.h
111
source/utils.h
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include <SDL3/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||
#include <SDL3/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||
#include <SDL3/SDL_stdinc.h> // Para Uint8
|
||||
|
||||
enum class PaletteColor : Uint8
|
||||
{
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
enum class PaletteColor : Uint8 {
|
||||
BLACK = 0,
|
||||
BRIGHT_BLACK = 1,
|
||||
|
||||
@@ -36,96 +36,95 @@ enum class PaletteColor : Uint8
|
||||
};
|
||||
|
||||
// Estructura para definir un circulo
|
||||
struct Circle
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int r;
|
||||
struct Circle {
|
||||
int x;
|
||||
int y;
|
||||
int r;
|
||||
};
|
||||
|
||||
// Estructura para definir una linea horizontal
|
||||
struct LineHorizontal
|
||||
{
|
||||
int x1, x2, y;
|
||||
struct LineHorizontal {
|
||||
int x1, x2, y;
|
||||
};
|
||||
|
||||
// Estructura para definir una linea vertical
|
||||
struct LineVertical
|
||||
{
|
||||
int x, y1, y2;
|
||||
struct LineVertical {
|
||||
int x, y1, y2;
|
||||
};
|
||||
|
||||
// Estructura para definir una linea diagonal
|
||||
struct LineDiagonal
|
||||
{
|
||||
int x1, y1, x2, y2;
|
||||
struct LineDiagonal {
|
||||
int x1, y1, x2, y2;
|
||||
};
|
||||
|
||||
// Estructura para definir una linea
|
||||
struct Line
|
||||
{
|
||||
int x1, y1, x2, y2;
|
||||
struct Line {
|
||||
int x1, y1, x2, y2;
|
||||
};
|
||||
|
||||
// Estructura para definir un color
|
||||
struct Color
|
||||
{
|
||||
Uint8 r;
|
||||
Uint8 g;
|
||||
Uint8 b;
|
||||
struct Color {
|
||||
Uint8 r;
|
||||
Uint8 g;
|
||||
Uint8 b;
|
||||
|
||||
// Constructor por defecto
|
||||
Color() : r(0), g(0), b(0) {}
|
||||
// Constructor por defecto
|
||||
Color()
|
||||
: r(0),
|
||||
g(0),
|
||||
b(0) {}
|
||||
|
||||
// Constructor
|
||||
Color(Uint8 red, Uint8 green, Uint8 blue)
|
||||
: r(red), g(green), b(blue) {}
|
||||
// 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);
|
||||
bool checkCollision(const Circle& a, const Circle& b);
|
||||
|
||||
// Detector de colisiones entre un circulo y un rectangulo
|
||||
bool checkCollision(const Circle &a, const SDL_Rect &b);
|
||||
bool checkCollision(const Circle& a, const SDL_Rect& b);
|
||||
|
||||
// Detector de colisiones entre un dos rectangulos
|
||||
bool checkCollision(const SDL_Rect &a, const SDL_Rect &b);
|
||||
bool checkCollision(const SDL_Rect& a, const SDL_Rect& b);
|
||||
|
||||
// Detector de colisiones entre un punto y un rectangulo
|
||||
bool checkCollision(const SDL_Point &p, const 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(const LineHorizontal &l, const SDL_Rect &r);
|
||||
bool checkCollision(const LineHorizontal& l, const SDL_Rect& r);
|
||||
|
||||
// Detector de colisiones entre una linea vertical y un rectangulo
|
||||
bool checkCollision(const LineVertical &l, const SDL_Rect &r);
|
||||
bool checkCollision(const LineVertical& l, const SDL_Rect& r);
|
||||
|
||||
// Detector de colisiones entre una linea horizontal y un punto
|
||||
bool checkCollision(const LineHorizontal &l, const SDL_Point &p);
|
||||
bool checkCollision(const LineHorizontal& l, const SDL_Point& p);
|
||||
|
||||
// Detector de colisiones entre dos lineas
|
||||
SDL_Point checkCollision(const Line &l1, const Line &l2);
|
||||
SDL_Point checkCollision(const Line& l1, const Line& l2);
|
||||
|
||||
// Detector de colisiones entre dos lineas
|
||||
SDL_Point checkCollision(const LineDiagonal &l1, const LineVertical &l2);
|
||||
SDL_Point checkCollision(const LineDiagonal& l1, const LineVertical& l2);
|
||||
|
||||
// Detector de colisiones entre un punto y una linea diagonal
|
||||
bool checkCollision(const SDL_Point &p, const LineDiagonal &l);
|
||||
bool checkCollision(const SDL_Point& p, const LineDiagonal& l);
|
||||
|
||||
// Normaliza una linea diagonal
|
||||
void normalizeLine(LineDiagonal &l);
|
||||
void normalizeLine(LineDiagonal& l);
|
||||
|
||||
// Devuelve un Color a partir de un string
|
||||
Uint8 stringToColor(const std::string &str);
|
||||
Uint8 stringToColor(const std::string& str);
|
||||
|
||||
// Convierte una cadena a un entero de forma segura
|
||||
int safeStoi(const std::string &value, int defaultValue = 0);
|
||||
int safeStoi(const std::string& value, int defaultValue = 0);
|
||||
|
||||
// Convierte una cadena a un booleano
|
||||
bool stringToBool(const std::string &str);
|
||||
bool stringToBool(const std::string& str);
|
||||
|
||||
// Convierte un booleano a una cadena
|
||||
std::string boolToString(bool value);
|
||||
@@ -134,25 +133,25 @@ std::string boolToString(bool value);
|
||||
bool colorAreEqual(Color color1, Color color2);
|
||||
|
||||
// Convierte una cadena a minusculas
|
||||
std::string toLower(const std::string &str);
|
||||
std::string toLower(const std::string& str);
|
||||
|
||||
// Convierte una cadena a mayúsculas
|
||||
std::string toUpper(const std::string &str);
|
||||
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);
|
||||
std::string getFileName(const std::string& path);
|
||||
|
||||
// Obtiene la ruta eliminando el nombre del fichero
|
||||
std::string getPath(const std::string &full_path);
|
||||
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);
|
||||
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);
|
||||
bool stringInVector(const std::vector<std::string>& vec, const std::string& str);
|
||||
|
||||
// Hace sonar la música
|
||||
void playMusic(const std::string &music_path);
|
||||
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