From d57cc15aeeaebe001907bb7df26e206ebb04c5d5 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 27 Dec 2024 13:38:07 +0100 Subject: [PATCH] Treballant en el enemic nou --- data/gfx/tabe/tabe.ani | 9 +++++++ data/gfx/tabe/tabe.png | Bin 0 -> 2113 bytes source/director.cpp | 5 ++++ source/game.cpp | 14 +++++++++-- source/game.h | 2 ++ source/logo.cpp | 1 - source/tabe.cpp | 55 +++++++++++++++++++++++++++++++++++++++++ source/tabe.h | 44 +++++++++++++++++++++++++++++++++ 8 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 data/gfx/tabe/tabe.ani create mode 100644 data/gfx/tabe/tabe.png create mode 100644 source/tabe.cpp create mode 100644 source/tabe.h diff --git a/data/gfx/tabe/tabe.ani b/data/gfx/tabe/tabe.ani new file mode 100644 index 0000000..08af04b --- /dev/null +++ b/data/gfx/tabe/tabe.ani @@ -0,0 +1,9 @@ +frame_width=32 +frame_height=32 + +[animation] +name=default +speed=2 +loop=0 +frames=0,1 +[/animation] diff --git a/data/gfx/tabe/tabe.png b/data/gfx/tabe/tabe.png new file mode 100644 index 0000000000000000000000000000000000000000..f85830006088543ded0741d696fccf0643f5fea2 GIT binary patch literal 2113 zcmV-H2)_4;P)Px+`$|IzSyxx2I zVRx^)hzsI0v=g5X?6Pyt^Z%d!^MB4g_rTNmdWU%22@bm^gWq+p=dtJi--catO1tKi z*F2qa>-P8L#mm)Fb2w$+GyfZ0G-=nI(qY$RXh8-Nw*Cy#91eNrMm-4Fw`V_FHm)Yx z6^AL!C&7N~uxoz73(M;fA% zfq&<8Pa21}>8sfU6-(_QG^#(q^lNXBnL1u0FM^!_== zt~uqI8+BnkR8 z*WO~=8$SdLK0jVS`kLjmRMmli?96050R^=lmJ0sfvkH6n?C0k@e~c6cOD2y+_clco zLDMvuf8!Ry6k!~it7{pPGyz{tJuhUYSnUB|qVU^&hr;q?JpUYdCr*-?m4RvVFL~+I zv3NXs1P2Jg&vyO*iR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lDuRpyw*!b8rr%ccO zsSFNwIAW#45i1>iXS{yx?FBTuUd7zQRsT3&^=yD zafdxN&{KMt&4Py?MSVab)P8+gaWL@}{~t+1eeWAf7?2XVkoWHOe#+}B1{>cB&Eb@h r>=GXzFGI&Z5!nAA{?m9GU&Hth+Df&lqQ9-G00000NkvXXu0mjf4Qk}4 literal 0 HcmV?d00001 diff --git a/source/director.cpp b/source/director.cpp index bbc31ca..0028988 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -451,6 +451,11 @@ void Director::setFileList() Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP); } + { // Tabe + Asset::get()->add(prefix + "/data/gfx/tabe/tabe.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/tabe/tabe.ani", AssetType::ANIMATION); + } + { // Juego Asset::get()->add(prefix + "/data/gfx/game/game_buildings.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_clouds1.png", AssetType::BITMAP); diff --git a/source/game.cpp b/source/game.cpp index 9e214a0..d63101b 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -32,6 +32,7 @@ #include "section.h" // Para Name, name, Options, options #include "smart_sprite.h" // Para SmartSprite #include "stage.h" // Para number, get, Stage, power, total_p... +#include "tabe.h" // Para Tabe #include "text.h" // Para Text #include "texture.h" // Para Texture struct JA_Sound_t; // lines 37-37 @@ -46,7 +47,8 @@ Game::Game(int player_id, int current_stage, bool demo) canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.play_area.rect.w, param.game.play_area.rect.h)), fade_in_(std::make_unique()), fade_out_(std::make_unique()), - balloon_manager_(std::make_unique()) + balloon_manager_(std::make_unique()), + tabe_(std::make_unique()) { // Pasa variables demo_.enabled = demo; @@ -942,6 +944,7 @@ void Game::fillCanvas() renderItems(); renderSmartSprites(); balloon_manager_->render(); + tabe_->render(); renderBullets(); renderPathSprites(); renderPlayers(); @@ -1207,6 +1210,12 @@ void Game::checkEvents() case SDLK_8: { players_.at(0)->setPlayingState(PlayerState::LEAVING_SCREEN); + break; + } + case SDLK_9: + { + tabe_->enable(); + break; } default: break; @@ -1373,7 +1382,7 @@ void Game::handleDemoMode() if (input_->checkAnyButtonPressed()) { - section::name = section::Name::TITLE; // Salir del modo demo y regresar al menú principal. + section::name = section::Name::TITLE; // Salir del modo demo y regresar al menú principal. section::attract_mode = section::AttractMode::TITLE_TO_DEMO; // El juego volverá a mostrar la demo return; } @@ -1805,6 +1814,7 @@ void Game::updateGame() updateScoreboard(); updateBackground(); balloon_manager_->update(); + tabe_->update(); moveBullets(); updateItems(); updateStage(); diff --git a/source/game.h b/source/game.h index 528f6d2..9237789 100644 --- a/source/game.h +++ b/source/game.h @@ -12,6 +12,7 @@ class Asset; // lines 13-13 class Background; // lines 14-14 class BalloonManager; +class Tabe; class Bullet; // lines 15-15 class Fade; // lines 16-16 class Input; // lines 17-17 @@ -144,6 +145,7 @@ private: std::unique_ptr fade_in_; // Objeto para renderizar fades std::unique_ptr fade_out_; // Objeto para renderizar fades std::unique_ptr balloon_manager_; // Objeto para gestionar los globos + std::unique_ptr tabe_; // Objeto para gestionar el Tabe Volaor std::vector paths_; // Vector con los recorridos precalculados almacenados // Variables diff --git a/source/logo.cpp b/source/logo.cpp index e93ca71..42fa3a5 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -234,7 +234,6 @@ void Logo::render() void Logo::run() { // Detiene la música - //JA_StopMusic(); JA_FadeOutMusic(500); while (section::name == section::Name::LOGO) diff --git a/source/tabe.cpp b/source/tabe.cpp new file mode 100644 index 0000000..a870125 --- /dev/null +++ b/source/tabe.cpp @@ -0,0 +1,55 @@ +#include "tabe.h" +#include "resource.h" +#include "param.h" +#include + +// Constructor +Tabe::Tabe() + : sprite_(std::make_unique(Resource::get()->getTexture("tabe.png"), Resource::get()->getAnimation("tabe.ani"))) +{ +} + +// Actualiza la lógica +void Tabe::update() +{ + if (enabled_) + { + sprite_->update(); + move(); + } +} + +// Dibuja el objeto +void Tabe::render() +{ + if (enabled_) + { + sprite_->render(); + } +} + +// Mueve el objeto +void Tabe::move() +{ + x_ += speed_; + const float min_x = param.game.game_area.rect.x; + const float max_x = param.game.game_area.rect.x + param.game.game_area.rect.w - WIDTH_; + if (x_ < min_x || x_ > max_x) + { + x_ = std::clamp(x_, min_x, max_x); + speed_ = -speed_; + sprite_->setFlip(speed_ > 0.0f ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE); + } + shiftSprite(); +} + +// Habilita el objeto +void Tabe::enable() +{ + enabled_ = true; + speed_ = 5.0f; + x_ = 50.0f; + y_ = 20.0f; + sprite_->setFlip(speed_ > 0.0f ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE); + shiftSprite(); +} \ No newline at end of file diff --git a/source/tabe.h b/source/tabe.h new file mode 100644 index 0000000..56d3ffb --- /dev/null +++ b/source/tabe.h @@ -0,0 +1,44 @@ +#pragma once + +#include "animated_sprite.h" +#include + +// Clase Tabe +class Tabe +{ +private: + // Constantes + static constexpr int WIDTH_ = 32; + static constexpr int HEIGHT_ = 32; + + // Punteros + std::unique_ptr sprite_; // Sprite con los graficos y animaciones + + // Variables + float x_; // Posición del objeto + float y_; // Posición del objeto + float speed_; // Velocidad de movimiento del objeto + bool enabled_ = false; // Indica si el objeto está activo + + // Mueve el objeto + void move(); + + // Actualiza la posición del sprite + void shiftSprite() { sprite_->setPos(x_, y_); } + +public: + // Constructor + Tabe(); + + // Destructor + ~Tabe() = default; + + // Actualiza la lógica + void update(); + + // Dibuja el objeto + void render(); + + // Habilita el objeto + void enable(); +}; \ No newline at end of file