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 0000000..f858300 Binary files /dev/null and b/data/gfx/tabe/tabe.png differ 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