Commit de vesprà tirada a la brossa

This commit is contained in:
2024-10-16 22:35:19 +02:00
parent 5585f996cb
commit db884cb422
32 changed files with 450 additions and 463 deletions

View File

@@ -7,11 +7,10 @@
#include "texture.h" // for Texture
// Carga la animación desde un fichero
AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string file_path)
std::vector<Animation> loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string file_path)
{
// Inicializa variables
AnimatedFile af;
af.texture = texture;
std::vector<Animation> animations;
auto frames_per_row = 0;
auto frame_width = 0;
auto frame_height = 0;
@@ -35,14 +34,14 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]")
{
Animation buffer;
buffer.counter = 0;
buffer.current_frame = 0;
buffer.completed = false;
buffer.name.clear();
buffer.speed = 5;
buffer.loop = 0;
buffer.frames.clear();
Animation animation;
animation.counter = 0;
animation.current_frame = 0;
animation.completed = false;
animation.name.clear();
animation.speed = 5;
animation.loop = 0;
animation.frames.clear();
do
{
@@ -56,17 +55,17 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string
{
if (line.substr(0, pos) == "name")
{
buffer.name = line.substr(pos + 1, line.length());
animation.name = line.substr(pos + 1, line.length());
}
else if (line.substr(0, pos) == "speed")
{
buffer.speed = std::stoi(line.substr(pos + 1, line.length()));
animation.speed = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "loop")
{
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
animation.loop = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "frames")
@@ -81,7 +80,7 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string
const auto num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
rect.x = (num_tile % frames_per_row) * frame_width;
rect.y = (num_tile / frames_per_row) * frame_height;
buffer.frames.push_back(rect);
animation.frames.push_back(rect);
}
}
@@ -95,7 +94,7 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string
} while (line != "[/animation]");
// Añade la animación al vector de animaciones
af.animations.push_back(buffer);
animations.push_back(animation);
}
// En caso contrario se parsea el fichero para buscar las variables y los valores
@@ -156,37 +155,35 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string
#endif
}
return af;
return animations;
}
// Constructor
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file, std::vector<std::string> *buffer)
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path)
: MovingSprite(texture),
current_animation_(0)
{
// Carga las animaciones
if (!file.empty())
if (!file_path.empty())
{
AnimatedFile as = loadAnimationFromFile(texture, file);
// Copia los datos de las animaciones
std::copy(as.animations.begin(), as.animations.end(), std::back_inserter(animations_));
animations_ = loadAnimationFromFile(texture, file_path);
}
}
else if (buffer)
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, std::vector<std::string> *animations)
: MovingSprite(texture),
current_animation_(0)
{
loadFromVector(buffer);
if (animations)
{
loadFromVector(animations);
}
}
// Constructor
AnimatedSprite::AnimatedSprite(const AnimatedFile *animation)
: MovingSprite(animation->texture),
current_animation_(0)
{
// Copia los datos de las animaciones
std::copy(animation->animations.begin(), animation->animations.end(), std::back_inserter(animations_));
}
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture)
: MovingSprite(texture),
current_animation_(0) {}
// Destructor
AnimatedSprite::~AnimatedSprite()
@@ -356,14 +353,14 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]")
{
Animation buffer;
buffer.counter = 0;
buffer.current_frame = 0;
buffer.completed = false;
buffer.name.clear();
buffer.speed = 5;
buffer.loop = 0;
buffer.frames.clear();
Animation animation;
animation.counter = 0;
animation.current_frame = 0;
animation.completed = false;
animation.name.clear();
animation.speed = 5;
animation.loop = 0;
animation.frames.clear();
do
{
@@ -379,17 +376,17 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
{
if (line.substr(0, pos) == "name")
{
buffer.name = line.substr(pos + 1, line.length());
animation.name = line.substr(pos + 1, line.length());
}
else if (line.substr(0, pos) == "speed")
{
buffer.speed = std::stoi(line.substr(pos + 1, line.length()));
animation.speed = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "loop")
{
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
animation.loop = std::stoi(line.substr(pos + 1, line.length()));
}
else if (line.substr(0, pos) == "frames")
@@ -404,7 +401,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
const int num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
rect.x = (num_tile % frames_per_row) * frame_width;
rect.y = (num_tile / frames_per_row) * frame_height;
buffer.frames.push_back(rect);
animation.frames.push_back(rect);
}
}
@@ -419,7 +416,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
} while (line != "[/animation]");
// Añade la animación al vector de animaciones
animations_.push_back(buffer);
animations_.push_back(animation);
}
// En caso contrario se parsea el fichero para buscar las variables y los valores

View File

@@ -19,14 +19,8 @@ struct Animation
int counter; // Contador para las animaciones
};
struct AnimatedFile
{
std::vector<Animation> animations; // Vector con las diferentes animaciones
std::shared_ptr<Texture> texture; // Textura con los graficos para el sprite
};
// Carga la animación desde un fichero
AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string filePath);
std::vector<Animation> loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string filePath);
class AnimatedSprite : public MovingSprite
{
@@ -35,16 +29,20 @@ protected:
std::vector<Animation> animations_; // Vector con las diferentes animaciones
int current_animation_; // Animacion activa
// Calcula el frame correspondiente a la animación actual
void animate();
public:
// Constructor
explicit AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, const std::string &file = std::string(), std::vector<std::string> *buffer = nullptr);
explicit AnimatedSprite(const AnimatedFile *animation);
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
AnimatedSprite(std::shared_ptr<Texture> texture, std::vector<std::string> *animations);
explicit AnimatedSprite(std::shared_ptr<Texture> texture);
// Destructor
virtual ~AnimatedSprite();
// Calcula el frame correspondiente a la animación actual
void animate();
// Actualiza las variables del objeto
void update() override;
// Obtiene el número de frames de la animación actual
int getNumFrames();
@@ -84,9 +82,6 @@ public:
void setCurrentAnimation(const std::string &name = "default");
void setCurrentAnimation(int index = 0);
// Actualiza las variables del objeto
void update() override;
// OLD - Establece el rectangulo para un frame de una animación
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);

