item.cpp: afegida rotació
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -102,6 +106,7 @@ 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
|
||||
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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user