From 57123d6b8a73e93bfae5ad240c4cdd6a47c994b2 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 26 Jun 2025 21:13:51 +0200 Subject: [PATCH] =?UTF-8?q?Bullet:=20ara=20tenen=20animaci=C3=B3=20de=20tr?= =?UTF-8?q?es=20frames,=20encara=20que=20no=20es=20nota=20una=20puta=20mer?= =?UTF-8?q?da?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/config/param_320x240.txt | 2 +- data/config/param_320x256.txt | 2 +- data/gfx/bullet/bullet.ani | 44 ++++++++++++++++++++++++++++++++++ data/gfx/bullet/bullet.png | Bin 858 -> 2016 bytes source/bullet.cpp | 38 +++++++++++++++++++++++------ source/bullet.h | 15 ++++++------ source/director.cpp | 1 + source/game.cpp | 9 ++----- source/game.h | 1 - 9 files changed, 88 insertions(+), 24 deletions(-) create mode 100644 data/gfx/bullet/bullet.ani 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 35d006d2dd4baf58f8ec34b2b14c1da91564bf54..2e74a72c19076306f77dd28327b53ebe745bfe1d 100644 GIT binary patch literal 2016 zcmV<62Os!}P)Px+nn^@KRA_^aq<>&gD8bSeL_w;-s5gQ-w#KPbqa`Y*R-))UP zP4FPB5VEceZ68Lgg*$L#F{*v|<}$Rej_UetxYz{W*$VBwFHs2xVj-SrgJ7fpUW)Pm6vW?(@u$skWb#djjv$L* zCP&iq|7(7bBI~%gax-_4utMm>#l-dId>t2K*HZja>RZxG#~RqWhpcUOhBVXJ2fOzb z;K$8$^~0e9DSk;hcP1nz=5N7&G`};&n98-dRN9Qnb^9=Muj-^ zjYWcyn4ge|-TQ1*h(ljg{De##I$&c%-1=ODV1yw0!iKf(&iv)~uwkujMqK)z@qc6c zNAAx2;kOZ1Pq_4rn7?{75zAUa~+SzIkYAR05D`%wh$%N}0 zVTCYPrYyckCe6?GAuUtGZ+PYb*D^h7!r$5I%5=x&J3bVQ5M;^Z8^H)cmQ1<)44E8G z7Wg{jBkk0$d1QyH_)>iJX_`;sOYzmGDPMdkzWR8dp|C>8);-pf#J%%=eD^-&nrrPJ4+EaO5+u zyWW+~J{uw6$Y)-6y(?Y)HbTJ47gh*)CvNpE)s%!R*j*DxUl;S2s-`4l!S0$k`sSGb zZPk>7EZAKelbfq}ju_&VoA~4dtmlX!PF%+)A7DL43~}rlKKblJElu56j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*OV8)nwMi(r#4kbFY$3qoe$ zE{j>2A8;eC1i_WD3AmVq5NH#fNz%HiSyXPNs=BHZEoi7db#C>&r|;N0HFS`y;7uNyTu#jApl?;_Y?bOv?9Gd;4ll` z1b5+yE08$31K{L`oui6#@6hw{?_I`M$?|QU+4!cqZPQuTy|EaB#!&;QXD|o#^^Q~6F=+R z`|ffdB}Nrt)tox3Q68dE9-{uREyV$ZZOm??m~q_Kxb=r^xevu;w1n548@9qtXDJQ< z{QUrSu(ayV0#i9R9k}d939mahZB@OUNpS#R5)W{;dnK)UwtIz1JkU7R+Zk+j%gCf> zPvW2g(r^-ogi||-gm_W7G^aJ{91>l#u}FF}?O`or^W+--}F5C2MD_X-@P4-<393U0oB`?g0*vt-OM*$6wUGW`i{5PcSO;AB~Hb=Y!&(eQ{Q6hxy^3ccMz+A!CMG0 z0pKYGS@48NX|{3=#ct-Fp&zj8>?xvXjwqVrI(sS$vf*ZInyp+zwVU-z8ulBxe{sT%o|8?uQ~&?~07*qoM6N<$f>~^jo&W#< 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