View File

@@ -19,6 +19,7 @@ Background::Background(SDL_Renderer *renderer)
{
// Inicializa variables
{
gradient_number_ = 0;
alpha_ = 0;
clouds_speed_ = 0;
@@ -45,29 +46,44 @@ Background::Background(SDL_Renderer *renderer)
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 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_);
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_);
top_clouds_sprite_a_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_Rect){0, top_clouds_y, rect_.w, top_clouds_texture_->getHeight()});
top_clouds_sprite_b_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_Rect){rect_.w, top_clouds_y, rect_.w, top_clouds_texture_->getHeight()});
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_);
bottom_clouds_sprite_a_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_Rect){0, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight()});
bottom_clouds_sprite_b_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_Rect){rect_.w, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight()});
buildings_sprite_ = std::make_unique<Sprite>(buildings_texture_, 0, 0, buildings_texture_->getWidth(), buildings_texture_->getHeight());
gradient_sprite_ = std::make_unique<Sprite>(gradients_texture_, 0, 0, rect_.w, rect_.h);
grass_sprite_ = std::make_unique<Sprite>(grass_texture_, 0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2);
}
// Inicializa objetos
{
constexpr float top_clouds_speed = 0.1f;
constexpr float bottom_clouds_speed = 0.05f;
top_clouds_sprite_a_->setVelX(-top_clouds_speed);
top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
top_clouds_sprite_b_->setVelX(-top_clouds_speed);
top_clouds_sprite_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight());
bottom_clouds_sprite_a_->setVelX(-bottom_clouds_speed);
bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
bottom_clouds_sprite_b_->setVelX(-bottom_clouds_speed);
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);
@@ -297,10 +313,10 @@ void Background::updateClouds()
bottom_clouds_sprite_b_->setVelX(clouds_speed_ / 2);
// Mueve las nubes
top_clouds_sprite_a_->move();
top_clouds_sprite_b_->move();
bottom_clouds_sprite_a_->move();
bottom_clouds_sprite_b_->move();
top_clouds_sprite_a_->update();
top_clouds_sprite_b_->update();
bottom_clouds_sprite_a_->update();
bottom_clouds_sprite_b_->update();
// Calcula el offset de las nubes
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth())

View File

@@ -1,6 +1,6 @@
#include "balloon.h"
#include <cmath> // for abs
#include "animated_sprite.h" // for AnimatedSprite
#include "animated_sprite.h" // for SpriteAnimated
#include "moving_sprite.h" // for MovingSprite
#include "param.h" // for param
#include "sprite.h" // for Sprite
@@ -8,7 +8,7 @@
// Constructor
Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, std::vector<std::string> *animation)
: sprite_(std::make_unique<AnimatedSprite>(texture, "", animation)),
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
pos_x_(x),
pos_y_(y),
vel_x_(vel_x),
@@ -217,7 +217,7 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
menace_ = 0;
// Añade rotación al sprite_
sprite_->setRotate(false);
sprite_->disableRotate();
sprite_->setRotateSpeed(0);
vel_x_ > 0.0f ? sprite_->setRotateAmount(2.0) : sprite_->setRotateAmount(-2.0);
@@ -306,7 +306,7 @@ void Balloon::render()
if (kind_ == POWER_BALL && !isBeingCreated())
{
auto sp = std::make_unique<Sprite>(sprite_->getPos(), sprite_->getTexture());
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPos());
sp->setSpriteClip(BALLOON_WIDTH_4, 0, BALLOON_WIDTH_4, BALLOON_WIDTH_4);
sp->render();
}
@@ -454,7 +454,7 @@ void Balloon::update()
{
if (enabled_)
{
sprite_->MovingSprite::update();
sprite_->update();
move();
updateAnimation();
updateColliders();
@@ -510,7 +510,7 @@ void Balloon::updateState()
setInvulnerable(false);
if (kind_ == POWER_BALL)
{
sprite_->setRotate(true);
sprite_->enableRotate();
}
}
}
@@ -520,7 +520,7 @@ void Balloon::updateState()
// Si es una powerball deja de rodar
if (kind_ == POWER_BALL)
{
sprite_->setRotate(false);
sprite_->disableRotate();
}
// Reduce el contador
@@ -536,7 +536,7 @@ void Balloon::updateState()
// Si es una powerball vuelve a rodar
if (kind_ == POWER_BALL)
{
sprite_->setRotate(true);
sprite_->enableRotate();
}
}
}
@@ -569,7 +569,7 @@ void Balloon::updateAnimation()
sprite_->setCurrentAnimation(normal_animation);
}
sprite_->animate();
sprite_->update();
}
// Comprueba si el globo está habilitado

View File

@@ -4,7 +4,7 @@
#include <memory> // for shared_ptr, unique_ptr
#include <string> // for string
#include <vector> // for vector
#include "animated_sprite.h" // for AnimatedSprite
#include "animated_sprite.h" // for SpriteAnimated
#include "utils.h" // for Circle
class Texture;

