item.cpp: afegida rotació
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
class Texture; // lines 6-6
|
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)),
|
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
|
||||||
play_area_(play_area),
|
play_area_(play_area),
|
||||||
type_(type) {
|
type_(type) {
|
||||||
@@ -33,13 +33,17 @@ Item::Item(ItemType type, float x, float y, SDL_FRect &play_area, const std::sha
|
|||||||
if (direction < 3) {
|
if (direction < 3) {
|
||||||
// Velocidades negativas: -1.0, -0.66, -0.33
|
// Velocidades negativas: -1.0, -0.66, -0.33
|
||||||
vel_x_ = -ITEM_VEL_X_BASE + (direction * ITEM_VEL_X_STEP);
|
vel_x_ = -ITEM_VEL_X_BASE + (direction * ITEM_VEL_X_STEP);
|
||||||
|
rotate_speed_ = -720.0F;
|
||||||
} else {
|
} else {
|
||||||
// Velocidades positivas: 0.33, 0.66, 1.0
|
// Velocidades positivas: 0.33, 0.66, 1.0
|
||||||
vel_x_ = ITEM_VEL_X_STEP + ((direction - 3) * ITEM_VEL_X_STEP);
|
vel_x_ = ITEM_VEL_X_STEP + ((direction - 3) * ITEM_VEL_X_STEP);
|
||||||
|
rotate_speed_ = 720.0F;
|
||||||
}
|
}
|
||||||
vel_y_ = ITEM_VEL_Y;
|
vel_y_ = ITEM_VEL_Y;
|
||||||
accel_y_ = ITEM_ACCEL_Y;
|
accel_y_ = ITEM_ACCEL_Y;
|
||||||
collider_.r = width_ / 2;
|
collider_.r = width_ / 2;
|
||||||
|
sprite_->startRotate();
|
||||||
|
sprite_->setRotateAmount(rotate_speed_);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +105,8 @@ void Item::move(float deltaTime) {
|
|||||||
|
|
||||||
// Si toca el borde lateral
|
// Si toca el borde lateral
|
||||||
if (pos_x_ == MIN_X || pos_x_ == MAX_X) {
|
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é)
|
// 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
|
// Si colisiona con la parte inferior
|
||||||
if (pos_y_ > play_area_.h - height_) {
|
if (pos_y_ > play_area_.h - height_) {
|
||||||
// Corrige la posición
|
pos_y_ = play_area_.h - height_; // Corrige la posición
|
||||||
pos_y_ = play_area_.h - height_;
|
sprite_->scaleRotateAmount(0.5F); // Reduce la rotación
|
||||||
|
sprite_->stopRotate(300.0F); // Detiene la rotacion
|
||||||
|
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case ItemType::COFFEE_MACHINE:
|
case ItemType::COFFEE_MACHINE:
|
||||||
|
|||||||
@@ -78,14 +78,15 @@ class Item {
|
|||||||
SDL_FRect play_area_; // Rectángulo con la zona de juego
|
SDL_FRect play_area_; // Rectángulo con la zona de juego
|
||||||
Circle collider_; // Círculo de colisión del objeto
|
Circle collider_; // Círculo de colisión del objeto
|
||||||
ItemType type_; // Tipo de objeto
|
ItemType type_; // Tipo de objeto
|
||||||
float pos_x_; // Posición X del objeto
|
float pos_x_ = 0.0F; // Posición X del objeto
|
||||||
float pos_y_; // Posición Y del objeto
|
float pos_y_ = 0.0F; // Posición Y del objeto
|
||||||
float vel_x_; // Velocidad en el eje X
|
float vel_x_ = 0.0F; // Velocidad en el eje X
|
||||||
float vel_y_; // Velocidad en el eje Y
|
float vel_y_ = 0.0F; // Velocidad en el eje Y
|
||||||
float accel_x_ = 0.0F; // Aceleración en el eje X
|
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 width_ = WIDTH; // Ancho del objeto
|
||||||
float height_ = HEIGHT; // Alto 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)
|
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 floor_collision_ = false; // Indica si el objeto colisiona con el suelo
|
||||||
bool enabled_ = true; // Indica si el objeto está habilitado
|
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()->setSpriteClip(0, Item::HEIGHT, Item::WIDTH, Item::HEIGHT);
|
||||||
smart_sprites_.back()->setRotatingCenter({Item::WIDTH / 2, Item::HEIGHT / 2});
|
smart_sprites_.back()->setRotatingCenter({Item::WIDTH / 2, Item::HEIGHT / 2});
|
||||||
smart_sprites_.back()->setRotate(true);
|
smart_sprites_.back()->setRotate(true);
|
||||||
smart_sprites_.back()->setRotateSpeed(10);
|
|
||||||
smart_sprites_.back()->setRotateAmount(90.0);
|
smart_sprites_.back()->setRotateAmount(90.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user