diff --git a/data/config/param_320x240.txt b/data/config/param_320x240.txt index 37edd5f..0201286 100644 --- a/data/config/param_320x240.txt +++ b/data/config/param_320x240.txt @@ -62,7 +62,7 @@ notification.color 303030 service_menu.title_color 99FF62 service_menu.text_color FFFFFF service_menu.selected_color FFDC44 -service_menu.bg_color 000000F0 +service_menu.bg_color 003000F5 service_menu.drop_shadow false ## --- INTRO --- diff --git a/data/config/param_320x256.txt b/data/config/param_320x256.txt index 66aef6b..8204e9a 100644 --- a/data/config/param_320x256.txt +++ b/data/config/param_320x256.txt @@ -62,7 +62,7 @@ notification.color 303030 service_menu.title_color 99FF62 service_menu.text_color FFFFFF service_menu.selected_color FFDC44 -service_menu.bg_color 000000F0 +service_menu.bg_color 000F00F5 service_menu.drop_shadow false ## --- INTRO --- diff --git a/data/gfx/bullet/bullet.ani b/data/gfx/bullet/bullet.ani new file mode 100644 index 0000000..b4daa26 --- /dev/null +++ b/data/gfx/bullet/bullet.ani @@ -0,0 +1,44 @@ +frame_width=12 +frame_height=12 + +[animation] +name=normal_up +speed=5 +loop=0 +frames=0,1,2,2,1,0 +[/animation] + +[animation] +name=normal_left +speed=5 +loop=0 +frames=3,4,5,5,4,3 +[/animation] + +[animation] +name=normal_right +speed=5 +loop=0 +frames=6,7,8,8,7,6 +[/animation] + +[animation] +name=powered_up +speed=5 +loop=0 +frames=9,10,11,11,10,9 +[/animation] + +[animation] +name=powered_left +speed=5 +loop=0 +frames=12,13,14,14,13,12 +[/animation] + +[animation] +name=powered_right +speed=5 +loop=0 +frames=15,16,17,17,26,15 +[/animation] \ No newline at end of file diff --git a/data/gfx/bullet/bullet.png b/data/gfx/bullet/bullet.png index 35d006d..2e74a72 100644 Binary files a/data/gfx/bullet/bullet.png and b/data/gfx/bullet/bullet.png differ diff --git a/source/bullet.cpp b/source/bullet.cpp index c6468d3..d16730c 100644 --- a/source/bullet.cpp +++ b/source/bullet.cpp @@ -3,11 +3,12 @@ #include // Para unique_ptr, make_unique, shared_ptr #include "param.h" // Para Param, ParamGame, param #include "sprite.h" // Para Sprite -class Texture; // lines 5-5 +#include "resource.h" +class Texture; // lines 5-5 // Constructor -Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered_up, int owner, std::shared_ptr texture) - : sprite_(std::make_unique(texture, SDL_FRect{x, y, BULLET_WIDTH_, BULLET_HEIGHT_})), +Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, int owner) + : sprite_(std::make_unique(Resource::get()->getTexture("bullet.png"), Resource::get()->getAnimation("bullet.ani"))), pos_x_(x), pos_y_(y), bullet_type_(bullet_type), @@ -17,9 +18,24 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered_up, int ow : (bullet_type_ == BulletType::RIGHT) ? BULLET_VEL_X_RIGHT_ : 0; - int sprite_offset = powered_up ? 3 : 0; - int offset = (static_cast(bullet_type) + sprite_offset) * BULLET_WIDTH_; - sprite_->setSpriteClip(offset, 0, BULLET_WIDTH_, BULLET_HEIGHT_); + std::string powered_type = powered ? "powered_" : "normal_"; + switch (bullet_type) + { + case BulletType::UP: + sprite_->setCurrentAnimation(powered_type + "up"); + break; + + case BulletType::LEFT: + sprite_->setCurrentAnimation(powered_type + "left"); + break; + + case BulletType::RIGHT: + sprite_->setCurrentAnimation(powered_type + "right"); + break; + + default: + break; + } collider_.r = BULLET_WIDTH_ / 2; shiftColliders(); @@ -28,7 +44,15 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered_up, int ow // Implementación de render (llama al render del sprite_) void Bullet::render() { - sprite_->render(); + if (bullet_type_ != BulletType::NONE) + sprite_->render(); +} + +// Actualiza el estado del objeto +BulletMoveStatus Bullet::update() +{ + sprite_->update(); + return move(); } // Implementación del movimiento usando BulletMoveStatus diff --git a/source/bullet.h b/source/bullet.h index 35ab636..d738b70 100644 --- a/source/bullet.h +++ b/source/bullet.h @@ -2,7 +2,7 @@ #include // Para Uint8 #include // Para shared_ptr, unique_ptr -#include "sprite.h" // Para Sprite +#include "animated_sprite.h" // Para AnimatedSprite #include "utils.h" // Para Circle class Texture; @@ -27,12 +27,12 @@ class Bullet { public: // Constructor y Destructor - Bullet(float x, float y, BulletType bullet_type, bool powered_up, int owner, std::shared_ptr texture); + Bullet(float x, float y, BulletType bullet_type, bool powered, int owner); ~Bullet() = default; // Métodos principales - void render(); // Dibuja la bala en pantalla - BulletMoveStatus move(); // Mueve la bala y devuelve su estado + void render(); // Dibuja la bala en pantalla + BulletMoveStatus update(); // Actualiza el estado del objeto // Estado de la bala bool isEnabled() const; // Comprueba si está activa @@ -51,7 +51,7 @@ private: static constexpr float BULLET_VEL_X_RIGHT_ = 2.0f; // Propiedades - std::unique_ptr sprite_; // Sprite con los gráficos + std::unique_ptr sprite_; // Sprite con los gráficos float pos_x_; // Posición en el eje X float pos_y_; // Posición en el eje Y @@ -62,6 +62,7 @@ private: Circle collider_; // Círculo de colisión // Métodos internos - void shiftColliders(); // Ajusta el círculo de colisión - void shiftSprite(); // Ajusta el sprite + void shiftColliders(); // Ajusta el círculo de colisión + void shiftSprite(); // Ajusta el sprite + BulletMoveStatus move(); // Mueve la bala y devuelve su estado }; diff --git a/source/director.cpp b/source/director.cpp index 19c161c..b24d10c 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -355,6 +355,7 @@ void Director::setFileList() { // Bala Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/bullet/bullet.ani", AssetType::ANIMATION); } { // Tabe diff --git a/source/game.cpp b/source/game.cpp index a08d759..a6e99b8 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -124,11 +124,6 @@ Game::~Game() // Asigna texturas y animaciones void Game::setResources() { - // Texturas - { - bullet_texture_ = Resource::get()->getTexture("bullet.png"); - } - // Texturas - Game_text { game_text_textures_.emplace_back(Resource::get()->getTexture("game_text_1000_points")); @@ -638,7 +633,7 @@ void Game::updateBullets() { for (auto &bullet : bullets_) { - if (bullet->move() == BulletMoveStatus::OUT) + if (bullet->update() == BulletMoveStatus::OUT) { getPlayer(bullet->getOwner())->decScoreMultiplier(); } @@ -656,7 +651,7 @@ void Game::renderBullets() void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner) { bullets_.emplace_back( - std::make_unique(x, y, kind, powered_up, owner, bullet_texture_)); + std::make_unique(x, y, kind, powered_up, owner)); } // Vacia el vector de balas diff --git a/source/game.h b/source/game.h index 9eacbde..eec3bee 100644 --- a/source/game.h +++ b/source/game.h @@ -118,7 +118,6 @@ private: std::vector> smart_sprites_; // Vector con los smartsprites std::vector> path_sprites_; // Vector con los pathsprites - std::shared_ptr bullet_texture_; // Textura para las balas std::vector> item_textures_; // Vector con las texturas de los items std::vector>> player_textures_; // Vector con todas las texturas de los jugadores