View File

@@ -12,7 +12,7 @@ constexpr int BULLET_VELX_RIGHT = 2;
// Constructor
Bullet::Bullet(int x, int y, BulletType kind, bool powered_up, int owner, SDL_Rect *play_area, std::shared_ptr<Texture> texture)
: sprite_(std::make_unique<Sprite>(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture)),
: sprite_(std::make_unique<Sprite>(texture, SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT})),
pos_x_(x),
pos_y_(y),
width_(BULLET_WIDTH),

View File

@@ -55,6 +55,10 @@ Director::Director(int argc, const char *argv[])
section::name = section::Name::LOGO;
#endif
// Deshabilita todos los std::cout
//std::ostream null_stream(nullptr);
//std::streambuf *orig_buf = std::cout.rdbuf(null_stream.rdbuf());
// Comprueba los parametros del programa
checkProgramArguments(argc, argv);

View File

@@ -1,6 +1,6 @@
#include "explosions.h"
#include <utility> // for move
#include "animated_sprite.h" // for AnimatedSprite
#include "animated_sprite.h" // for SpriteAnimated
class Texture; // lines 3-3
// Constructor
@@ -51,7 +51,7 @@ void Explosions::addTexture(int size, std::shared_ptr<Texture> texture, std::vec
void Explosions::add(int x, int y, int size)
{
const int index = getIndexBySize(size);
auto sprite = std::make_unique<AnimatedSprite>(textures_[index].texture, "", textures_[index].animation);
auto sprite = std::make_unique<AnimatedSprite>(textures_[index].texture, textures_[index].animation);
sprite->setPos(x, y);
explosions_.push_back(std::move(sprite));
}

View File

@@ -32,7 +32,7 @@
#include "scoreboard.h" // for Scoreboard, ScoreboardMode, SCOREB...
#include "screen.h" // for Screen
#include "section.h" // for Name, name, Options, options
#include "smart_sprite.h" // for SmartSprite
#include "smart_sprite.h" // for SpriteSmart
#include "text.h" // for Text, TEXT_CENTER
#include "texture.h" // for Texture
struct JA_Music_t; // lines 35-35
@@ -1413,7 +1413,7 @@ void Game::freeItems()
}
}
// Crea un objeto SmartSprite para mostrar la puntuación al coger un objeto
// Crea un objeto SpriteSmart para mostrar la puntuación al coger un objeto
void Game::createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture)
{
smart_sprites_.emplace_back(std::make_unique<SmartSprite>(texture));
@@ -1432,7 +1432,7 @@ void Game::createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture)
}
// Vacia el vector de smartsprites
void Game::freeSmartSprites()
void Game::freeSpriteSmarts()
{
if (!smart_sprites_.empty())
{
@@ -1446,7 +1446,7 @@ void Game::freeSmartSprites()
}
}
// Crea un SmartSprite para arrojar el item café al recibir un impacto
// Crea un SpriteSmart para arrojar el item café al recibir un impacto
void Game::throwCoffee(int x, int y)
{
smart_sprites_.emplace_back(std::make_unique<SmartSprite>(item_textures_[4]));
@@ -1464,13 +1464,13 @@ void Game::throwCoffee(int x, int y)
smart_sprites_.back()->setEnabled(true);
smart_sprites_.back()->setFinishedCounter(1);
smart_sprites_.back()->setSpriteClip(0, param.game.item_size, param.game.item_size, param.game.item_size);
smart_sprites_.back()->setRotate(true);
smart_sprites_.back()->enableRotate();
smart_sprites_.back()->setRotateSpeed(10);
smart_sprites_.back()->setRotateAmount(90.0);
}
// Actualiza los SmartSprites
void Game::updateSmartSprites()
// Actualiza los SpriteSmarts
void Game::updateSpriteSmarts()
{
for (auto &ss : smart_sprites_)
{
@@ -1478,8 +1478,8 @@ void Game::updateSmartSprites()
}
}
// Pinta los SmartSprites activos
void Game::renderSmartSprites()
// Pinta los SpriteSmarts activos
void Game::renderSpriteSmarts()
{
for (auto &ss : smart_sprites_)
{
@@ -1679,8 +1679,8 @@ void Game::update()
// Actualiza el estado de muerte
updateGameOver();
// Actualiza los SmartSprites
updateSmartSprites();
// Actualiza los SpriteSmarts
updateSpriteSmarts();
// Actualiza los contadores de estado y efectos
updateTimeStoppedCounter();
@@ -1708,7 +1708,7 @@ void Game::update()
freeBullets();
freeBalloons();
freeItems();
freeSmartSprites();
freeSpriteSmarts();
}
// Comprueba si la música ha de estar sonando
@@ -1757,7 +1757,7 @@ void Game::fillCanvas()
// Dibuja los objetos
background_->render();
renderItems();
renderSmartSprites();
renderSpriteSmarts();
explosions_->render();
renderBalloons();
renderBullets();

View File

@@ -134,7 +134,7 @@ private:
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures_; // Vector con todas las texturas de los jugadores;
std::vector<std::shared_ptr<Texture>> game_text_textures_; // Vector con las texturas para los sprites con textos
//std::vector<std::shared_ptr<SmartSprite>> game_text_sprites_; // Sprite con el textos que aparecen al coger items
// std::vector<std::shared_ptr<SpriteSmart>> game_text_sprites_; // Sprite con el textos que aparecen al coger items
std::vector<std::vector<std::string> *> item_animations_; // Vector con las animaciones de los items
std::vector<std::vector<std::string> *> player_animations_; // Vector con las animaciones del jugador
@@ -321,20 +321,20 @@ private:
// Vacia el vector de items
void freeItems();
// Crea un objeto SmartSprite
// Crea un objeto SpriteSmart
void createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture);
// Vacia el vector de smartsprites
void freeSmartSprites();
void freeSpriteSmarts();
// Crea un SmartSprite para arrojar el item café al recibir un impacto
// Crea un SpriteSmart para arrojar el item café al recibir un impacto
void throwCoffee(int x, int y);
// Actualiza los SmartSprites
void updateSmartSprites();
// Actualiza los SpriteSmarts
void updateSpriteSmarts();
// Pinta los SmartSprites activos
void renderSmartSprites();
// Pinta los SpriteSmarts activos
void renderSpriteSmarts();
// Acciones a realizar cuando el jugador muere
void killPlayer(std::shared_ptr<Player> &player);

