Estandaritzant noms segons convencions
This commit is contained in:
@@ -1,108 +1,108 @@
|
||||
#include "background.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <algorithm> // for max, min
|
||||
#include <string> // for basic_string
|
||||
#include "asset.h" // for Asset
|
||||
#include "param.h" // for param
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <algorithm> // for max, min
|
||||
#include <string> // for basic_string
|
||||
#include "asset.h" // for Asset
|
||||
#include "param.h" // for param
|
||||
|
||||
// Constructor
|
||||
Background::Background(SDL_Renderer *renderer)
|
||||
: renderer(renderer)
|
||||
: renderer_(renderer)
|
||||
{
|
||||
// Carga las texturas
|
||||
buildingsTexture = std::make_shared<Texture>(renderer, Asset::get()->get("game_buildings.png"));
|
||||
topCloudsTexture = std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds1.png"));
|
||||
bottomCloudsTexture = std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds2.png"));
|
||||
grassTexture = std::make_shared<Texture>(renderer, Asset::get()->get("game_grass.png"));
|
||||
gradientsTexture = std::make_shared<Texture>(renderer, Asset::get()->get("game_sky_colors.png"));
|
||||
buildings_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("game_buildings.png"));
|
||||
top_clouds_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds1.png"));
|
||||
bottom_clouds_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("game_clouds2.png"));
|
||||
grass_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("game_grass.png"));
|
||||
gradients_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("game_sky_colors.png"));
|
||||
|
||||
// Inicializa variables
|
||||
gradientNumber = 0;
|
||||
alpha = 0;
|
||||
cloudsSpeed = 0;
|
||||
transition = 0;
|
||||
counter = 0;
|
||||
gradient_number_ = 0;
|
||||
alpha_ = 0;
|
||||
clouds_speed_ = 0;
|
||||
transition_ = 0;
|
||||
counter_ = 0;
|
||||
|
||||
rect = {0, 0, gradientsTexture->getWidth() / 2, gradientsTexture->getHeight() / 2};
|
||||
srcRect = {0, 0, 320, 240};
|
||||
dstRect = {0, 0, 320, 240};
|
||||
rect_ = {0, 0, gradients_texture_->getWidth() / 2, gradients_texture_->getHeight() / 2};
|
||||
src_rect_ = {0, 0, 320, 240};
|
||||
dst_rect_ = {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;
|
||||
base_ = rect_.h;
|
||||
color_ = {param.background.attenuateColor.r, param.background.attenuateColor.g, param.background.attenuateColor.b};
|
||||
alpha_color_text_ = alpha_color_text_temp_ = 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};
|
||||
gradientRect[3] = {rect.w, rect.h, rect.w, rect.h};
|
||||
gradient_rect_[0] = {0, 0, rect_.w, rect_.h};
|
||||
gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h};
|
||||
gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h};
|
||||
gradient_rect_[3] = {rect_.w, rect_.h, rect_.w, rect_.h};
|
||||
|
||||
const int topCloudsTextureHeight = topCloudsTexture->getHeight() / 4;
|
||||
const int bottomCloudsTextureHeight = bottomCloudsTexture->getHeight() / 4;
|
||||
const int top_clouds_texture_height = top_clouds_texture_->getHeight() / 4;
|
||||
const int bottom_clouds_texture_height = bottom_clouds_texture_->getHeight() / 4;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
topCloudsRect[i] = {0, i * topCloudsTextureHeight, topCloudsTexture->getWidth(), topCloudsTextureHeight};
|
||||
bottomCloudsRect[i] = {0, i * bottomCloudsTextureHeight, bottomCloudsTexture->getWidth(), bottomCloudsTextureHeight};
|
||||
top_clouds_rect_[i] = {0, i * top_clouds_texture_height, top_clouds_texture_->getWidth(), top_clouds_texture_height};
|
||||
bottom_clouds_rect_[i] = {0, i * bottom_clouds_texture_height, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_height};
|
||||
}
|
||||
|
||||
// Crea los sprites
|
||||
const int topClouds_y = base - 165;
|
||||
const int bottomClouds_y = base - 101;
|
||||
const float topCloudsSpeed = 0.1f;
|
||||
const float bottomCloudsSpeed = 0.05f;
|
||||
topCloudsSprite_A = std::make_unique<MovingSprite>(0, topClouds_y, rect.w, topCloudsTexture->getHeight(), -topCloudsSpeed, 0.0f, 0.0f, 0.0f, topCloudsTexture);
|
||||
topCloudsSprite_B = std::make_unique<MovingSprite>(rect.w, topClouds_y, rect.w, topCloudsTexture->getHeight(), -topCloudsSpeed, 0.0f, 0.0f, 0.0f, topCloudsTexture);
|
||||
const int top_clouds_y = base_ - 165;
|
||||
const int bottom_clouds_y = base_ - 101;
|
||||
constexpr float top_clouds_speed = 0.1f;
|
||||
constexpr float bottom_clouds_speed = 0.05f;
|
||||
top_clouds_sprite_a_ = std::make_unique<MovingSprite>(0, top_clouds_y, rect_.w, top_clouds_texture_->getHeight(), -top_clouds_speed, 0.0f, 0.0f, 0.0f, top_clouds_texture_);
|
||||
top_clouds_sprite_b_ = std::make_unique<MovingSprite>(rect_.w, top_clouds_y, rect_.w, top_clouds_texture_->getHeight(), -top_clouds_speed, 0.0f, 0.0f, 0.0f, top_clouds_texture_);
|
||||
|
||||
bottomCloudsSprite_A = std::make_unique<MovingSprite>(0, bottomClouds_y, rect.w, bottomCloudsTexture->getHeight(), -bottomCloudsSpeed, 0.0f, 0.0f, 0.0f, bottomCloudsTexture);
|
||||
bottomCloudsSprite_B = std::make_unique<MovingSprite>(rect.w, bottomClouds_y, rect.w, bottomCloudsTexture->getHeight(), -bottomCloudsSpeed, 0.0f, 0.0f, 0.0f, bottomCloudsTexture);
|
||||
bottom_clouds_sprite_a_ = std::make_unique<MovingSprite>(0, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight(), -bottom_clouds_speed, 0.0f, 0.0f, 0.0f, bottom_clouds_texture_);
|
||||
bottom_clouds_sprite_b_ = std::make_unique<MovingSprite>(rect_.w, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight(), -bottom_clouds_speed, 0.0f, 0.0f, 0.0f, bottom_clouds_texture_);
|
||||
|
||||
buildingsSprite = std::make_unique<Sprite>(0, 0, buildingsTexture->getWidth(), buildingsTexture->getHeight(), buildingsTexture);
|
||||
gradientSprite = std::make_unique<Sprite>(0, 0, rect.w, rect.h, gradientsTexture);
|
||||
grassSprite = std::make_unique<Sprite>(0, 0, grassTexture->getWidth(), grassTexture->getHeight() / 2, grassTexture);
|
||||
buildings_sprite_ = std::make_unique<Sprite>(0, 0, buildings_texture_->getWidth(), buildings_texture_->getHeight(), buildings_texture_);
|
||||
gradient_sprite_ = std::make_unique<Sprite>(0, 0, rect_.w, rect_.h, gradients_texture_);
|
||||
grass_sprite_ = std::make_unique<Sprite>(0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2, grass_texture_);
|
||||
|
||||
// Inicializa objetos
|
||||
topCloudsSprite_A->setSpriteClip(0, 0, topCloudsTexture->getWidth(), topCloudsTexture->getHeight());
|
||||
topCloudsSprite_B->setSpriteClip(0, 0, topCloudsTexture->getWidth(), topCloudsTexture->getHeight());
|
||||
bottomCloudsSprite_A->setSpriteClip(0, 0, bottomCloudsTexture->getWidth(), bottomCloudsTexture->getHeight());
|
||||
bottomCloudsSprite_B->setSpriteClip(0, 0, bottomCloudsTexture->getWidth(), bottomCloudsTexture->getHeight());
|
||||
buildingsSprite->setPosY(base - buildingsSprite->getHeight());
|
||||
grassSprite->setPosY(base - grassSprite->getHeight());
|
||||
top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||
top_clouds_sprite_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
|
||||
bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
|
||||
buildings_sprite_->setPosY(base_ - buildings_sprite_->getHeight());
|
||||
grass_sprite_->setPosY(base_ - grass_sprite_->getHeight());
|
||||
|
||||
// Crea la textura para componer el fondo
|
||||
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
|
||||
SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND);
|
||||
canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||
SDL_SetTextureBlendMode(canvas_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Crea la textura para atenuar el fondo
|
||||
colorTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
|
||||
SDL_SetTextureBlendMode(colorTexture, SDL_BLENDMODE_BLEND);
|
||||
setColor(color);
|
||||
SDL_SetTextureAlphaMod(colorTexture, alphaColorText);
|
||||
color_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h);
|
||||
SDL_SetTextureBlendMode(color_texture_, SDL_BLENDMODE_BLEND);
|
||||
setColor(color_);
|
||||
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Background::~Background()
|
||||
{
|
||||
SDL_DestroyTexture(canvas);
|
||||
SDL_DestroyTexture(colorTexture);
|
||||
SDL_DestroyTexture(canvas_);
|
||||
SDL_DestroyTexture(color_texture_);
|
||||
}
|
||||
|
||||
// Actualiza la lógica del objeto
|
||||
void Background::update()
|
||||
{
|
||||
// Actualiza el valor de alpha
|
||||
// Actualiza el valor de alpha_
|
||||
updateAlphaColorText();
|
||||
|
||||
// Actualiza las nubes
|
||||
updateClouds();
|
||||
|
||||
// Calcula el frame de la hierba
|
||||
grassSprite->setSpriteClip(0, (10 * (counter / 20 % 2)), 320, 10);
|
||||
grass_sprite_->setSpriteClip(0, (10 * (counter_ / 20 % 2)), 320, 10);
|
||||
|
||||
// Calcula el valor de alpha
|
||||
alpha = std::max((255 - (int)(255 * transition)), 0);
|
||||
// Calcula el valor de alpha_
|
||||
alpha_ = std::max((255 - (int)(255 * transition_)), 0);
|
||||
|
||||
// Incrementa el contador
|
||||
counter++;
|
||||
counter_++;
|
||||
|
||||
fillCanvas();
|
||||
}
|
||||
@@ -111,58 +111,58 @@ void Background::update()
|
||||
void Background::renderGradient()
|
||||
{
|
||||
// Dibuja el gradiente 2
|
||||
gradientsTexture->setAlpha(255);
|
||||
gradientSprite->setSpriteClip(gradientRect[(gradientNumber + 1) % 4]);
|
||||
gradientSprite->render();
|
||||
gradients_texture_->setAlpha(255);
|
||||
gradient_sprite_->setSpriteClip(gradient_rect_[(gradient_number_ + 1) % 4]);
|
||||
gradient_sprite_->render();
|
||||
|
||||
// Dibuja el gradiente 1 con una opacidad cada vez menor
|
||||
gradientsTexture->setAlpha(alpha);
|
||||
gradientSprite->setSpriteClip(gradientRect[gradientNumber]);
|
||||
gradientSprite->render();
|
||||
gradients_texture_->setAlpha(alpha_);
|
||||
gradient_sprite_->setSpriteClip(gradient_rect_[gradient_number_]);
|
||||
gradient_sprite_->render();
|
||||
}
|
||||
|
||||
// Dibuja las nubes de arriba
|
||||
void Background::renderTopClouds()
|
||||
{
|
||||
// Dibuja el primer conjunto de nubes
|
||||
topCloudsTexture->setAlpha(255);
|
||||
topCloudsSprite_A->setSpriteClip(topCloudsRect[(gradientNumber + 1) % 4]);
|
||||
topCloudsSprite_A->render();
|
||||
topCloudsSprite_B->setSpriteClip(topCloudsRect[(gradientNumber + 1) % 4]);
|
||||
topCloudsSprite_B->render();
|
||||
top_clouds_texture_->setAlpha(255);
|
||||
top_clouds_sprite_a_->setSpriteClip(top_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||
top_clouds_sprite_a_->render();
|
||||
top_clouds_sprite_b_->setSpriteClip(top_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||
top_clouds_sprite_b_->render();
|
||||
|
||||
// Dibuja el segundo conjunto de nubes
|
||||
topCloudsTexture->setAlpha(alpha);
|
||||
topCloudsSprite_A->setSpriteClip(topCloudsRect[gradientNumber]);
|
||||
topCloudsSprite_A->render();
|
||||
topCloudsSprite_B->setSpriteClip(topCloudsRect[gradientNumber]);
|
||||
topCloudsSprite_B->render();
|
||||
top_clouds_texture_->setAlpha(alpha_);
|
||||
top_clouds_sprite_a_->setSpriteClip(top_clouds_rect_[gradient_number_]);
|
||||
top_clouds_sprite_a_->render();
|
||||
top_clouds_sprite_b_->setSpriteClip(top_clouds_rect_[gradient_number_]);
|
||||
top_clouds_sprite_b_->render();
|
||||
}
|
||||
|
||||
// Dibuja las nubes de abajo
|
||||
void Background::renderBottomClouds()
|
||||
{
|
||||
// Dibuja el primer conjunto de nubes
|
||||
bottomCloudsTexture->setAlpha(255);
|
||||
bottomCloudsSprite_A->setSpriteClip(bottomCloudsRect[(gradientNumber + 1) % 4]);
|
||||
bottomCloudsSprite_A->render();
|
||||
bottomCloudsSprite_B->setSpriteClip(bottomCloudsRect[(gradientNumber + 1) % 4]);
|
||||
bottomCloudsSprite_B->render();
|
||||
bottom_clouds_texture_->setAlpha(255);
|
||||
bottom_clouds_sprite_a_->setSpriteClip(bottom_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||
bottom_clouds_sprite_a_->render();
|
||||
bottom_clouds_sprite_b_->setSpriteClip(bottom_clouds_rect_[(gradient_number_ + 1) % 4]);
|
||||
bottom_clouds_sprite_b_->render();
|
||||
|
||||
// Dibuja el segundo conjunto de nubes
|
||||
bottomCloudsTexture->setAlpha(alpha);
|
||||
bottomCloudsSprite_A->setSpriteClip(bottomCloudsRect[gradientNumber]);
|
||||
bottomCloudsSprite_A->render();
|
||||
bottomCloudsSprite_B->setSpriteClip(bottomCloudsRect[gradientNumber]);
|
||||
bottomCloudsSprite_B->render();
|
||||
bottom_clouds_texture_->setAlpha(alpha_);
|
||||
bottom_clouds_sprite_a_->setSpriteClip(bottom_clouds_rect_[gradient_number_]);
|
||||
bottom_clouds_sprite_a_->render();
|
||||
bottom_clouds_sprite_b_->setSpriteClip(bottom_clouds_rect_[gradient_number_]);
|
||||
bottom_clouds_sprite_b_->render();
|
||||
}
|
||||
|
||||
// Compone todos los elementos del fondo en la textura
|
||||
void Background::fillCanvas()
|
||||
{
|
||||
// Cambia el destino del renderizador
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, canvas);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, canvas_);
|
||||
|
||||
// Dibuja el gradiente de fondo
|
||||
renderGradient();
|
||||
@@ -174,45 +174,45 @@ void Background::fillCanvas()
|
||||
renderBottomClouds();
|
||||
|
||||
// Dibuja los edificios
|
||||
buildingsSprite->render();
|
||||
buildings_sprite_->render();
|
||||
|
||||
// Dibuja la hierba
|
||||
grassSprite->render();
|
||||
grass_sprite_->render();
|
||||
|
||||
// Deja el renderizador apuntando donde estaba
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
// Dibuja el objeto
|
||||
void Background::render()
|
||||
{
|
||||
// Fondo
|
||||
SDL_RenderCopy(renderer, canvas, &srcRect, &dstRect);
|
||||
SDL_RenderCopy(renderer_, canvas_, &src_rect_, &dst_rect_);
|
||||
|
||||
// Atenuación
|
||||
SDL_RenderCopy(renderer, colorTexture, &srcRect, &dstRect);
|
||||
SDL_RenderCopy(renderer_, color_texture_, &src_rect_, &dst_rect_);
|
||||
}
|
||||
|
||||
// Vuelve a cargar las texturas
|
||||
void Background::reloadTextures()
|
||||
{
|
||||
buildingsTexture->reLoad();
|
||||
topCloudsTexture->reLoad();
|
||||
bottomCloudsTexture->reLoad();
|
||||
grassTexture->reLoad();
|
||||
gradientsTexture->reLoad();
|
||||
buildings_texture_->reLoad();
|
||||
top_clouds_texture_->reLoad();
|
||||
bottom_clouds_texture_->reLoad();
|
||||
grass_texture_->reLoad();
|
||||
gradients_texture_->reLoad();
|
||||
}
|
||||
|
||||
// Ajusta el valor de la variable
|
||||
void Background::setCloudsSpeed(float value)
|
||||
{
|
||||
cloudsSpeed = value;
|
||||
clouds_speed_ = value;
|
||||
}
|
||||
|
||||
// Ajusta el valor de la variable
|
||||
void Background::setGradientNumber(int value)
|
||||
{
|
||||
gradientNumber = value % 4;
|
||||
gradient_number_ = value % 4;
|
||||
}
|
||||
|
||||
// Ajusta el valor de la variable
|
||||
@@ -220,73 +220,73 @@ void Background::setTransition(float value)
|
||||
{
|
||||
value = std::min(value, 1.0f);
|
||||
value = std::max(value, 0.0f);
|
||||
transition = value;
|
||||
transition_ = value;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Background::setPos(SDL_Rect pos)
|
||||
{
|
||||
this->dstRect = pos;
|
||||
dst_rect_ = pos;
|
||||
|
||||
// Si cambian las medidas del destino, hay que cambiar las del origen para evitar deformar la imagen
|
||||
this->srcRect.x = 0;
|
||||
this->srcRect.y = rect.h - pos.h;
|
||||
this->srcRect.w = pos.w;
|
||||
this->srcRect.h = pos.h;
|
||||
src_rect_.x = 0;
|
||||
src_rect_.y = rect_.h - pos.h;
|
||||
src_rect_.w = pos.w;
|
||||
src_rect_.h = pos.h;
|
||||
}
|
||||
|
||||
// Ajusta el valor de la variable
|
||||
void Background::setSrcRect(SDL_Rect value)
|
||||
{
|
||||
srcRect = value;
|
||||
src_rect_ = value;
|
||||
}
|
||||
|
||||
// Ajusta el valor de la variable
|
||||
void Background::setDstRect(SDL_Rect value)
|
||||
{
|
||||
dstRect = value;
|
||||
dst_rect_ = value;
|
||||
}
|
||||
|
||||
// Establece el color de atenuación
|
||||
void Background::setColor(color_t color)
|
||||
// Establece el color_ de atenuación
|
||||
void Background::setColor(Color color)
|
||||
{
|
||||
this->color = color;
|
||||
color_ = color;
|
||||
|
||||
// Colorea la textura
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, colorTexture);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, color_texture_);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderDrawColor(renderer_, color_.r, color_.g, color_.b, 255);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
// Establece la transparencia de la atenuación
|
||||
void Background::setAlpha(int alpha)
|
||||
{
|
||||
// Evita que se asignen valores fuera de rango
|
||||
alpha = std::min(alpha, 255);
|
||||
alpha = std::max(alpha, 0);
|
||||
alpha_ = std::min(alpha, 255);
|
||||
alpha_ = std::max(alpha, 0);
|
||||
|
||||
// Guarda el valor actual
|
||||
alphaColorTextTemp = alphaColorText;
|
||||
alpha_color_text_temp_ = alpha_color_text_;
|
||||
|
||||
// Establece el nuevo valor
|
||||
alphaColorText = alpha;
|
||||
alpha_color_text_ = alpha_;
|
||||
}
|
||||
|
||||
// Actualiza el valor de alpha
|
||||
// Actualiza el valor de alpha_
|
||||
void Background::updateAlphaColorText()
|
||||
{
|
||||
if (alphaColorText == alphaColorTextTemp)
|
||||
if (alpha_color_text_ == alpha_color_text_temp_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
alphaColorText > alphaColorTextTemp ? alphaColorTextTemp++ : alphaColorTextTemp--;
|
||||
SDL_SetTextureAlphaMod(colorTexture, alphaColorTextTemp);
|
||||
alpha_color_text_ > alpha_color_text_temp_ ? ++alpha_color_text_temp_ : --alpha_color_text_temp_;
|
||||
SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_temp_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,35 +294,35 @@ void Background::updateAlphaColorText()
|
||||
void Background::updateClouds()
|
||||
{
|
||||
// Aplica la velocidad calculada a las nubes
|
||||
topCloudsSprite_A->setVelX(cloudsSpeed);
|
||||
topCloudsSprite_B->setVelX(cloudsSpeed);
|
||||
bottomCloudsSprite_A->setVelX(cloudsSpeed / 2);
|
||||
bottomCloudsSprite_B->setVelX(cloudsSpeed / 2);
|
||||
top_clouds_sprite_a_->setVelX(clouds_speed_);
|
||||
top_clouds_sprite_b_->setVelX(clouds_speed_);
|
||||
bottom_clouds_sprite_a_->setVelX(clouds_speed_ / 2);
|
||||
bottom_clouds_sprite_b_->setVelX(clouds_speed_ / 2);
|
||||
|
||||
// Mueve las nubes
|
||||
topCloudsSprite_A->move();
|
||||
topCloudsSprite_B->move();
|
||||
bottomCloudsSprite_A->move();
|
||||
bottomCloudsSprite_B->move();
|
||||
top_clouds_sprite_a_->move();
|
||||
top_clouds_sprite_b_->move();
|
||||
bottom_clouds_sprite_a_->move();
|
||||
bottom_clouds_sprite_b_->move();
|
||||
|
||||
// Calcula el offset de las nubes
|
||||
if (topCloudsSprite_A->getPosX() < -topCloudsSprite_A->getWidth())
|
||||
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth())
|
||||
{
|
||||
topCloudsSprite_A->setPosX(topCloudsSprite_A->getWidth());
|
||||
top_clouds_sprite_a_->setPosX(top_clouds_sprite_a_->getWidth());
|
||||
}
|
||||
|
||||
if (topCloudsSprite_B->getPosX() < -topCloudsSprite_B->getWidth())
|
||||
if (top_clouds_sprite_b_->getPosX() < -top_clouds_sprite_b_->getWidth())
|
||||
{
|
||||
topCloudsSprite_B->setPosX(topCloudsSprite_B->getWidth());
|
||||
top_clouds_sprite_b_->setPosX(top_clouds_sprite_b_->getWidth());
|
||||
}
|
||||
|
||||
if (bottomCloudsSprite_A->getPosX() < -bottomCloudsSprite_A->getWidth())
|
||||
if (bottom_clouds_sprite_a_->getPosX() < -bottom_clouds_sprite_a_->getWidth())
|
||||
{
|
||||
bottomCloudsSprite_A->setPosX(bottomCloudsSprite_A->getWidth());
|
||||
bottom_clouds_sprite_a_->setPosX(bottom_clouds_sprite_a_->getWidth());
|
||||
}
|
||||
|
||||
if (bottomCloudsSprite_B->getPosX() < -bottomCloudsSprite_B->getWidth())
|
||||
if (bottom_clouds_sprite_b_->getPosX() < -bottom_clouds_sprite_b_->getWidth())
|
||||
{
|
||||
bottomCloudsSprite_B->setPosX(bottomCloudsSprite_B->getWidth());
|
||||
bottom_clouds_sprite_b_->setPosX(bottom_clouds_sprite_b_->getWidth());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user