cleanup time-based: elimina entitats frame-based (Bullet/Item/Player/Balloon), VELX en px/s, Game::popBalloon amb vel en px/s
This commit is contained in:
@@ -15,7 +15,6 @@ Item::Item(Id id, float x, float y, Texture *texture, const std::vector<std::str
|
||||
enabled_ = true;
|
||||
time_to_live_ = 600;
|
||||
time_to_live_s_ = TIME_TO_LIVE_S;
|
||||
accel_x_ = 0.0F;
|
||||
accel_x_s_ = 0.0F;
|
||||
floor_collision_ = false;
|
||||
|
||||
@@ -24,9 +23,6 @@ Item::Item(Id id, float x, float y, Texture *texture, const std::vector<std::str
|
||||
height_ = 29;
|
||||
pos_x_ = (((int)x + (PLAY_AREA_WIDTH / 2)) % (PLAY_AREA_WIDTH - width_ - 5)) + 2;
|
||||
pos_y_ = PLAY_AREA_TOP - height_;
|
||||
vel_x_ = 0.0F;
|
||||
vel_y_ = -0.1F;
|
||||
accel_y_ = 0.1F;
|
||||
vel_x_s_ = 0.0F;
|
||||
vel_y_s_ = COFFEE_VEL_Y_PX_PER_S;
|
||||
accel_y_s_ = COFFEE_ACCEL_Y_PX_PER_S2;
|
||||
@@ -38,9 +34,6 @@ Item::Item(Id id, float x, float y, Texture *texture, const std::vector<std::str
|
||||
pos_y_ = y;
|
||||
// Distribució original: -1.0, -0.5, 0.0, 0.5, 1.0 px/frame ⇒ -60..60 px/s en passos de 30.
|
||||
const int RAND_STEP = rand() % 5;
|
||||
vel_x_ = -1.0F + (static_cast<float>(RAND_STEP) * 0.5F);
|
||||
vel_y_ = -4.0F;
|
||||
accel_y_ = 0.2F;
|
||||
vel_x_s_ = (-2.0F + static_cast<float>(RAND_STEP)) * ITEM_VEL_X_STEP_PX_PER_S;
|
||||
vel_y_s_ = ITEM_VEL_Y_PX_PER_S;
|
||||
accel_y_s_ = ITEM_ACCEL_Y_PX_PER_S2;
|
||||
@@ -85,55 +78,6 @@ void Item::render() {
|
||||
}
|
||||
|
||||
// Actualiza la posición y estados del objeto
|
||||
void Item::move() {
|
||||
floor_collision_ = false;
|
||||
|
||||
// Calcula la nueva posición
|
||||
pos_x_ += vel_x_;
|
||||
pos_y_ += vel_y_;
|
||||
|
||||
// Aplica las aceleraciones a la velocidad
|
||||
vel_x_ += accel_x_;
|
||||
vel_y_ += accel_y_;
|
||||
|
||||
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
|
||||
if ((pos_x_ < PLAY_AREA_LEFT) || (pos_x_ + width_ > PLAY_AREA_RIGHT)) {
|
||||
// Corregir posición
|
||||
pos_x_ -= vel_x_;
|
||||
|
||||
// Invertir sentido
|
||||
vel_x_ = -vel_x_;
|
||||
}
|
||||
|
||||
// Si se sale por arriba rebota (excepto la maquina de café)
|
||||
if ((pos_y_ < PLAY_AREA_TOP) && !(id_ == Item::Id::COFFEE_MACHINE)) {
|
||||
// Corrige
|
||||
pos_y_ -= vel_y_;
|
||||
|
||||
// Invierte el sentido
|
||||
vel_y_ = -vel_y_;
|
||||
}
|
||||
|
||||
// Si el objeto se sale por la parte inferior
|
||||
if (pos_y_ + height_ > PLAY_AREA_BOTTOM) {
|
||||
// Detiene el objeto
|
||||
vel_y_ = 0;
|
||||
vel_x_ = 0;
|
||||
accel_x_ = 0;
|
||||
accel_y_ = 0;
|
||||
pos_y_ = PLAY_AREA_BOTTOM - height_;
|
||||
if (id_ == Item::Id::COFFEE_MACHINE) {
|
||||
floor_collision_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
sprite_->setPosX(int(pos_x_));
|
||||
sprite_->setPosY(int(pos_y_));
|
||||
shiftColliders();
|
||||
}
|
||||
|
||||
// Actualiza la posición y estados del objeto (time-based)
|
||||
void Item::move(float dt_s) {
|
||||
floor_collision_ = false;
|
||||
|
||||
@@ -180,14 +124,6 @@ void Item::disable() {
|
||||
}
|
||||
|
||||
// Actualiza el objeto a su posicion, animación y controla los contadores
|
||||
void Item::update() {
|
||||
move();
|
||||
sprite_->animate();
|
||||
updateTimeToLive();
|
||||
checkTimeToLive();
|
||||
}
|
||||
|
||||
// Actualiza el objeto (time-based)
|
||||
void Item::update(float dt_s) {
|
||||
move(dt_s);
|
||||
sprite_->animate(dt_s);
|
||||
@@ -195,15 +131,9 @@ void Item::update(float dt_s) {
|
||||
checkTimeToLive();
|
||||
}
|
||||
|
||||
// Actualiza el contador
|
||||
void Item::updateTimeToLive() {
|
||||
if (time_to_live_ > 0) {
|
||||
time_to_live_--;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el contador (time-based). Manté time_to_live_ sincronitzat per a
|
||||
// que render() segueixi funcionant amb la mateixa condició de parpelleig.
|
||||
// Actualiza el contador. Manté time_to_live_ (frames) sincronitzat amb el
|
||||
// segons per a que render() segueixi funcionant amb la mateixa condició de
|
||||
// parpelleig.
|
||||
void Item::updateTimeToLive(float dt_s) {
|
||||
if (time_to_live_s_ > 0.0F) {
|
||||
time_to_live_s_ = std::max(0.0F, time_to_live_s_ - dt_s);
|
||||
|
||||
Reference in New Issue
Block a user