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 #include "texture.h" // for Texture
// Carga la animación desde un fichero // 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 // Inicializa variables
AnimatedFile af; std::vector<Animation> animations;
af.texture = texture;
auto frames_per_row = 0; auto frames_per_row = 0;
auto frame_width = 0; auto frame_width = 0;
auto frame_height = 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 // Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]") if (line == "[animation]")
{ {
Animation buffer; Animation animation;
buffer.counter = 0; animation.counter = 0;
buffer.current_frame = 0; animation.current_frame = 0;
buffer.completed = false; animation.completed = false;
buffer.name.clear(); animation.name.clear();
buffer.speed = 5; animation.speed = 5;
buffer.loop = 0; animation.loop = 0;
buffer.frames.clear(); animation.frames.clear();
do do
{ {
@@ -56,17 +55,17 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string
{ {
if (line.substr(0, pos) == "name") 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") 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") 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") 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); const auto num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
rect.x = (num_tile % frames_per_row) * frame_width; rect.x = (num_tile % frames_per_row) * frame_width;
rect.y = (num_tile / frames_per_row) * frame_height; 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]"); } while (line != "[/animation]");
// Añade la animación al vector de animaciones // 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 // 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 #endif
} }
return af; return animations;
} }
// Constructor // 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), : MovingSprite(texture),
current_animation_(0) current_animation_(0)
{ {
// Carga las animaciones // Carga las animaciones
if (!file.empty()) if (!file_path.empty())
{ {
AnimatedFile as = loadAnimationFromFile(texture, file); animations_ = loadAnimationFromFile(texture, file_path);
// Copia los datos de las animaciones
std::copy(as.animations.begin(), as.animations.end(), std::back_inserter(animations_));
} }
}
else if (buffer) AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, std::vector<std::string> *animations)
: MovingSprite(texture),
current_animation_(0)
{
if (animations)
{ {
loadFromVector(buffer); loadFromVector(animations);
} }
} }
// Constructor // Constructor
AnimatedSprite::AnimatedSprite(const AnimatedFile *animation) AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture)
: MovingSprite(animation->texture), : MovingSprite(texture),
current_animation_(0) current_animation_(0) {}
{
// Copia los datos de las animaciones
std::copy(animation->animations.begin(), animation->animations.end(), std::back_inserter(animations_));
}
// Destructor // Destructor
AnimatedSprite::~AnimatedSprite() 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 // Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]") if (line == "[animation]")
{ {
Animation buffer; Animation animation;
buffer.counter = 0; animation.counter = 0;
buffer.current_frame = 0; animation.current_frame = 0;
buffer.completed = false; animation.completed = false;
buffer.name.clear(); animation.name.clear();
buffer.speed = 5; animation.speed = 5;
buffer.loop = 0; animation.loop = 0;
buffer.frames.clear(); animation.frames.clear();
do do
{ {
@@ -379,17 +376,17 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
{ {
if (line.substr(0, pos) == "name") 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") 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") 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") 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); const int num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp);
rect.x = (num_tile % frames_per_row) * frame_width; rect.x = (num_tile % frames_per_row) * frame_width;
rect.y = (num_tile / frames_per_row) * frame_height; 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]"); } while (line != "[/animation]");
// Añade la animación al vector de animaciones // 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 // 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 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 // 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 class AnimatedSprite : public MovingSprite
{ {
@@ -35,16 +29,20 @@ protected:
std::vector<Animation> animations_; // Vector con las diferentes animaciones std::vector<Animation> animations_; // Vector con las diferentes animaciones
int current_animation_; // Animacion activa int current_animation_; // Animacion activa
// Calcula el frame correspondiente a la animación actual
void animate();
public: public:
// Constructor // Constructor
explicit AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, const std::string &file = std::string(), std::vector<std::string> *buffer = nullptr); AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
explicit AnimatedSprite(const AnimatedFile *animation); AnimatedSprite(std::shared_ptr<Texture> texture, std::vector<std::string> *animations);
explicit AnimatedSprite(std::shared_ptr<Texture> texture);
// Destructor // Destructor
virtual ~AnimatedSprite(); virtual ~AnimatedSprite();
// Calcula el frame correspondiente a la animación actual // Actualiza las variables del objeto
void animate(); void update() override;
// Obtiene el número de frames de la animación actual // Obtiene el número de frames de la animación actual
int getNumFrames(); int getNumFrames();
@@ -84,9 +82,6 @@ public:
void setCurrentAnimation(const std::string &name = "default"); void setCurrentAnimation(const std::string &name = "default");
void setCurrentAnimation(int index = 0); void setCurrentAnimation(int index = 0);
// Actualiza las variables del objeto
void update() override;
// OLD - Establece el rectangulo para un frame de una animación // 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); void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);

View File

@@ -1,12 +1,12 @@
#include "background.h" #include "background.h"
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888 #include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <algorithm> // for clamp, max #include <algorithm> // for clamp, max
#include "asset.h" // for Asset #include "asset.h" // for Asset
#include "moving_sprite.h" // for MovingSprite #include "moving_sprite.h" // for MovingSprite
#include "param.h" // for param #include "param.h" // for param
#include "sprite.h" // for Sprite #include "sprite.h" // for Sprite
#include "texture.h" // for Texture #include "texture.h" // for Texture
// Constructor // Constructor
Background::Background(SDL_Renderer *renderer) Background::Background(SDL_Renderer *renderer)
@@ -19,55 +19,71 @@ Background::Background(SDL_Renderer *renderer)
{ {
// Inicializa variables // Inicializa variables
gradient_number_ = 0;
alpha_ = 0;
clouds_speed_ = 0;
transition_ = 0;
counter_ = 0;
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.attenuate_color.r, param.background.attenuate_color.g, param.background.attenuate_color.b};
alpha_color_text_ = alpha_color_text_temp_ = param.background.attenuate_alpha;
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 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)
{ {
top_clouds_rect_[i] = {0, i * top_clouds_texture_height, top_clouds_texture_->getWidth(), top_clouds_texture_height}; gradient_number_ = 0;
bottom_clouds_rect_[i] = {0, i * bottom_clouds_texture_height, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_height}; alpha_ = 0;
clouds_speed_ = 0;
transition_ = 0;
counter_ = 0;
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.attenuate_color.r, param.background.attenuate_color.g, param.background.attenuate_color.b};
alpha_color_text_ = alpha_color_text_temp_ = param.background.attenuate_alpha;
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 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)
{
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 // Crea los sprites
const int top_clouds_y = base_ - 165; {
const int bottom_clouds_y = base_ - 101; const int top_clouds_y = base_ - 165;
constexpr float top_clouds_speed = 0.1f; const int bottom_clouds_y = base_ - 101;
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_); top_clouds_sprite_a_ = std::make_unique<MovingSprite>(top_clouds_texture_, (SDL_Rect){0, top_clouds_y, rect_.w, top_clouds_texture_->getHeight()});
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_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_); bottom_clouds_sprite_a_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_Rect){0, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight()});
gradient_sprite_ = std::make_unique<Sprite>(0, 0, rect_.w, rect_.h, gradients_texture_); bottom_clouds_sprite_b_ = std::make_unique<MovingSprite>(bottom_clouds_texture_, (SDL_Rect){rect_.w, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight()});
grass_sprite_ = std::make_unique<Sprite>(0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2, grass_texture_);
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 // Inicializa objetos
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()); constexpr float top_clouds_speed = 0.1f;
bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight()); constexpr float bottom_clouds_speed = 0.05f;
bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight());
buildings_sprite_->setPosY(base_ - buildings_sprite_->getHeight()); top_clouds_sprite_a_->setVelX(-top_clouds_speed);
grass_sprite_->setPosY(base_ - grass_sprite_->getHeight()); 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 // Crea la textura para componer el fondo
canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h); 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); bottom_clouds_sprite_b_->setVelX(clouds_speed_ / 2);
// Mueve las nubes // Mueve las nubes
top_clouds_sprite_a_->move(); top_clouds_sprite_a_->update();
top_clouds_sprite_b_->move(); top_clouds_sprite_b_->update();
bottom_clouds_sprite_a_->move(); bottom_clouds_sprite_a_->update();
bottom_clouds_sprite_b_->move(); bottom_clouds_sprite_b_->update();
// Calcula el offset de las nubes // Calcula el offset de las nubes
if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth()) if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth())

