From 0c8b39cee763e07a241f77e69181f9d334448d5d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 17 Aug 2025 20:42:55 +0200 Subject: [PATCH] els items ja no tenen vel_x = 0 --- source/director.cpp | 2 +- source/item.cpp | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 3ec6c0c..180287c 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -41,7 +41,7 @@ Director::Director(int argc, std::span argv) { Section::name = Section::Name::GAME; Section::options = Section::Options::GAME_PLAY_1P; #elif _DEBUG - Section::name = Section::Name::TITLE; + Section::name = Section::Name::GAME; Section::options = Section::Options::GAME_PLAY_1P; #else // NORMAL GAME Section::name = Section::Name::LOGO; diff --git a/source/item.cpp b/source/item.cpp index 0350f25..9e990c4 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -9,9 +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) - : sprite_(std::make_unique(texture, animation)), - play_area_(play_area), - type_(type) { + : sprite_(std::make_unique(texture, animation)), play_area_(play_area), type_(type) { switch (type) { case ItemType::COFFEE_MACHINE: { width_ = COFFEE_MACHINE_WIDTH; @@ -29,7 +27,15 @@ Item::Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::sha height_ = param.game.item_size; pos_x_ = x; pos_y_ = y; - vel_x_ = -1.0F + ((rand() % 5) * 0.5F); + // 6 velocidades: 3 negativas (-1.0, -0.66, -0.33) y 3 positivas (0.33, 0.66, 1.0) + const int direction = rand() % 6; + if (direction < 3) { + // Velocidades negativas: -1.0, -0.66, -0.33 + vel_x_ = -1.0F + (direction * 0.33F); + } else { + // Velocidades positivas: 0.33, 0.66, 1.0 + vel_x_ = 0.33F + ((direction - 3) * 0.33F); + } vel_y_ = -4.0F; accel_y_ = 0.2F; collider_.r = width_ / 2; @@ -82,9 +88,9 @@ void Item::move() { const float MAX_X = play_area_.w - width_; pos_x_ = std::clamp(pos_x_, MIN_X, MAX_X); - // Si toca el borde lateral, invierte la velocidad horizontal + // Si toca el borde lateral if (pos_x_ == MIN_X || pos_x_ == MAX_X) { - vel_x_ = -vel_x_; + vel_x_ = -vel_x_; // Invierte la velocidad horizontal } // Si colisiona por arriba, rebota (excepto la máquina de café)