View File

@@ -1,12 +1,12 @@
#include "game_logo.h"
#include <SDL2/SDL_render.h> // for SDL_FLIP_HORIZONTAL
#include <algorithm> // for max
#include "animated_sprite.h" // for AnimatedSprite
#include "animated_sprite.h" // for SpriteAnimated
#include "asset.h" // for Asset
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_PlaySound
#include "param.h" // for param
#include "screen.h" // for Screen
#include "smart_sprite.h" // for SmartSprite
#include "smart_sprite.h" // for SpriteSmart
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
#include "utils.h" // for Param, ParamGame, ParamTitle
@@ -24,7 +24,7 @@ GameLogo::GameLogo(int x, int y)
coffee_sprite_(std::make_unique<SmartSprite>(coffee_texture_)),
crisis_sprite_(std::make_unique<SmartSprite>(crisis_texture_)),
arcade_edition_sprite_(std::make_unique<Sprite>((param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight(), arcade_edition_texture_)),
arcade_edition_sprite_(std::make_unique<Sprite>(arcade_edition_texture_, (param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight())),
crash_sound_(JA_LoadSound(Asset::get()->get("title.wav").c_str())),

View File

@@ -98,7 +98,7 @@ void Instructions::iniSprites()
// Inicializa los sprites
for (int i = 0; i < (int)item_textures_.size(); ++i)
{
auto sprite = std::make_unique<Sprite>(0, 0, param.game.item_size, param.game.item_size, item_textures_[i]);
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, param.game.item_size, param.game.item_size);
sprite->setPos((SDL_Point){sprite_pos_.x, sprite_pos_.y + ((param.game.item_size + item_space_) * i)});
sprites_.push_back(std::move(sprite));
}

View File

@@ -11,7 +11,7 @@
#include "param.h" // for param
#include "screen.h" // for Screen
#include "section.h" // for Name, name, Options, options
#include "smart_sprite.h" // for SmartSprite
#include "smart_sprite.h" // for SpriteSmart
#include "text.h" // for Text
#include "texture.h" // for Texture
#include "utils.h" // for Param, ParamGame, Zone, BLOCK, Color

View File

@@ -3,7 +3,7 @@
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
#include <memory> // for unique_ptr, shared_ptr
#include <vector> // for vector
#include "smart_sprite.h" // for SmartSprite
#include "smart_sprite.h" // for SpriteSmart
#include "writer.h" // for Writer
class Text;
class Texture;

View File

@@ -1,12 +1,12 @@
#include "item.h"
#include <stdlib.h> // for rand
#include "animated_sprite.h" // for AnimatedSprite
#include "animated_sprite.h" // for SpriteAnimated
#include "param.h" // for param
class Texture;
// Constructor
Item::Item(ItemType type, float x, float y, SDL_Rect *play_area, std::shared_ptr<Texture> texture, std::vector<std::string> *animation)
: sprite_(std::make_unique<AnimatedSprite>(texture, "", animation)),
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
accel_x_(0.0f),
floor_collision_(false),
type_(type),
@@ -144,7 +144,7 @@ void Item::disable()
void Item::update()
{
move();
sprite_->animate();
sprite_->update();
updateTimeToLive();
checkTimeToLive();
}

View File

@@ -5,7 +5,7 @@
#include <memory> // for shared_ptr, unique_ptr
#include <string> // for string
#include <vector> // for vector
#include "animated_sprite.h" // for AnimatedSprite
#include "animated_sprite.h" // for SpriteAnimated
#include "utils.h" // for Circle
class Texture;

View File

@@ -23,7 +23,7 @@ Logo::Logo()
// Reserva memoria para los punteros
jail_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames.png"));
since_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_since_1998.png"));
since_sprite_ = std::make_unique<Sprite>((param.game.width - since_texture_->getWidth()) / 2, 83 + jail_texture_->getHeight() + 5, since_texture_->getWidth(), since_texture_->getHeight(), since_texture_);
since_sprite_ = std::make_unique<Sprite>(since_texture_, (param.game.width - since_texture_->getWidth()) / 2, 83 + jail_texture_->getHeight() + 5, since_texture_->getWidth(), since_texture_->getHeight());
// Inicializa variables
counter_ = 0;
@@ -38,7 +38,7 @@ Logo::Logo()
// Crea los sprites de cada linea
for (int i = 0; i < jail_texture_->getHeight(); ++i)
{
auto temp = std::make_unique<Sprite>(0, i, jail_texture_->getWidth(), 1, jail_texture_);
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
temp->setPosX(posX);
@@ -115,12 +115,12 @@ void Logo::updateJAILGAMES()
{
for (int i = 0; i < (int)jail_sprite_.size(); ++i)
{
if (jail_sprite_[i]->getIntPosX() != dest_.x)
if (jail_sprite_[i]->getPosX() != dest_.x)
{
if (i % 2 == 0)
{
jail_sprite_[i]->incPosX(-SPEED);
if (jail_sprite_[i]->getIntPosX() < dest_.x)
if (jail_sprite_[i]->getPosX() < dest_.x)
{
jail_sprite_[i]->setPosX(dest_.x);
}
@@ -128,7 +128,7 @@ void Logo::updateJAILGAMES()
else
{
jail_sprite_[i]->incPosX(SPEED);
if (jail_sprite_[i]->getIntPosX() > dest_.x)
if (jail_sprite_[i]->getPosX() > dest_.x)
{
jail_sprite_[i]->setPosX(dest_.x);
}

View File

@@ -2,34 +2,26 @@
#include "texture.h" // for Texture
// Constructor
MovingSprite::MovingSprite(float x, float y, int w, int h, float vx, float vy, float ax, float ay, std::shared_ptr<Texture> texture)
: Sprite((int)x, (int)y, w, h, texture),
x_(x),
y_(y),
vx_(vx),
vy_(vy),
ax_(ax),
ay_(ay),
zoom_w_(1),
zoom_h_(1),
counter_(0),
flip_(SDL_FLIP_NONE)
{
// Establece los valores de rotacion
rotate_.enabled = false;
rotate_.speed = 0;
rotate_.angle = 0.0f;
rotate_.amount = 0.0f;
rotate_.center = nullptr;
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip)
: Sprite(texture, pos),
rotate_(rotate),
zoom_w_(zoom_w),
zoom_h_(zoom_h),
flip_(flip) {}
sprite_clip_ = (SDL_Rect){0, 0, w, h};
};
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos)
: Sprite(texture, pos),
rotate_({false, 0, 0, 0.0f, 0.0f, nullptr}),
zoom_w_(1.0f),
zoom_h_(1.0f),
flip_(SDL_FLIP_NONE) {}
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture)
: Sprite(texture)
{
clear();
};
: Sprite(texture),
rotate_({false, 0, 0, 0.0f, 0.0f, nullptr}),
zoom_w_(1.0f),
zoom_h_(1.0f),
flip_(SDL_FLIP_NONE) {}
// Reinicia todas las variables
void MovingSprite::clear()
@@ -43,16 +35,15 @@ void MovingSprite::clear()
ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad
ay_ = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
zoom_w_ = 1.0f; // Zoom aplicado a la anchura
zoom_h_ = 1.0f; // Zoom aplicado a la altura
rotate_.enabled = false; // Indica si ha de rotar
rotate_.counter = 0; // Contador
rotate_.speed = 0; // Velocidad de giro
rotate_.angle = 0.0f; // Angulo para dibujarlo
rotate_.amount = 0.0f; // Cantidad de grados a girar en cada iteración
rotate_.center = nullptr; // Centro de rotación
counter_ = 0; // Contador interno
zoom_w_ = 1.0f; // Zoom aplicado a la anchura
zoom_h_ = 1.0f; // Zoom aplicado a la altura
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
@@ -70,10 +61,135 @@ void MovingSprite::move()
vy_ += ay_;
}
// Actualiza las variables internas del objeto
void MovingSprite::update()
{
move();
rotate();
}
// Muestra el sprite por pantalla
void MovingSprite::render()
{
texture_->render((int)x_, (int)y_, &sprite_clip_, zoom_w_, zoom_h_, (double)rotate_.angle, rotate_.center, flip_);
texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_);
}
// Obtiene el valor de la variable
float MovingSprite::getZoomW() const
{
return zoom_w_;
}
// Obtiene el valor de la variable
float MovingSprite::getZoomH() const
{
return zoom_h_;
}
// Obtiene el valor de la variable
double MovingSprite::getAngle() const
{
return rotate_.angle;
}
// Establece el valor de la variable
void MovingSprite::setZoomW(float value)
{
zoom_w_ = value;
}
// Establece el valor de la variable
void MovingSprite::setZoomH(float value)
{
zoom_h_ = value;
}
// Establece el valor de la variable
void MovingSprite::setAngle(double value)
{
rotate_.angle = value;
}
// Incrementa el valor del ángulo
void MovingSprite::updateAngle()
{
rotate_.angle += rotate_.amount;
}
// Obtiene el valor de la variable
bool MovingSprite::isRotating() const
{
return rotate_.enabled;
}
// Obtiene el valor de la variable
int MovingSprite::getRotateSpeed() const
{
return rotate_.speed;
}
// Establece la rotacion
void MovingSprite::rotate()
{
if (rotate_.enabled)
{
++rotate_.counter;
if (rotate_.counter % rotate_.speed == 0)
{
updateAngle();
rotate_.counter = 0;
}
}
}
// Establece el valor de la variable
void MovingSprite::enableRotate()
{
rotate_.enabled = true;
rotate_.counter = 0;
}
// Establece el valor de la variable
void MovingSprite::disableRotate()
{
rotate_.enabled = false;
rotate_.counter = 0;
}
// Establece el valor de la variable
void MovingSprite::setRotateSpeed(int value)
{
rotate_.speed = std::max(1, value);
}
// Establece el valor de la variable
void MovingSprite::setRotateAmount(double value)
{
rotate_.amount = value;
}
// Cambia el sentido de la rotación
void MovingSprite::switchRotate()
{
rotate_.amount *= -1;
}
// Establece el valor de la variable
void MovingSprite::setFlip(SDL_RendererFlip flip)
{
flip_ = flip;
}
// Gira el sprite horizontalmente
void MovingSprite::flip()
{
flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
}
// Obtiene el valor de la variable
SDL_RendererFlip MovingSprite::getFlip()
{
return flip_;
}
// Obtiene el valor de la variable
@@ -112,24 +228,6 @@ float MovingSprite::getAccelY() const
return ay_;
}
// Obtiene el valor de la variable
float MovingSprite::getZoomW() const
{
return zoom_w_;
}
// Obtiene el valor de la variable
float MovingSprite::getZoomH() const
{
return zoom_h_;
}
// Obtiene el valor de la variable
float MovingSprite::getAngle() const
{
return rotate_.angle;
}
// Establece la posición y_ el tamaño del objeto
void MovingSprite::setPos(SDL_Rect rect)
{
@@ -186,120 +284,3 @@ void MovingSprite::setAccelY(float value)
{
ay_ = value;
}
// Establece el valor de la variable
void MovingSprite::setZoomW(float value)
{
zoom_w_ = value;
}
// Establece el valor de la variable
void MovingSprite::setZoomH(float value)
{
zoom_h_ = value;
}
// Establece el valor de la variable
void MovingSprite::setAngle(double value)
{
rotate_.angle = value;
}
// Incrementa el valor de la variable
void MovingSprite::incAngle(double value)
{
rotate_.angle += value;
}
// Decrementa el valor de la variable
void MovingSprite::decAngle(double value)
{
rotate_.angle -= value;
}
// Obtiene el valor de la variable
bool MovingSprite::getRotate() const
{
return rotate_.enabled;
}
// Obtiene el valor de la variable
Uint16 MovingSprite::getRotateSpeed() const
{
return rotate_.speed;
}
// Establece la rotacion
void MovingSprite::rotate()
{
if (rotate_.enabled)
{
if (counter_ % rotate_.speed == 0)
{
incAngle(rotate_.amount);
}
}
}
// Establece el valor de la variable
void MovingSprite::setRotate(bool value)
{
rotate_.enabled = value;
}
// Establece el valor de la variable
void MovingSprite::setRotateSpeed(int value)
{
rotate_.speed = (value < 1) ? 1 : value;
}
// Establece el valor de la variable
void MovingSprite::setRotateAmount(double value)
{
rotate_.amount = value;
}
// Establece el valor de la variable
void MovingSprite::disableRotate()
{
rotate_.enabled = false;
rotate_.angle = 0.0f;
}
// Actualiza las variables internas del objeto
void MovingSprite::update()
{
move();
rotate();
++counter_ %= 60000;
}
// Cambia el sentido de la rotación
void MovingSprite::switchRotate()
{
rotate_.amount *= -1;
}
// Establece el valor de la variable
void MovingSprite::setFlip(SDL_RendererFlip flip)
{
flip_ = flip;
}
// Gira el sprite horizontalmente
void MovingSprite::flip()
{
flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
}
// Obtiene el valor de la variable
SDL_RendererFlip MovingSprite::getFlip()
{
return flip_;
}
// Devuelve el rectangulo donde está el sprite
SDL_Rect MovingSprite::getPos() const
{
return (SDL_Rect){(int)x_, (int)y_, pos_.w, pos_.h};
}

View File

@@ -7,19 +7,21 @@
#include "sprite.h" // for Sprite
class Texture;
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
// Clase MovingSprite. Añade movimiento y efectos de rotación, zoom y flip al sprite
class MovingSprite : public Sprite
{
protected:
public:
struct Rotate
{
bool enabled; // Indica si ha de rotar
int counter; // Contador
int speed; // Velocidad de giro
float angle; // Angulo para dibujarlo
double angle; // Angulo para dibujarlo
float amount; // Cantidad de grados a girar en cada iteración
SDL_Point *center; // Centro de rotación
};
protected:
float x_; // Posición en el eje X
float y_; // Posición en el eje Y
@@ -29,20 +31,13 @@ protected:
float ax_; // Aceleración en el eje X. Variación de la velocidad
float ay_; // Aceleración en el eje Y. Variación de la velocidad
Rotate rotate_; // Variables usada para controlar la rotación del sprite
float zoom_w_; // Zoom aplicado a la anchura
float zoom_h_; // Zoom aplicado a la altura
int counter_; // Contador interno
Rotate rotate_; // Variables usada para controlar la rotación del sprite
SDL_RendererFlip flip_; // Indica como se voltea el sprite
public:
// Constructor
explicit MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, std::shared_ptr<Texture> texture = nullptr);
explicit MovingSprite(std::shared_ptr<Texture> texture = nullptr);
// Destructor
virtual ~MovingSprite() = default;
// Incrementa el valor del ángulo
void updateAngle();
// Mueve el sprite
void move();
@@ -50,6 +45,15 @@ public:
// Rota el sprite
void rotate();
public:
// Constructor
MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, MovingSprite::Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip);
MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos);
explicit MovingSprite(std::shared_ptr<Texture> texture);
// Destructor
~MovingSprite() = default;
// Actualiza las variables internas del objeto
virtual void update();
@@ -59,45 +63,28 @@ public:
// Muestra el sprite por pantalla
void render() override;
// Obten el valor de la variable
// Obtiene la variable
float getPosX() const;
float getPosY() const;
// Obten el valor de la variable
float getVelX() const;
float getVelY() const;
// Obten el valor de la variable
float getAccelX() const;
float getAccelY() const;
// Establece la variable
void setVelX(float value);
void setVelY(float value);
void setAccelX(float value);
void setAccelY(float value);
// Obten el valor de la variable
float getZoomW() const;
float getZoomH() const;
// Obten el valor de la variable
float getAngle() const;
bool getRotate() const;
Uint16 getRotateSpeed() const;
// Establece la posición del objeto
void setPos(SDL_Rect rect) override;
void setPos(float x, float y);
// Devuelve el rectangulo donde está el sprite
SDL_Rect getPos() const override;
// Establece el valor de la variable
void setPosX(float value);
void setPosY(float value);
// Establece el valor de la variable
void setVelX(float value);
void setVelY(float value);
// Establece el valor de la variable
void setAccelX(float value);
void setAccelY(float value);
bool isRotating() const;
double getAngle() const;
int getRotateSpeed() const;
// Establece el valor de la variable
void setZoomW(float value);
@@ -105,17 +92,15 @@ public:
// Establece el valor de la variable
void setAngle(double vaue);
void incAngle(double value);
void decAngle(double value);
// Activa o desactiva el efecto derotación
void enableRotate();
void disableRotate();
// Establece el valor de la variable
void setRotate(bool value);
void setRotateSpeed(int value);
void setRotateAmount(double value);
// Quita el efecto de rotación y deja el sprite en su angulo inicial.
void disableRotate();
// Cambia el sentido de la rotación
void switchRotate();
@@ -128,5 +113,15 @@ public:
// Obtiene el valor de la variable
SDL_RendererFlip getFlip();
// Establece la posición y_ el tamaño del objeto
void setPos(SDL_Rect rect);
// Establece el valor de las variables
void setPos(float x, float y);
// Establece el valor de la variable
void setPosX(float value);
// Establece el valor de la variable
void setPosY(float value);
};