View File

@@ -1,9 +1,9 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture #include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
#include <memory> // for unique_ptr, shared_ptr #include <memory> // for unique_ptr, shared_ptr
#include "utils.h" // for Color #include "utils.h" // for Color
class MovingSprite; class MovingSprite;
class Sprite; class Sprite;
class Texture; class Texture;

View File

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

View File

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

View File

@@ -12,7 +12,7 @@ constexpr int BULLET_VELX_RIGHT = 2;
// Constructor // Constructor
Bullet::Bullet(int x, int y, BulletType kind, bool powered_up, int owner, SDL_Rect *play_area, std::shared_ptr<Texture> texture) 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_x_(x),
pos_y_(y), pos_y_(y),
width_(BULLET_WIDTH), width_(BULLET_WIDTH),

View File

@@ -55,6 +55,10 @@ Director::Director(int argc, const char *argv[])
section::name = section::Name::LOGO; section::name = section::Name::LOGO;
#endif #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 // Comprueba los parametros del programa
checkProgramArguments(argc, argv); checkProgramArguments(argc, argv);

View File

@@ -1,6 +1,6 @@
#include "explosions.h" #include "explosions.h"
#include <utility> // for move #include <utility> // for move
#include "animated_sprite.h" // for AnimatedSprite #include "animated_sprite.h" // for SpriteAnimated
class Texture; // lines 3-3 class Texture; // lines 3-3
// Constructor // 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) void Explosions::add(int x, int y, int size)
{ {
const int index = getIndexBySize(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); sprite->setPos(x, y);
explosions_.push_back(std::move(sprite)); explosions_.push_back(std::move(sprite));
} }

