From f39e65afafea8c0f407007efd944cb666fac9136 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 25 Jan 2025 18:47:06 +0100 Subject: [PATCH] =?UTF-8?q?Ja=20no=20se=20que=20he=20tocat=20i=20qu=C3=A9?= =?UTF-8?q?=20no,=20cosetes=20del=20malo=20nou?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/game.cpp | 13 ++++++++----- source/tabe.cpp | 11 +++++++---- source/tabe.h | 3 ++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/source/game.cpp b/source/game.cpp index 23bd482..a669990 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -774,7 +774,7 @@ void Game::createItemText(int x, std::shared_ptr texture) const auto h = texture->getHeight(); const int y0 = param.game.play_area.rect.h - h; - const int y1 = 155; + const int y1 = 160 - (h / 2); const int y2 = -h; // Ajusta para que no se dibuje fuera de pantalla @@ -1262,10 +1262,10 @@ void Game::checkEvents() createItem(ItemType::CLOCK, players_.at(0)->getPosX(), players_.at(0)->getPosY() - 40); break; } - case SDLK_5: // Crea un PathSprite + case SDLK_5: // 5.000 { const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2; - createItemText(x, game_text_textures_.at(3)); + createItemText(x, game_text_textures_.at(2)); break; } case SDLK_6: // Crea un mensaje @@ -1273,10 +1273,13 @@ void Game::checkEvents() createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready")); break; } - case SDLK_7: // Flash + case SDLK_7: // 100.000 { // screen_->flash(flash_color, 3); - tabe_->setState(TabeState::HIT); + // tabe_->setState(TabeState::HIT); + const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2; + createItemText(x, game_text_textures_.at(6)); + break; break; } case SDLK_8: diff --git a/source/tabe.cpp b/source/tabe.cpp index 08bcbc1..efb26ac 100644 --- a/source/tabe.cpp +++ b/source/tabe.cpp @@ -102,6 +102,8 @@ void Tabe::enable() { enabled_ = true; has_bonus_ = true; + hit_counter_ = 0; + number_of_hits_ = 0; y_ = param.game.game_area.rect.y + 20.0f; // Establece una dirección aleatoria @@ -164,7 +166,8 @@ void Tabe::setState(TabeState state) case TabeState::HIT: sprite_->setCurrentAnimation("hit"); - hit_counter = 5; + hit_counter_ = 5; + ++number_of_hits_; break; default: @@ -178,8 +181,8 @@ void Tabe::updateState() { if (state_ == TabeState::HIT) { - --hit_counter; - if (hit_counter == 0) + --hit_counter_; + if (hit_counter_ == 0) { setState(TabeState::FLY); } @@ -189,7 +192,7 @@ void Tabe::updateState() // Intenta obtener el bonus bool Tabe::tryToGetBonus() { - if (has_bonus_ && rand() % 8 == 0) + if (has_bonus_ && rand() % std::max(1, 10 - number_of_hits_) == 0) { has_bonus_ = false; return true; diff --git a/source/tabe.h b/source/tabe.h index ad81be4..6a93bb1 100644 --- a/source/tabe.h +++ b/source/tabe.h @@ -37,7 +37,8 @@ private: TabeDirection direction_; // Dirección del objeto TabeDirection destiny_; // Destino del objeto TabeState state_ = TabeState::FLY; // Estado - int hit_counter = 0; // Contador para el estado HIT + int hit_counter_ = 0; // Contador para el estado HIT + int number_of_hits_ = 0; // Cantidad de disparos que ha recibido bool has_bonus_ = true; // Indica si el Tabe aun tiene el bonus para soltar // Mueve el objeto