reestructurat utils

This commit is contained in:
2025-11-12 14:02:17 +01:00
parent 9cf45062a3
commit 477ab34057
3 changed files with 64 additions and 111 deletions

View File

@@ -282,6 +282,24 @@ void normalizeLine(LineDiagonal& l) {
}
}
// Convierte SDL_FRect a SDL_Rect
auto toSDLRect(const SDL_FRect& frect) -> SDL_Rect {
SDL_Rect rect = {
.x = static_cast<int>(frect.x),
.y = static_cast<int>(frect.y),
.w = static_cast<int>(frect.w),
.h = static_cast<int>(frect.h)};
return rect;
}
// Convierte SDL_FPoint a SDL_Point
auto toSDLPoint(const SDL_FPoint& fpoint) -> SDL_Point {
SDL_Point point = {
.x = static_cast<int>(fpoint.x),
.y = static_cast<int>(fpoint.y)};
return point;
}
// Detector de colisiones entre un punto y una linea diagonal
auto checkCollision(const SDL_FPoint& point, const LineDiagonal& l) -> bool {
SDL_Point p = toSDLPoint(point);
@@ -425,14 +443,6 @@ auto stringInVector(const std::vector<std::string>& vec, const std::string& str)
return std::ranges::find(vec, str) != vec.end();
}
// Hace sonar la música
void playMusic(const std::string& music_path) {
// Si la música no está sonando
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED) {
JA_PlayMusic(Resource::Cache::get()->getMusic(music_path));
}
}
// Rellena una textura de un color
void fillTextureWithColor(SDL_Renderer* renderer, SDL_Texture* texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
// Guardar el render target actual