View File

@@ -277,7 +277,7 @@ void Notifier::showText(std::string text1, std::string text2, int icon, std::str
// Dibuja el icono de la notificación
if (has_icons_ && icon >= 0 && num_texts == 2)
{
auto sp = std::make_unique<Sprite>((SDL_Rect){0, 0, icon_size, icon_size}, icon_texture_);
auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_Rect){0, 0, icon_size, icon_size});
sp->setPos({padding_in_h, padding_in_v, icon_size, icon_size});
sp->setSpriteClip({icon_size * (icon % 10), icon_size * (icon / 10), icon_size, icon_size});
sp->render();
@@ -299,7 +299,7 @@ void Notifier::showText(std::string text1, std::string text2, int icon, std::str
SDL_SetRenderTarget(renderer_, nullptr);
// Crea el sprite de la notificación
n.sprite = std::make_shared<Sprite>(n.rect, n.texture);
n.sprite = std::make_shared<Sprite>(n.texture, n.rect);
// Deja la notificación invisible
n.texture->setAlpha(0);

View File

@@ -101,7 +101,7 @@ void OnScreenHelp::fillTexture()
auto controllersTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("controllers.png"));
// Crea el sprite para dibujar los gráficos
auto sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, 16, 16}, controllersTexture);
auto sprite = std::make_unique<Sprite>(controllersTexture, (SDL_Rect){0, 0, 16, 16});
// Borra la textura
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);

