forked from jaildesigner-jailgames/jaildoctors_dilemma
Ara es poden carregar paletes desde fitxers .pal Reajustada la pleta general fix: la pantalla de càrrega deixava un pixel per pintar, desde sempre Ajustat el color del borde en el Logo i el Title per a ser igual al fondo amb les paletes de 16 colors (la del Spectrum es de 15)
159 lines
3.9 KiB
C++
159 lines
3.9 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
|
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
|
#include <string> // for string
|
|
#include <vector> // for 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_Rect &b);
|
|
|
|
// Detector de colisiones entre un dos rectangulos
|
|
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);
|
|
|
|
// Detector de colisiones entre una linea horizontal y un rectangulo
|
|
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);
|
|
|
|
// Detector de colisiones entre una linea horizontal y un punto
|
|
bool checkCollision(const LineHorizontal &l, const SDL_Point &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_Point &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); |