revisat tabe.cpp, item.cpp i game.cpp

This commit is contained in:
2025-09-24 09:37:23 +02:00
parent 6a223b68ba
commit 2977869ab5
7 changed files with 96 additions and 93 deletions

View File

@@ -40,12 +40,10 @@ void Tabe::render() {
// Mueve el objeto (time-based)
void Tabe::move(float deltaTime) {
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
float frameFactor = deltaTime / (1000.0f / 60.0f);
const int X = static_cast<int>(x_);
speed_ += accel_ * frameFactor;
x_ += speed_ * frameFactor;
speed_ += accel_ * deltaTime;
x_ += speed_ * deltaTime;
fly_distance_ -= std::abs(X - static_cast<int>(x_));
// Comprueba si sale por los bordes
@@ -80,7 +78,7 @@ void Tabe::move(float deltaTime) {
if (fly_distance_ <= 0) {
if (waiting_counter_ > 0) {
accel_ = speed_ = 0.0F;
waiting_counter_ -= frameFactor;
waiting_counter_ -= deltaTime;
if (waiting_counter_ < 0) waiting_counter_ = 0;
} else {
constexpr int CHOICES = 4;
@@ -132,22 +130,22 @@ void Tabe::enable() {
void Tabe::setRandomFlyPath(Direction direction, int length) {
direction_ = direction;
fly_distance_ = length;
waiting_counter_ = 5 + rand() % 15;
waiting_counter_ = 0.083f + (rand() % 15) * 0.0167f; // 5-20 frames converted to seconds (5/60 to 20/60)
Audio::get()->playSound("tabe.wav");
constexpr float SPEED = 2.0F;
constexpr float SPEED = 120.0f; // 2 pixels/frame * 60fps = 120 pixels/second
switch (direction) {
case Direction::TO_THE_LEFT: {
speed_ = -1.0F * SPEED;
accel_ = -1.0F * (1 + rand() % 10) / 30.0F;
accel_ = -1.0F * (1 + rand() % 10) * 2.0f; // Converted from frame-based to seconds
sprite_->setFlip(SDL_FLIP_NONE);
break;
}
case Direction::TO_THE_RIGHT: {
speed_ = SPEED;
accel_ = (1 + rand() % 10) / 30.0F;
accel_ = (1 + rand() % 10) * 2.0f; // Converted from frame-based to seconds
sprite_->setFlip(SDL_FLIP_HORIZONTAL);
break;
}
@@ -169,7 +167,7 @@ void Tabe::setState(State state) {
case State::HIT:
sprite_->setCurrentAnimation("hit");
hit_counter_ = 5;
hit_counter_ = 0.083f; // 5 frames converted to seconds (5/60)
++number_of_hits_;
break;
@@ -182,9 +180,7 @@ void Tabe::setState(State state) {
// Actualiza el estado (time-based)
void Tabe::updateState(float deltaTime) {
if (state_ == State::HIT) {
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
float frameFactor = deltaTime / (1000.0f / 60.0f);
hit_counter_ -= frameFactor;
hit_counter_ -= deltaTime;
if (hit_counter_ <= 0) {
setState(State::FLY);
}