View File

@@ -3,7 +3,7 @@
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <stdlib.h> // for rand
#include <algorithm> // for max, min
#include "animated_sprite.h" // for AnimatedSprite
#include "animated_sprite.h" // for SpriteAnimated
#include "input.h" // for inputs_e
#include "param.h" // for param
#include "texture.h" // for Texture
@@ -12,8 +12,8 @@
// Constructor
Player::Player(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vector<std::shared_ptr<Texture>> texture, std::vector<std::vector<std::string> *> animations)
: player_sprite_(std::make_unique<AnimatedSprite>(texture[0], "", animations[0])),
power_sprite_(std::make_unique<AnimatedSprite>(texture[1], "", animations[1])),
: player_sprite_(std::make_unique<AnimatedSprite>(texture[0], animations[0])),
power_sprite_(std::make_unique<AnimatedSprite>(texture[1], animations[1])),
enter_name_(std::make_unique<EnterName>()),
play_area_(play_area),
id_(id),
@@ -279,10 +279,10 @@ void Player::setAnimation()
}
// Actualiza las animaciones de los sprites
player_sprite_->animate();
player_sprite_->update();
// powerSprite->setFlip(flip_walk);
power_sprite_->animate();
power_sprite_->update();
}
// Obtiene el valor de la variable