View File

@@ -1,8 +1,8 @@
#pragma once #pragma once
#include <memory> // for shared_ptr, unique_ptr #include <memory> // for shared_ptr, unique_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
class AnimatedSprite; class AnimatedSprite;
class Texture; class Texture;

View File

@@ -32,7 +32,7 @@
#include "scoreboard.h" // for Scoreboard, ScoreboardMode, SCOREB... #include "scoreboard.h" // for Scoreboard, ScoreboardMode, SCOREB...
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "section.h" // for Name, name, Options, options #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 "text.h" // for Text, TEXT_CENTER
#include "texture.h" // for Texture #include "texture.h" // for Texture
struct JA_Music_t; // lines 35-35 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) void Game::createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture)
{ {
smart_sprites_.emplace_back(std::make_unique<SmartSprite>(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 // Vacia el vector de smartsprites
void Game::freeSmartSprites() void Game::freeSpriteSmarts()
{ {
if (!smart_sprites_.empty()) 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) void Game::throwCoffee(int x, int y)
{ {
smart_sprites_.emplace_back(std::make_unique<SmartSprite>(item_textures_[4])); 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()->setEnabled(true);
smart_sprites_.back()->setFinishedCounter(1); 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()->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()->setRotateSpeed(10);
smart_sprites_.back()->setRotateAmount(90.0); smart_sprites_.back()->setRotateAmount(90.0);
} }
// Actualiza los SmartSprites // Actualiza los SpriteSmarts
void Game::updateSmartSprites() void Game::updateSpriteSmarts()
{ {
for (auto &ss : smart_sprites_) for (auto &ss : smart_sprites_)
{ {
@@ -1478,8 +1478,8 @@ void Game::updateSmartSprites()
} }
} }
// Pinta los SmartSprites activos // Pinta los SpriteSmarts activos
void Game::renderSmartSprites() void Game::renderSpriteSmarts()
{ {
for (auto &ss : smart_sprites_) for (auto &ss : smart_sprites_)
{ {
@@ -1679,8 +1679,8 @@ void Game::update()
// Actualiza el estado de muerte // Actualiza el estado de muerte
updateGameOver(); updateGameOver();
// Actualiza los SmartSprites // Actualiza los SpriteSmarts
updateSmartSprites(); updateSpriteSmarts();
// Actualiza los contadores de estado y efectos // Actualiza los contadores de estado y efectos
updateTimeStoppedCounter(); updateTimeStoppedCounter();
@@ -1708,7 +1708,7 @@ void Game::update()
freeBullets(); freeBullets();
freeBalloons(); freeBalloons();
freeItems(); freeItems();
freeSmartSprites(); freeSpriteSmarts();
} }
// Comprueba si la música ha de estar sonando // Comprueba si la música ha de estar sonando
@@ -1757,7 +1757,7 @@ void Game::fillCanvas()
// Dibuja los objetos // Dibuja los objetos
background_->render(); background_->render();
renderItems(); renderItems();
renderSmartSprites(); renderSpriteSmarts();
explosions_->render(); explosions_->render();
renderBalloons(); renderBalloons();
renderBullets(); renderBullets();

View File

@@ -133,8 +133,8 @@ private:
std::vector<std::shared_ptr<Texture>> player2_textures_; // Vector con las texturas del jugador std::vector<std::shared_ptr<Texture>> player2_textures_; // Vector con las texturas del jugador
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures_; // Vector con todas las texturas de los jugadores; 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<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> *> item_animations_; // Vector con las animaciones de los items
std::vector<std::vector<std::string> *> player_animations_; // Vector con las animaciones del jugador std::vector<std::vector<std::string> *> player_animations_; // Vector con las animaciones del jugador
@@ -321,20 +321,20 @@ private:
// Vacia el vector de items // Vacia el vector de items
void freeItems(); void freeItems();
// Crea un objeto SmartSprite // Crea un objeto SpriteSmart
void createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture); void createItemScoreSprite(int x, int y, std::shared_ptr<Texture> texture);
// Vacia el vector de smartsprites // 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); void throwCoffee(int x, int y);
// Actualiza los SmartSprites // Actualiza los SpriteSmarts
void updateSmartSprites(); void updateSpriteSmarts();
// Pinta los SmartSprites activos // Pinta los SpriteSmarts activos
void renderSmartSprites(); void renderSpriteSmarts();
// Acciones a realizar cuando el jugador muere // Acciones a realizar cuando el jugador muere
void killPlayer(std::shared_ptr<Player> &player); void killPlayer(std::shared_ptr<Player> &player);

View File

@@ -1,12 +1,12 @@
#include "game_logo.h" #include "game_logo.h"
#include <SDL2/SDL_render.h> // for SDL_FLIP_HORIZONTAL #include <SDL2/SDL_render.h> // for SDL_FLIP_HORIZONTAL
#include <algorithm> // for max #include <algorithm> // for max
#include "animated_sprite.h" // for AnimatedSprite #include "animated_sprite.h" // for SpriteAnimated
#include "asset.h" // for Asset #include "asset.h" // for Asset
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_PlaySound #include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_PlaySound
#include "param.h" // for param #include "param.h" // for param
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "smart_sprite.h" // for SmartSprite #include "smart_sprite.h" // for SpriteSmart
#include "sprite.h" // for Sprite #include "sprite.h" // for Sprite
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "utils.h" // for Param, ParamGame, ParamTitle #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_)), coffee_sprite_(std::make_unique<SmartSprite>(coffee_texture_)),
crisis_sprite_(std::make_unique<SmartSprite>(crisis_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())), crash_sound_(JA_LoadSound(Asset::get()->get("title.wav").c_str())),

View File

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

View File

@@ -1,22 +1,22 @@
#include "intro.h" #include "intro.h"
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_QUIT, SDL... #include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_QUIT, SDL...
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED #include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
#include <utility> // for move #include <utility> // for move
#include "asset.h" // for Asset #include "asset.h" // for Asset
#include "global_inputs.h" // for check #include "global_inputs.h" // for check
#include "input.h" // for Input #include "input.h" // for Input
#include "jail_audio.h" // for JA_StopMusic, JA_PlayMusic #include "jail_audio.h" // for JA_StopMusic, JA_PlayMusic
#include "lang.h" // for getText #include "lang.h" // for getText
#include "param.h" // for param #include "param.h" // for param
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "section.h" // for Name, name, Options, options #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 "text.h" // for Text
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "utils.h" // for Param, ParamGame, Zone, BLOCK, Color #include "utils.h" // for Param, ParamGame, Zone, BLOCK, Color
#include "writer.h" // for Writer #include "writer.h" // for Writer
struct JA_Music_t; // lines 19-19 struct JA_Music_t; // lines 19-19
// Constructor // Constructor
Intro::Intro(JA_Music_t *music) Intro::Intro(JA_Music_t *music)

View File

@@ -1,13 +1,13 @@
#pragma once #pragma once
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8 #include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
#include <memory> // for unique_ptr, shared_ptr #include <memory> // for unique_ptr, shared_ptr
#include <vector> // for vector #include <vector> // for vector
#include "smart_sprite.h" // for SmartSprite #include "smart_sprite.h" // for SpriteSmart
#include "writer.h" // for Writer #include "writer.h" // for Writer
class Text; class Text;
class Texture; class Texture;
struct JA_Music_t; // lines 11-11 struct JA_Music_t; // lines 11-11
/* /*
Esta clase gestiona un estado del programa. Se encarga de mostrar la secuencia Esta clase gestiona un estado del programa. Se encarga de mostrar la secuencia

View File

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

View File

@@ -5,7 +5,7 @@
#include <memory> // for shared_ptr, unique_ptr #include <memory> // for shared_ptr, unique_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
#include "animated_sprite.h" // for AnimatedSprite #include "animated_sprite.h" // for SpriteAnimated
#include "utils.h" // for Circle #include "utils.h" // for Circle
class Texture; class Texture;
@@ -38,7 +38,7 @@ private:
float accel_x_; // Aceleración en el eje X float accel_x_; // Aceleración en el eje X
float accel_y_; // Aceleración en el eje Y float accel_y_; // Aceleración en el eje Y
bool floor_collision_; // Indica si el objeto colisiona con el suelo bool floor_collision_; // Indica si el objeto colisiona con el suelo
ItemType type_; // Especifica el tipo de objeto que es ItemType type_; // Especifica el tipo de objeto que es
bool enabled_; // Especifica si el objeto está habilitado bool enabled_; // Especifica si el objeto está habilitado
Circle collider_; // Circulo de colisión del objeto Circle collider_; // Circulo de colisión del objeto
SDL_Rect *play_area_; // Rectangulo con la zona de juego SDL_Rect *play_area_; // Rectangulo con la zona de juego

View File

@@ -1,18 +1,18 @@
#include "logo.h" #include "logo.h"
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_QUIT, SDL... #include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_QUIT, SDL...
#include <SDL2/SDL_render.h> // for SDL_Renderer #include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED #include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
#include <utility> // for move #include <utility> // for move
#include "asset.h" // for Asset #include "asset.h" // for Asset
#include "global_inputs.h" // for check #include "global_inputs.h" // for check
#include "input.h" // for Input #include "input.h" // for Input
#include "jail_audio.h" // for JA_StopMusic #include "jail_audio.h" // for JA_StopMusic
#include "param.h" // for param #include "param.h" // for param
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "section.h" // for Name, name, Options, options #include "section.h" // for Name, name, Options, options
#include "sprite.h" // for Sprite #include "sprite.h" // for Sprite
#include "texture.h" // for Texture #include "texture.h" // for Texture
// Constructor // Constructor
Logo::Logo() Logo::Logo()
@@ -23,7 +23,7 @@ Logo::Logo()
// Reserva memoria para los punteros // Reserva memoria para los punteros
jail_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames.png")); 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_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 // Inicializa variables
counter_ = 0; counter_ = 0;
@@ -38,7 +38,7 @@ Logo::Logo()
// Crea los sprites de cada linea // Crea los sprites de cada linea
for (int i = 0; i < jail_texture_->getHeight(); ++i) 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); temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3); const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
temp->setPosX(posX); temp->setPosX(posX);
@@ -115,12 +115,12 @@ void Logo::updateJAILGAMES()
{ {
for (int i = 0; i < (int)jail_sprite_.size(); ++i) 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) if (i % 2 == 0)
{ {
jail_sprite_[i]->incPosX(-SPEED); 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); jail_sprite_[i]->setPosX(dest_.x);
} }
@@ -128,7 +128,7 @@ void Logo::updateJAILGAMES()
else else
{ {
jail_sprite_[i]->incPosX(SPEED); 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); jail_sprite_[i]->setPosX(dest_.x);
} }

View File

@@ -2,34 +2,26 @@
#include "texture.h" // for Texture #include "texture.h" // for Texture
// Constructor // Constructor
MovingSprite::MovingSprite(float x, float y, int w, int h, float vx, float vy, float ax, float ay, std::shared_ptr<Texture> texture) MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip)
: Sprite((int)x, (int)y, w, h, texture), : Sprite(texture, pos),
x_(x), rotate_(rotate),
y_(y), zoom_w_(zoom_w),
vx_(vx), zoom_h_(zoom_h),
vy_(vy), flip_(flip) {}
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;
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) MovingSprite::MovingSprite(std::shared_ptr<Texture> texture)
: Sprite(texture) : Sprite(texture),
{ rotate_({false, 0, 0, 0.0f, 0.0f, nullptr}),
clear(); zoom_w_(1.0f),
}; zoom_h_(1.0f),
flip_(SDL_FLIP_NONE) {}
// Reinicia todas las variables // Reinicia todas las variables
void MovingSprite::clear() void MovingSprite::clear()
@@ -43,16 +35,15 @@ void MovingSprite::clear()
ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad 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 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_.enabled = false; // Indica si ha de rotar
rotate_.counter = 0; // Contador
rotate_.speed = 0; // Velocidad de giro rotate_.speed = 0; // Velocidad de giro
rotate_.angle = 0.0f; // Angulo para dibujarlo rotate_.angle = 0.0f; // Angulo para dibujarlo
rotate_.amount = 0.0f; // Cantidad de grados a girar en cada iteración rotate_.amount = 0.0f; // Cantidad de grados a girar en cada iteración
rotate_.center = nullptr; // Centro de rotació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 flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
@@ -70,10 +61,135 @@ void MovingSprite::move()
vy_ += ay_; vy_ += ay_;
} }
// Actualiza las variables internas del objeto
void MovingSprite::update()
{
move();
rotate();
}
// Muestra el sprite por pantalla // Muestra el sprite por pantalla
void MovingSprite::render() 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 // Obtiene el valor de la variable
@@ -112,24 +228,6 @@ float MovingSprite::getAccelY() const
return ay_; 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 // Establece la posición y_ el tamaño del objeto
void MovingSprite::setPos(SDL_Rect rect) void MovingSprite::setPos(SDL_Rect rect)
{ {
@@ -186,120 +284,3 @@ void MovingSprite::setAccelY(float value)
{ {
ay_ = 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

@@ -1,25 +1,27 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point #include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // for SDL_RendererFlip #include <SDL2/SDL_render.h> // for SDL_RendererFlip
#include <SDL2/SDL_stdinc.h> // for Uint16 #include <SDL2/SDL_stdinc.h> // for Uint16
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
#include "sprite.h" // for Sprite #include "sprite.h" // for Sprite
class Texture; 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 class MovingSprite : public Sprite
{ {
protected: public:
struct Rotate struct Rotate
{ {
bool enabled; // Indica si ha de rotar bool enabled; // Indica si ha de rotar
int counter; // Contador
int speed; // Velocidad de giro 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 float amount; // Cantidad de grados a girar en cada iteración
SDL_Point *center; // Centro de rotación SDL_Point *center; // Centro de rotación
}; };
protected:
float x_; // Posición en el eje X float x_; // Posición en el eje X
float y_; // Posición en el eje Y 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 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 float ay_; // Aceleración en el eje Y. Variación de la velocidad
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 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
SDL_RendererFlip flip_; // Indica como se voltea el sprite SDL_RendererFlip flip_; // Indica como se voltea el sprite
public: // Incrementa el valor del ángulo
// Constructor void updateAngle();
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;
// Mueve el sprite // Mueve el sprite
void move(); void move();
@@ -50,6 +45,15 @@ public:
// Rota el sprite // Rota el sprite
void rotate(); 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 // Actualiza las variables internas del objeto
virtual void update(); virtual void update();
@@ -59,45 +63,28 @@ public:
// Muestra el sprite por pantalla // Muestra el sprite por pantalla
void render() override; void render() override;
// Obten el valor de la variable // Obtiene la variable
float getPosX() const; float getPosX() const;
float getPosY() const; float getPosY() const;
// Obten el valor de la variable
float getVelX() const; float getVelX() const;
float getVelY() const; float getVelY() const;
// Obten el valor de la variable
float getAccelX() const; float getAccelX() const;
float getAccelY() 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 // Obten el valor de la variable
float getZoomW() const; float getZoomW() const;
float getZoomH() const; float getZoomH() const;
// Obten el valor de la variable // Obten el valor de la variable
float getAngle() const; bool isRotating() const;
bool getRotate() const; double getAngle() const;
Uint16 getRotateSpeed() const; int 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);
// Establece el valor de la variable // Establece el valor de la variable
void setZoomW(float value); void setZoomW(float value);
@@ -105,17 +92,15 @@ public:
// Establece el valor de la variable // Establece el valor de la variable
void setAngle(double vaue); 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 // Establece el valor de la variable
void setRotate(bool value);
void setRotateSpeed(int value); void setRotateSpeed(int value);
void setRotateAmount(double 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 // Cambia el sentido de la rotación
void switchRotate(); void switchRotate();
@@ -128,5 +113,15 @@ public:
// Obtiene el valor de la variable // Obtiene el valor de la variable
SDL_RendererFlip getFlip(); 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 // Dibuja el icono de la notificación
if (has_icons_ && icon >= 0 && num_texts == 2) 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->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->setSpriteClip({icon_size * (icon % 10), icon_size * (icon / 10), icon_size, icon_size});
sp->render(); sp->render();
@@ -299,7 +299,7 @@ void Notifier::showText(std::string text1, std::string text2, int icon, std::str
SDL_SetRenderTarget(renderer_, nullptr); SDL_SetRenderTarget(renderer_, nullptr);
// Crea el sprite de la notificación // 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 // Deja la notificación invisible
n.texture->setAlpha(0); 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")); auto controllersTexture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get("controllers.png"));
// Crea el sprite para dibujar los gráficos // 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 // Borra la textura
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);

View File

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

View File

@@ -5,7 +5,8 @@
#include <memory> // for unique_ptr, shared_ptr #include <memory> // for unique_ptr, shared_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #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 "enter_name.h" // for EnterName
#include "utils.h" // for Circle #include "utils.h" // for Circle
class Texture; class Texture;
@@ -42,10 +43,10 @@ class Player
{ {
private: private:
// Objetos y punteros // Objetos y punteros
std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador
std::unique_ptr<AnimatedSprite> power_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope std::unique_ptr<AnimatedSprite> power_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope
std::unique_ptr<EnterName> enter_name_; // Clase utilizada para introducir el nombre std::unique_ptr<EnterName> enter_name_; // Clase utilizada para introducir el nombre
SDL_Rect *play_area_; // Rectangulo con la zona de juego SDL_Rect *play_area_; // Rectangulo con la zona de juego
// Variables // Variables
int id_; // Numero de identificación para el jugador int id_; // Numero de identificación para el jugador

View File

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

View File

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

View File

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

View File

@@ -15,25 +15,25 @@ protected:
public: public:
// Constructor // Constructor
explicit Sprite(int x = 0, int y = 0, int w = 0, int h = 0, std::shared_ptr<Texture> texture = nullptr); Sprite(std::shared_ptr<Texture>, int x, int y, int w, int h);
explicit Sprite(SDL_Rect rect, std::shared_ptr<Texture> texture = nullptr); Sprite(std::shared_ptr<Texture>, SDL_Rect rect);
explicit Sprite(std::shared_ptr<Texture> texture = nullptr); explicit Sprite(std::shared_ptr<Texture>);
// Destructor // Destructor
virtual ~Sprite() = default; ~Sprite() = default;
// Muestra el sprite por pantalla // Muestra el sprite por pantalla
virtual void render(); virtual void render();
// Obten el valor de la variable // Obten el valor de la variable
int getIntPosX() const; int getPosX() const;
int getIntPosY() const; int getPosY() const;
int getWidth() const; int getWidth() const;
int getHeight() const; int getHeight() const;
// Devuelve el rectangulo donde está el sprite // Devuelve el rectangulo donde está el sprite
virtual SDL_Rect getPos() const; SDL_Rect getPos() const;
// Establece el valor de la variable // Establece el valor de la variable
void setPosX(int x); void setPosX(int x);
void setPosY(int y); void setPosY(int y);
@@ -43,7 +43,7 @@ public:
// Establece la posición del objeto // Establece la posición del objeto
void setPos(int x, int y); void setPos(int x, int y);
void setPos(SDL_Point p); void setPos(SDL_Point p);
virtual void setPos(SDL_Rect r); void setPos(SDL_Rect r);
// Incrementa el valor de la variable // Incrementa el valor de la variable
void incPosX(int value); 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 // Crea los objetos
texture_ = std::make_shared<Texture>(renderer, bitmap_file); 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 // Inicializa variables
fixed_width_ = false; fixed_width_ = false;
@@ -122,7 +122,7 @@ Text::Text(const std::string &text_file, std::shared_ptr<Texture> texture)
} }
// Crea los objetos // 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 // Inicializa variables
fixed_width_ = false; fixed_width_ = false;
@@ -142,7 +142,7 @@ Text::Text(TextFile *text_file, std::shared_ptr<Texture> texture)
} }
// Crea los objetos // 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 // Inicializa variables
fixed_width_ = false; fixed_width_ = false;

View File

@@ -60,7 +60,7 @@ void Tiledbg::fillTexture()
{ {
// Crea los objetos para pintar en la textura de fondo // Crea los objetos para pintar en la textura de fondo
auto bg_tile_texture = std::make_shared<Texture>(renderer_, texture_path_); 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 // Prepara para dibujar sobre la textura
auto temp = SDL_GetRenderTarget(renderer_); 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); 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_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); 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);