From 4e083a8cdbf38ec3f0fcaab07af22b875dd94b27 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 30 Sep 2025 14:16:25 +0200 Subject: [PATCH] =?UTF-8?q?item.cpp:=20afegida=20rotaci=C3=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/item.cpp | 14 ++++++++++---- source/item.h | 11 ++++++----- source/sections/game.cpp | 1 - 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/source/item.cpp b/source/item.cpp index 5ba48a7..ceff45c 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -9,7 +9,7 @@ class Texture; // lines 6-6 -Item::Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::shared_ptr &texture, const std::vector &animation) +Item::Item(ItemType type, float x, float y, SDL_FRect& play_area, const std::shared_ptr& texture, const std::vector& animation) : sprite_(std::make_unique(texture, animation)), play_area_(play_area), type_(type) { @@ -33,13 +33,17 @@ Item::Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::sha if (direction < 3) { // Velocidades negativas: -1.0, -0.66, -0.33 vel_x_ = -ITEM_VEL_X_BASE + (direction * ITEM_VEL_X_STEP); + rotate_speed_ = -720.0F; } else { // Velocidades positivas: 0.33, 0.66, 1.0 vel_x_ = ITEM_VEL_X_STEP + ((direction - 3) * ITEM_VEL_X_STEP); + rotate_speed_ = 720.0F; } vel_y_ = ITEM_VEL_Y; accel_y_ = ITEM_ACCEL_Y; collider_.r = width_ / 2; + sprite_->startRotate(); + sprite_->setRotateAmount(rotate_speed_); break; } } @@ -101,7 +105,8 @@ void Item::move(float deltaTime) { // Si toca el borde lateral if (pos_x_ == MIN_X || pos_x_ == MAX_X) { - vel_x_ = -vel_x_; // Invierte la velocidad horizontal + vel_x_ = -vel_x_; // Invierte la velocidad horizontal + sprite_->scaleRotateAmount(-1.0F); // Invierte la rotación } // Si colisiona por arriba, rebota (excepto la máquina de café) @@ -115,8 +120,9 @@ void Item::move(float deltaTime) { // Si colisiona con la parte inferior if (pos_y_ > play_area_.h - height_) { - // Corrige la posición - pos_y_ = play_area_.h - height_; + pos_y_ = play_area_.h - height_; // Corrige la posición + sprite_->scaleRotateAmount(0.5F); // Reduce la rotación + sprite_->stopRotate(300.0F); // Detiene la rotacion switch (type_) { case ItemType::COFFEE_MACHINE: diff --git a/source/item.h b/source/item.h index 1a40800..7051ea8 100644 --- a/source/item.h +++ b/source/item.h @@ -78,14 +78,15 @@ class Item { SDL_FRect play_area_; // Rectángulo con la zona de juego Circle collider_; // Círculo de colisión del objeto ItemType type_; // Tipo de objeto - float pos_x_; // Posición X del objeto - float pos_y_; // Posición Y del objeto - float vel_x_; // Velocidad en el eje X - float vel_y_; // Velocidad en el eje Y + float pos_x_ = 0.0F; // Posición X del objeto + float pos_y_ = 0.0F; // Posición Y del objeto + float vel_x_ = 0.0F; // Velocidad en el eje X + float vel_y_ = 0.0F; // Velocidad en el eje Y float accel_x_ = 0.0F; // Aceleración en el eje X - float accel_y_; // Aceleración en el eje Y + float accel_y_ = 0.0F; // Aceleración en el eje Y float width_ = WIDTH; // Ancho del objeto float height_ = HEIGHT; // Alto del objeto + float rotate_speed_ = 0.0F; // Velocidad de rotacion float lifetime_timer_ = 0.0f; // Acumulador de tiempo de vida del ítem (segundos) bool floor_collision_ = false; // Indica si el objeto colisiona con el suelo bool enabled_ = true; // Indica si el objeto está habilitado diff --git a/source/sections/game.cpp b/source/sections/game.cpp index e599ebc..2867fd4 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -799,7 +799,6 @@ void Game::throwCoffee(int x, int y) { smart_sprites_.back()->setSpriteClip(0, Item::HEIGHT, Item::WIDTH, Item::HEIGHT); smart_sprites_.back()->setRotatingCenter({Item::WIDTH / 2, Item::HEIGHT / 2}); smart_sprites_.back()->setRotate(true); - smart_sprites_.back()->setRotateSpeed(10); smart_sprites_.back()->setRotateAmount(90.0); }