View File

@@ -5,7 +5,8 @@
#include <memory> // for unique_ptr, shared_ptr
#include <string> // for string
#include <vector> // for vector
#include "animated_sprite.h" // for AnimatedSprite
#include "animated_sprite.h" // for SpriteAnimated
#include "smart_sprite.h" // for SpriteAnimated
#include "enter_name.h" // for EnterName
#include "utils.h" // for Circle
class Texture;

View File

@@ -1,5 +1,4 @@
#include "smart_sprite.h"
#include "moving_sprite.h" // for MovingSprite
class Texture;
// Constructor
@@ -14,8 +13,7 @@ void SmartSprite::init()
{
finished_counter_ = 0;
on_destination_ = false;
dest_x_ = 0;
dest_y_ = 0;
dest_x_ = dest_y_ = 0;
finished_ = false;
enabled_ = false;
}

View File

@@ -1,10 +1,10 @@
#pragma once
#include <memory> // for shared_ptr
#include "animated_sprite.h" // for AnimatedSprite
#include "animated_sprite.h" // for SpriteAnimated
class Texture;
// Clase SmartSprite
// Clase SpriteSmart
class SmartSprite : public AnimatedSprite
{
private:
@@ -16,12 +16,12 @@ private:
bool finished_; // Indica si ya ha terminado
bool enabled_; // Indica si el objeto está habilitado
// Comprueba el movimiento
void checkMove();
// Comprueba si ha terminado
void checkFinished();
// Comprueba el movimiento
void checkMove();
public:
// Constructor
explicit SmartSprite(std::shared_ptr<Texture> texture);

View File

@@ -1,12 +1,12 @@
#include "sprite.h"
// Constructor
Sprite::Sprite(int x, int y, int w, int h, std::shared_ptr<Texture> texture)
Sprite::Sprite(std::shared_ptr<Texture> texture, int x, int y, int w, int h)
: texture_(texture),
pos_((SDL_Rect){x, y, w, h}),
sprite_clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
Sprite::Sprite(SDL_Rect rect, std::shared_ptr<Texture> texture)
Sprite::Sprite(std::shared_ptr<Texture> texture, SDL_Rect rect)
: texture_(texture),
pos_(rect),
sprite_clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
@@ -23,13 +23,13 @@ void Sprite::render()
}
// Obten el valor de la variable
int Sprite::getIntPosX() const
int Sprite::getPosX() const
{
return pos_.x;
}
// Obten el valor de la variable
int Sprite::getIntPosY() const
int Sprite::getPosY() const
{
return pos_.y;
}

