Commit pa que Mon arregle el codi mentre em dutxe

This commit is contained in:
2024-10-09 21:48:01 +02:00
parent 3c1dcad3ab
commit f2fa216b0d
34 changed files with 862 additions and 1218 deletions

View File

@@ -4,21 +4,18 @@
#include <algorithm> // for max, min
#include <string> // for basic_string
#include "asset.h" // for Asset
#include "moving_sprite.h" // for MovingSprite
#include "param.h" // for param
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
// Constructor
Background::Background(SDL_Renderer *renderer)
: renderer(renderer)
{
// Carga las texturas
buildingsTexture = new Texture(renderer, Asset::get()->get("game_buildings.png"));
topCloudsTexture = new Texture(renderer, Asset::get()->get("game_clouds1.png"));
bottomCloudsTexture = new Texture(renderer, Asset::get()->get("game_clouds2.png"));
grassTexture = new Texture(renderer, Asset::get()->get("game_grass.png"));
gradientsTexture = new Texture(renderer, Asset::get()->get("game_sky_colors.png"));
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"));
// Inicializa variables
gradientNumber = 0;
@@ -53,15 +50,15 @@ Background::Background(SDL_Renderer *renderer)
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);
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);
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);
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);
buildingsSprite = new Sprite(0, 0, buildingsTexture->getWidth(), buildingsTexture->getHeight(), buildingsTexture);
gradientSprite = new Sprite(0, 0, rect.w, rect.h, gradientsTexture);
grassSprite = new Sprite(0, 0, grassTexture->getWidth(), grassTexture->getHeight() / 2, grassTexture);
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);
// Inicializa objetos
topCloudsSprite_A->setSpriteClip(0, 0, topCloudsTexture->getWidth(), topCloudsTexture->getHeight());
@@ -85,19 +82,6 @@ Background::Background(SDL_Renderer *renderer)
// Destructor
Background::~Background()
{
delete buildingsTexture;
delete topCloudsTexture;
delete bottomCloudsTexture;
delete grassTexture;
delete gradientsTexture;
delete topCloudsSprite_A;
delete topCloudsSprite_B;
delete bottomCloudsSprite_A;
delete bottomCloudsSprite_B;
delete buildingsSprite;
delete gradientSprite;
delete grassSprite;
SDL_DestroyTexture(canvas);
SDL_DestroyTexture(colorTexture);
}