item.cpp: afegida rotació
This commit is contained in:
@@ -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> &texture, const std::vector<std::string> &animation)
|
||||
Item::Item(ItemType type, float x, float y, SDL_FRect& play_area, const std::shared_ptr<Texture>& texture, const std::vector<std::string>& animation)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(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:
|
||||
|
||||
Reference in New Issue
Block a user