View File

@@ -15,24 +15,24 @@ protected:
public:
// Constructor
explicit Sprite(int x = 0, int y = 0, int w = 0, int h = 0, std::shared_ptr<Texture> texture = nullptr);
explicit Sprite(SDL_Rect rect, std::shared_ptr<Texture> texture = nullptr);
explicit Sprite(std::shared_ptr<Texture> texture = nullptr);
Sprite(std::shared_ptr<Texture>, int x, int y, int w, int h);
Sprite(std::shared_ptr<Texture>, SDL_Rect rect);
explicit Sprite(std::shared_ptr<Texture>);
// Destructor
virtual ~Sprite() = default;
~Sprite() = default;
// Muestra el sprite por pantalla
virtual void render();
// Obten el valor de la variable
int getIntPosX() const;
int getIntPosY() const;
int getPosX() const;
int getPosY() const;
int getWidth() const;
int getHeight() const;
// Devuelve el rectangulo donde está el sprite
virtual SDL_Rect getPos() const;
SDL_Rect getPos() const;
// Establece el valor de la variable
void setPosX(int x);
@@ -43,7 +43,7 @@ public:
// Establece la posición del objeto
void setPos(int x, int y);
void setPos(SDL_Point p);
virtual void setPos(SDL_Rect r);
void setPos(SDL_Rect r);
// Incrementa el valor de la variable
void incPosX(int value);

View File

@@ -99,7 +99,7 @@ Text::Text(const std::string &bitmap_file, const std::string &text_file, SDL_Ren
// Crea los objetos
texture_ = std::make_shared<Texture>(renderer, bitmap_file);
sprite_ = std::make_unique<Sprite>((SDL_Rect){0, 0, box_width_, box_height_}, texture_);
sprite_ = std::make_unique<Sprite>(texture_, (SDL_Rect){0, 0, box_width_, box_height_});
// Inicializa variables
fixed_width_ = false;
@@ -122,7 +122,7 @@ Text::Text(const std::string &text_file, std::shared_ptr<Texture> texture)
}
// Crea los objetos
sprite_ = std::make_unique<Sprite>((SDL_Rect){0, 0, box_width_, box_height_}, texture);
sprite_ = std::make_unique<Sprite>(texture, (SDL_Rect){0, 0, box_width_, box_height_});
// Inicializa variables
fixed_width_ = false;
@@ -142,7 +142,7 @@ Text::Text(TextFile *text_file, std::shared_ptr<Texture> texture)
}
// Crea los objetos
sprite_ = std::make_unique<Sprite>((SDL_Rect){0, 0, box_width_, box_height_}, texture);
sprite_ = std::make_unique<Sprite>(texture, (SDL_Rect){0, 0, box_width_, box_height_});
// Inicializa variables
fixed_width_ = false;

View File

@@ -60,7 +60,7 @@ void Tiledbg::fillTexture()
{
// Crea los objetos para pintar en la textura de fondo
auto bg_tile_texture = std::make_shared<Texture>(renderer_, texture_path_);
auto tile = std::make_unique<Sprite>((SDL_Rect){0, 0, tile_width_, tile_height_}, bg_tile_texture);
auto tile = std::make_unique<Sprite>(bg_tile_texture, (SDL_Rect){0, 0, tile_width_, tile_height_});
// Prepara para dibujar sobre la textura
auto temp = SDL_GetRenderTarget(renderer_);

View File

@@ -39,7 +39,7 @@ Title::Title(JA_Music_t *music)
text2_ = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer);
mini_logo_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames_mini.png"));
mini_logo_sprite_ = std::make_unique<Sprite>(param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight(), mini_logo_texture_);
mini_logo_sprite_ = std::make_unique<Sprite>(mini_logo_texture_, param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight());
tiled_bg_ = std::make_unique<Tiledbg>(Asset::get()->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM);