Cambiados muchos DEFINEs por variables de param

This commit is contained in:
2024-09-06 08:41:10 +02:00
parent c5bab7019c
commit 62b1ba84ac
23 changed files with 215 additions and 158 deletions

View File

@@ -8,19 +8,6 @@ Background::Background(SDL_Renderer *renderer, Asset *asset, param_t *param)
this->asset = asset;
this->param = param;
// Inicializa variables
gradientNumber = 0;
alpha = 0;
cloudsSpeed = 0;
transition = 0;
counter = 0;
rect = {0, 0, param->game.width, param->game.height};
srcRect = {playArea.x, rect.h - playArea.h, playArea.w, playArea.h};
dstRect = {0, 0, playArea.w, playArea.h};
base = rect.h;
color = {param->background.attenuateColor.r, param->background.attenuateColor.g, param->background.attenuateColor.b};
alphaColorText = alphaColorTextTemp = param->background.attenuateAlpha;
// Carga las texturas
buildingsTexture = new Texture(renderer, asset->get("game_buildings.png"));
topCloudsTexture = new Texture(renderer, asset->get("game_clouds1.png"));
@@ -28,6 +15,21 @@ Background::Background(SDL_Renderer *renderer, Asset *asset, param_t *param)
grassTexture = new Texture(renderer, asset->get("game_grass.png"));
gradientsTexture = new Texture(renderer, asset->get("game_sky_colors.png"));
// Inicializa variables
gradientNumber = 0;
alpha = 0;
cloudsSpeed = 0;
transition = 0;
counter = 0;
rect = {0, 0, gradientsTexture->getWidth() / 2, gradientsTexture->getHeight() / 2};
srcRect = {0, 0, 320, 240};
dstRect = {0, 0, 320, 240};
base = rect.h;
color = {param->background.attenuateColor.r, param->background.attenuateColor.g, param->background.attenuateColor.b};
alphaColorText = alphaColorTextTemp = param->background.attenuateAlpha;
gradientRect[0] = {0, 0, rect.w, rect.h};
gradientRect[1] = {rect.w, 0, rect.w, rect.h};
gradientRect[2] = {0, rect.h, rect.w, rect.h};
@@ -42,15 +44,15 @@ Background::Background(SDL_Renderer *renderer, Asset *asset, param_t *param)
}
// Crea los sprites
const int clouds1y = base - 165;
const int clouds2y = base - 101;
const float clouds1speed = 0.1f;
const float clouds2speed = 0.05f;
topCloudsSprite_A = new MovingSprite(0, clouds1y, rect.w, topCloudsTexture->getHeight(), -clouds1speed, 0.0f, 0.0f, 0.0f, topCloudsTexture);
topCloudsSprite_B = new MovingSprite(rect.w, clouds1y, rect.w, topCloudsTexture->getHeight(), -clouds1speed, 0.0f, 0.0f, 0.0f, topCloudsTexture);
const int topClouds_y = base - 165;
const int bottomClouds_y = base - 101;
const float topCloudsSpeed = 0.1f;
const float bottomCloudsSpeed = 0.05f;
topCloudsSprite_A = new MovingSprite(0, topClouds_y, rect.w, topCloudsTexture->getHeight(), -topCloudsSpeed, 0.0f, 0.0f, 0.0f, topCloudsTexture);
topCloudsSprite_B = new MovingSprite(rect.w, topClouds_y, rect.w, topCloudsTexture->getHeight(), -topCloudsSpeed, 0.0f, 0.0f, 0.0f, topCloudsTexture);
bottomCloudsSprite_A = new MovingSprite(0, clouds2y, rect.w, bottomCloudsTexture->getHeight(), -clouds2speed, 0.0f, 0.0f, 0.0f, bottomCloudsTexture);
bottomCloudsSprite_B = new MovingSprite(rect.w, clouds2y, rect.w, bottomCloudsTexture->getHeight(), -clouds2speed, 0.0f, 0.0f, 0.0f, bottomCloudsTexture);
bottomCloudsSprite_A = new MovingSprite(0, bottomClouds_y, rect.w, bottomCloudsTexture->getHeight(), -bottomCloudsSpeed, 0.0f, 0.0f, 0.0f, bottomCloudsTexture);
bottomCloudsSprite_B = new MovingSprite(rect.w, bottomClouds_y, rect.w, bottomCloudsTexture->getHeight(), -bottomCloudsSpeed, 0.0f, 0.0f, 0.0f, bottomCloudsTexture);
buildingsSprite = new Sprite(0, 0, buildingsTexture->getWidth(), buildingsTexture->getHeight(), buildingsTexture);
gradientSprite = new Sprite(0, 0, rect.w, rect.h, gradientsTexture);
@@ -233,13 +235,15 @@ void Background::setTransition(float value)
}
// Establece la posición del objeto
void Background::setPos(SDL_Rect rect)
void Background::setPos(SDL_Rect pos)
{
dstRect = rect;
this->dstRect = pos;
// Si cambian las medidas del destino, hay que cambiar las del origen para evitar deformar la imagen
srcRect.w = rect.w;
srcRect.h = rect.h;
this->srcRect.x = 0;
this->srcRect.y = rect.h - pos.h;
this->srcRect.w = pos.w;
this->srcRect.h = pos.h;
}
// Ajusta el valor de la variable