revisat credits.cpp, player.cpp, balloon.cpp i balloon_manager.cpp
This commit is contained in:
@@ -48,15 +48,15 @@ title.bg_color 41526F # Color de fondo en la sección titulo
|
||||
# --- BACKGROUND ---
|
||||
background.attenuate_color FFFFFF00 # Color de atenuación del fondo (RGBA hexadecimal)
|
||||
|
||||
# --- BALLOONS --- (deltaTime puro: vel en pixels/ms, grav en pixels/ms²)
|
||||
balloon.settings[0].vel 0.165f # Velocidad inicial del globo 1 (pixels/ms)
|
||||
balloon.settings[0].grav 0.00032f # Gravedad aplicada al globo 1 (pixels/ms²)
|
||||
balloon.settings[1].vel 0.222f # Velocidad inicial del globo 2 (pixels/ms)
|
||||
balloon.settings[1].grav 0.00036f # Gravedad aplicada al globo 2 (pixels/ms²)
|
||||
balloon.settings[2].vel 0.282f # Velocidad inicial del globo 3 (pixels/ms)
|
||||
balloon.settings[2].grav 0.00036f # Gravedad aplicada al globo 3 (pixels/ms²)
|
||||
balloon.settings[3].vel 0.327f # Velocidad inicial del globo 4 (pixels/ms)
|
||||
balloon.settings[3].grav 0.00036f # Gravedad aplicada al globo 4 (pixels/ms²)
|
||||
# --- BALLOONS --- (deltaTime en segundos: vel en pixels/s, grav en pixels/s²)
|
||||
balloon.settings[0].vel 165.0f # Velocidad inicial del globo 1 (pixels/s)
|
||||
balloon.settings[0].grav 320.0f # Gravedad aplicada al globo 1 (pixels/s²)
|
||||
balloon.settings[1].vel 222.0f # Velocidad inicial del globo 2 (pixels/s)
|
||||
balloon.settings[1].grav 360.0f # Gravedad aplicada al globo 2 (pixels/s²)
|
||||
balloon.settings[2].vel 282.0f # Velocidad inicial del globo 3 (pixels/s)
|
||||
balloon.settings[2].grav 360.0f # Gravedad aplicada al globo 3 (pixels/s²)
|
||||
balloon.settings[3].vel 327.0f # Velocidad inicial del globo 4 (pixels/s)
|
||||
balloon.settings[3].grav 360.0f # Gravedad aplicada al globo 4 (pixels/s²)
|
||||
|
||||
balloon.color[0] blue # Color de creación del globo normal
|
||||
balloon.color[1] orange # Color del globo normal
|
||||
|
||||
@@ -48,15 +48,15 @@ title.bg_color 41526F # Color de fondo en la sección titulo
|
||||
# --- BACKGROUND ---
|
||||
background.attenuate_color FFFFFF00 # Color de atenuación del fondo (RGBA hexadecimal)
|
||||
|
||||
# --- BALLOONS --- (deltaTime puro: vel en pixels/ms, grav en pixels/ms²)
|
||||
balloon.settings[0].vel 0.165f # Velocidad inicial del globo 1 (pixels/ms)
|
||||
balloon.settings[0].grav 0.00032f # Gravedad aplicada al globo 1 (pixels/ms²)
|
||||
balloon.settings[1].vel 0.222f # Velocidad inicial del globo 2 (pixels/ms)
|
||||
balloon.settings[1].grav 0.00036f # Gravedad aplicada al globo 2 (pixels/ms²)
|
||||
balloon.settings[2].vel 0.282f # Velocidad inicial del globo 3 (pixels/ms)
|
||||
balloon.settings[2].grav 0.00036f # Gravedad aplicada al globo 3 (pixels/ms²)
|
||||
balloon.settings[3].vel 0.327f # Velocidad inicial del globo 4 (pixels/ms)
|
||||
balloon.settings[3].grav 0.00036f # Gravedad aplicada al globo 4 (pixels/ms²)
|
||||
# --- BALLOONS --- (deltaTime en segundos: vel en pixels/s, grav en pixels/s²)
|
||||
balloon.settings[0].vel 165.0f # Velocidad inicial del globo 1 (pixels/s)
|
||||
balloon.settings[0].grav 320.0f # Gravedad aplicada al globo 1 (pixels/s²)
|
||||
balloon.settings[1].vel 222.0f # Velocidad inicial del globo 2 (pixels/s)
|
||||
balloon.settings[1].grav 360.0f # Gravedad aplicada al globo 2 (pixels/s²)
|
||||
balloon.settings[2].vel 282.0f # Velocidad inicial del globo 3 (pixels/s)
|
||||
balloon.settings[2].grav 360.0f # Gravedad aplicada al globo 3 (pixels/s²)
|
||||
balloon.settings[3].vel 327.0f # Velocidad inicial del globo 4 (pixels/s)
|
||||
balloon.settings[3].grav 360.0f # Gravedad aplicada al globo 4 (pixels/s²)
|
||||
|
||||
balloon.color[0] blue # Color de creación del globo normal
|
||||
balloon.color[1] orange # Color del globo normal
|
||||
|
||||
@@ -3,28 +3,28 @@ frame_height=10
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
speed=10
|
||||
speed=0.1667
|
||||
loop=0
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=blue
|
||||
speed=20
|
||||
speed=0.3333
|
||||
loop=0
|
||||
frames=10,11,12,13,14,15,16,17,18,19
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=green
|
||||
speed=10
|
||||
speed=0.1667
|
||||
loop=0
|
||||
frames=20,21,22,23,24,25,26,27,28,29
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red
|
||||
speed=20
|
||||
speed=0.3333
|
||||
loop=0
|
||||
frames=30,31,32,33,34,35,36,37,38,39
|
||||
[/animation]
|
||||
@@ -3,28 +3,28 @@ frame_height=16
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
speed=10
|
||||
speed=0.1667
|
||||
loop=0
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=blue
|
||||
speed=20
|
||||
speed=0.3333
|
||||
loop=0
|
||||
frames=10,11,12,13,14,15,16,17,18,19
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=green
|
||||
speed=10
|
||||
speed=0.1667
|
||||
loop=0
|
||||
frames=20,21,22,23,24,25,26,27,28,29
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red
|
||||
speed=20
|
||||
speed=0.3333
|
||||
loop=0
|
||||
frames=30,31,32,33,34,35,36,37,38,39
|
||||
[/animation]
|
||||
@@ -3,28 +3,28 @@ frame_height=26
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
speed=10
|
||||
speed=0.1667
|
||||
loop=0
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=blue
|
||||
speed=20
|
||||
speed=0.3333
|
||||
loop=0
|
||||
frames=10,11,12,13,14,15,16,17,18,19
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=green
|
||||
speed=10
|
||||
speed=0.1667
|
||||
loop=0
|
||||
frames=20,21,22,23,24,25,26,27,28,29
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red
|
||||
speed=20
|
||||
speed=0.3333
|
||||
loop=0
|
||||
frames=30,31,32,33,34,35,36,37,38,39
|
||||
[/animation]
|
||||
@@ -3,28 +3,28 @@ frame_height=48
|
||||
|
||||
[animation]
|
||||
name=orange
|
||||
speed=10
|
||||
speed=0.1667
|
||||
loop=0
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=blue
|
||||
speed=20
|
||||
speed=0.3333
|
||||
loop=0
|
||||
frames=10,11,12,13,14,15,16,17,18,19
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=green
|
||||
speed=10
|
||||
speed=0.1667
|
||||
loop=0
|
||||
frames=20,21,22,23,24,25,26,27,28,29
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=red
|
||||
speed=20
|
||||
speed=0.3333
|
||||
loop=0
|
||||
frames=30,31,32,33,34,35,36,37,38,39
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=10
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=-1
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=16
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=-1
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=26
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=-1
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=48
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=-1
|
||||
frames=0,1,2,3,4,5,6,7,8,9
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=49
|
||||
|
||||
[animation]
|
||||
name=powerball
|
||||
speed=10
|
||||
speed=0.0167
|
||||
loop=-1
|
||||
frames=1
|
||||
[/animation]
|
||||
@@ -3,42 +3,42 @@ frame_height=12
|
||||
|
||||
[animation]
|
||||
name=normal_up
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=0,1,2
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=normal_left
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=3,4,5,5,4,3
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=normal_right
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=6,7,8,8,7,6
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=powered_up
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=9,10,11,11,10,9
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=powered_left
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=12,13,14,14,13,12
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=powered_right
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=15,16,17,17,26,15
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=20
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=8
|
||||
speed=0.1333
|
||||
loop=0
|
||||
frames=0,0,1
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=20
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=8
|
||||
speed=0.1333
|
||||
loop=0
|
||||
frames=0,0,1
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=39
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=6
|
||||
speed=0.1
|
||||
loop=0
|
||||
frames=0,1,2,3,4,5,6,7,8
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=20
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=8
|
||||
speed=0.1333
|
||||
loop=0
|
||||
frames=0,0,1
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=20
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=8
|
||||
speed=0.1333
|
||||
loop=0
|
||||
frames=0,0,1
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=20
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=8
|
||||
speed=0.1333
|
||||
loop=0
|
||||
frames=0,0,1
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=20
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=8
|
||||
speed=0.1333
|
||||
loop=0
|
||||
frames=0,0,1
|
||||
[/animation]
|
||||
@@ -3,133 +3,133 @@ frame_height=32
|
||||
|
||||
[animation]
|
||||
name=walk
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=0,1,2,3
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand
|
||||
speed=10
|
||||
speed=0.0167
|
||||
loop=0
|
||||
frames=4,5,6,7
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=walk-fire-side
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=8,9,10,11
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=walk-recoil-side
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=12,13,14,15
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=walk-cool-side
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=16,17,18,19
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand-fire-side
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=20
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand-recoil-side
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=21
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand-cool-side
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=22
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=walk-fire-center
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=23,24,25,26
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=walk-recoil-center
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=27,28,29,30
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=walk-cool-center
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=31,32,33,34
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand-fire-center
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=35
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand-recoil-center
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=36
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=stand-cool-center
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=37
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=rolling
|
||||
speed=10
|
||||
speed=0.0167
|
||||
loop=0
|
||||
frames=38,39,40,41
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=celebration
|
||||
speed=10
|
||||
speed=0.0167
|
||||
loop=-1
|
||||
frames=42,42,42,42,42,42,43,44,45,46,46,46,46,46,46,45,45,45,46,46,46,45,45,45,44,43,42,42,42
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=dizzy
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=47,48,49,50,51,52,53
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=recover
|
||||
speed=3
|
||||
speed=0.05
|
||||
loop=-1
|
||||
frames=54,54,54,54,55,56,57,58,58,58,59,60,61,58,59,60,61,58,59,60,61,62,62,62,62
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=hello
|
||||
speed=3
|
||||
speed=0.05
|
||||
loop=-1
|
||||
frames=63,64,65,66,67,68,69,70,71,72,73,73,73,73,73,73,73,73,73,73,73,73,73,74,75,76,77,78,79,80,81,82,82,81,80,79,79,80,81,82,82,81,80,79,79,80,81,82,82,81,80,79,79,80,81,82,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=44
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=5
|
||||
speed=0.0833
|
||||
loop=0
|
||||
frames=0,1,2,3
|
||||
[/animation]
|
||||
@@ -3,14 +3,14 @@ frame_height=32
|
||||
|
||||
[animation]
|
||||
name=fly
|
||||
speed=2
|
||||
speed=0.0333
|
||||
loop=0
|
||||
frames=0,1
|
||||
[/animation]
|
||||
|
||||
[animation]
|
||||
name=hit
|
||||
speed=2
|
||||
speed=0.0333
|
||||
loop=0
|
||||
frames=2,3
|
||||
[/animation]
|
||||
@@ -3,7 +3,7 @@ frame_height=16
|
||||
|
||||
[animation]
|
||||
name=default
|
||||
speed=8
|
||||
speed=0.1333
|
||||
loop=-1
|
||||
frames=0,1,2,3,4,5,6
|
||||
[/animation]
|
||||
@@ -269,7 +269,7 @@ void AnimatedSprite::processAnimationParameter(const std::string& line, Animatio
|
||||
if (key == "name") {
|
||||
animation.name = value;
|
||||
} else if (key == "speed") {
|
||||
animation.speed = std::stoi(value);
|
||||
animation.speed = std::stof(value);
|
||||
} else if (key == "loop") {
|
||||
animation.loop = std::stoi(value);
|
||||
} else if (key == "frames") {
|
||||
@@ -296,7 +296,7 @@ void AnimatedSprite::parseFramesParameter(const std::string& frames_str, Animati
|
||||
}
|
||||
|
||||
// Establece la velocidad de la animación
|
||||
void AnimatedSprite::setAnimationSpeed(size_t value) {
|
||||
void AnimatedSprite::setAnimationSpeed(float value) {
|
||||
animations_[current_animation_].speed = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ class AnimatedSprite : public MovingSprite {
|
||||
void setCurrentAnimation(const std::string& name = "default", bool reset = true); // Establece la animación por nombre
|
||||
void setCurrentAnimation(int index = 0, bool reset = true); // Establece la animación por índice
|
||||
void resetAnimation(); // Reinicia la animación actual
|
||||
void setAnimationSpeed(size_t value); // Establece la velocidad de la animación
|
||||
auto getAnimationSpeed() const -> size_t { return animations_[current_animation_].speed; } // Obtiene la velocidad de la animación actual
|
||||
void setAnimationSpeed(float value); // Establece la velocidad de la animación
|
||||
auto getAnimationSpeed() const -> float { return animations_[current_animation_].speed; } // Obtiene la velocidad de la animación actual
|
||||
void animtionPause() { animations_[current_animation_].paused = true; } // Detiene la animación
|
||||
void animationResume() { animations_[current_animation_].paused = false; } // Reanuda la animación
|
||||
auto getCurrentAnimationFrame() const -> size_t { return animations_[current_animation_].current_frame; } // Obtiene el numero de frame de la animación actual
|
||||
|
||||
@@ -29,7 +29,7 @@ Balloon::Balloon(const Config& config)
|
||||
switch (type_) {
|
||||
case Type::BALLOON: {
|
||||
vy_ = 0;
|
||||
max_vy_ = 3.0F;
|
||||
max_vy_ = 3.0F * 60.0F; // Convert from frames to seconds (180 pixels/s)
|
||||
|
||||
const int INDEX = static_cast<int>(size_);
|
||||
gravity_ = param.balloon.settings.at(INDEX).grav;
|
||||
@@ -65,7 +65,7 @@ Balloon::Balloon(const Config& config)
|
||||
power_ = score_ = menace_ = 0;
|
||||
|
||||
vy_ = 0;
|
||||
max_vy_ = 3.0F;
|
||||
max_vy_ = 3.0F * 60.0F; // Convert from frames to seconds (180 pixels/s)
|
||||
gravity_ = param.balloon.settings.at(INDEX).grav;
|
||||
default_vy_ = param.balloon.settings.at(INDEX).vel;
|
||||
|
||||
@@ -153,7 +153,7 @@ void Balloon::move(float deltaTime) {
|
||||
}
|
||||
|
||||
void Balloon::handleHorizontalMovement(float deltaTime) {
|
||||
// DeltaTime puro: velocidad (pixels/ms) * tempo * tiempo (ms)
|
||||
// DeltaTime en segundos: velocidad (pixels/s) * tempo * tiempo (s)
|
||||
x_ += vx_ * game_tempo_ * deltaTime;
|
||||
|
||||
const int CLIP = 2;
|
||||
@@ -166,7 +166,7 @@ void Balloon::handleHorizontalMovement(float deltaTime) {
|
||||
}
|
||||
|
||||
void Balloon::handleVerticalMovement(float deltaTime) {
|
||||
// DeltaTime puro: velocidad (pixels/ms) * tempo * tiempo (ms)
|
||||
// DeltaTime en segundos: velocidad (pixels/s) * tempo * tiempo (s)
|
||||
y_ += vy_ * game_tempo_ * deltaTime;
|
||||
|
||||
if (shouldCheckTopCollision()) {
|
||||
@@ -223,7 +223,7 @@ void Balloon::handleBottomCollision() {
|
||||
}
|
||||
|
||||
void Balloon::applyGravity(float deltaTime) {
|
||||
// DeltaTime puro: aceleración (pixels/ms²) * tempo * tiempo (ms)
|
||||
// DeltaTime en segundos: aceleración (pixels/s²) * tempo * tiempo (s)
|
||||
vy_ += gravity_ * game_tempo_ * deltaTime;
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ void Balloon::update(float deltaTime) {
|
||||
shiftSprite();
|
||||
shiftColliders();
|
||||
sprite_->update(deltaTime);
|
||||
// Contador interno con deltaTime puro
|
||||
// Contador interno con deltaTime en segundos
|
||||
counter_ += deltaTime;
|
||||
}
|
||||
|
||||
@@ -261,13 +261,14 @@ void Balloon::updateState(float deltaTime) {
|
||||
|
||||
if (creation_counter_ > 0) {
|
||||
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
||||
// Cada 166ms (equivalente a 10 frames a 60fps)
|
||||
// Cada 10/60 segundos (equivalente a 10 frames a 60fps)
|
||||
movement_accumulator_ += deltaTime;
|
||||
|
||||
if (movement_accumulator_ >= 166.0f) {
|
||||
movement_accumulator_ -= 166.0f;
|
||||
constexpr float MOVEMENT_INTERVAL_S = 10.0f / 60.0f; // 10 frames = ~0.167s
|
||||
if (movement_accumulator_ >= MOVEMENT_INTERVAL_S) {
|
||||
movement_accumulator_ -= MOVEMENT_INTERVAL_S;
|
||||
y_++;
|
||||
x_ += vx_ * 10.0f; // Movimiento equivalente a 10 frames de velocidad horizontal
|
||||
x_ += vx_ * MOVEMENT_INTERVAL_S; // Movimiento equivalente a 10 frames de velocidad horizontal
|
||||
|
||||
// Comprueba no se salga por los laterales
|
||||
const int MIN_X = play_area_.x;
|
||||
@@ -275,7 +276,7 @@ void Balloon::updateState(float deltaTime) {
|
||||
|
||||
if (x_ < MIN_X || x_ > MAX_X) {
|
||||
// Corrige y cambia el sentido de la velocidad
|
||||
x_ -= vx_ * 10.0f;
|
||||
x_ -= vx_ * MOVEMENT_INTERVAL_S;
|
||||
vx_ = -vx_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ class Balloon {
|
||||
"balloon_pop2.wav",
|
||||
"balloon_pop3.wav"};
|
||||
|
||||
// Velocidades horizontales en pixels/ms (convertidas desde 0.7 pixels/frame a 60fps)
|
||||
static constexpr float VELX_POSITIVE = 0.7F / (1000.0F / 60.0F); // ~0.042 pixels/ms
|
||||
static constexpr float VELX_NEGATIVE = -0.7F / (1000.0F / 60.0F); // ~-0.042 pixels/ms
|
||||
// Velocidades horizontales en pixels/segundo (convertidas desde 0.7 pixels/frame a 60fps)
|
||||
static constexpr float VELX_POSITIVE = 0.7F * 60.0F; // 42 pixels/segundo
|
||||
static constexpr float VELX_NEGATIVE = -0.7F * 60.0F; // -42 pixels/segundo
|
||||
|
||||
// Multiplicadores de tempo del juego (sin cambios, son puros multiplicadores)
|
||||
static constexpr std::array<float, 5> GAME_TEMPO = {0.60F, 0.70F, 0.80F, 0.90F, 1.00F};
|
||||
|
||||
@@ -86,7 +86,7 @@ void BalloonManager::deployRandomFormation(int stage) {
|
||||
// En este punto se decide entre crear una powerball o una formación enemiga
|
||||
if ((rand() % 100 < 15) && (canPowerBallBeCreated())) {
|
||||
createPowerBall(); // Crea una powerball
|
||||
balloon_deploy_counter_ = -167; // Resetea con pequeño retraso (10 frames = 167ms negativos)
|
||||
balloon_deploy_counter_ = -10.0f / 60.0f; // Resetea con pequeño retraso (10 frames = ~0.167s negativos)
|
||||
} else {
|
||||
// Decrementa el contador de despliegues de globos necesarios para la siguiente PowerBall
|
||||
if (power_ball_counter_ > 0) {
|
||||
@@ -164,7 +164,7 @@ void BalloonManager::freeBalloons() {
|
||||
|
||||
// Actualiza la variable enemyDeployCounter (time-based)
|
||||
void BalloonManager::updateBalloonDeployCounter(float deltaTime) {
|
||||
// DeltaTime puro - contador incrementa hasta llegar al umbral
|
||||
// DeltaTime en segundos - contador incrementa hasta llegar al umbral
|
||||
balloon_deploy_counter_ += deltaTime;
|
||||
}
|
||||
|
||||
@@ -216,9 +216,9 @@ void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon,
|
||||
// Crea el globo
|
||||
auto b = createBalloon(config);
|
||||
|
||||
// Establece parametros (deltaTime puro - valores ya en pixels/ms)
|
||||
constexpr float VEL_Y_BALLOON_PER_MS = -0.15F; // -2.50F convertido a pixels/ms
|
||||
b->setVelY(b->getType() == Balloon::Type::BALLOON ? VEL_Y_BALLOON_PER_MS : Balloon::VELX_NEGATIVE * 2.0F);
|
||||
// Establece parametros (deltaTime en segundos - velocidades en pixels/segundo)
|
||||
constexpr float VEL_Y_BALLOON_PER_S = -9.0F; // -0.15 pixels/ms convertido a pixels/segundo (-0.15 * 60 = -9)
|
||||
b->setVelY(b->getType() == Balloon::Type::BALLOON ? VEL_Y_BALLOON_PER_S : Balloon::VELX_NEGATIVE * 2.0F);
|
||||
|
||||
// Herencia de estados
|
||||
if (balloon->isStopped()) { b->stop(); }
|
||||
@@ -280,7 +280,7 @@ auto BalloonManager::popBalloon(const std::shared_ptr<Balloon> &balloon) -> int
|
||||
balloon->pop(true);
|
||||
score = destroyAllBalloons();
|
||||
power_ball_enabled_ = false;
|
||||
balloon_deploy_counter_ = -334; // Resetea con retraso (20 frames = 334ms negativos)
|
||||
balloon_deploy_counter_ = -20.0f / 60.0f; // Resetea con retraso (20 frames = ~0.333s negativos)
|
||||
} else {
|
||||
score = balloon->getScore();
|
||||
if (balloon->getSize() != Balloon::Size::SMALL) {
|
||||
@@ -336,7 +336,7 @@ auto BalloonManager::destroyAllBalloons() -> int {
|
||||
score += destroyBalloon(balloon);
|
||||
}
|
||||
|
||||
balloon_deploy_counter_ = -5000; // Resetea con retraso grande (300 frames = 5000ms negativos)
|
||||
balloon_deploy_counter_ = -300.0f / 60.0f; // Resetea con retraso grande (300 frames = 5s negativos)
|
||||
Screen::get()->flash(Colors::FLASH, 3);
|
||||
Screen::get()->shake();
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class BalloonManager {
|
||||
|
||||
private:
|
||||
// --- Constantes ---
|
||||
static const int DEFAULT_BALLOON_DEPLOY_COUNTER = 5000; // 300 frames × 16.67ms = 5000ms
|
||||
static constexpr float DEFAULT_BALLOON_DEPLOY_COUNTER = 300.0f / 60.0f; // 300 frames = 5 segundos
|
||||
|
||||
// --- Objetos y punteros ---
|
||||
Balloons balloons_; // Vector con los globos activos
|
||||
|
||||
@@ -80,12 +80,12 @@ struct BalloonSettings {
|
||||
grav(g) {}
|
||||
};
|
||||
|
||||
// Valores para deltaTime puro: vel en pixels/ms, grav en pixels/ms² (aceleración)
|
||||
// Valores para deltaTime en segundos: vel en pixels/s, grav en pixels/s² (aceleración)
|
||||
constexpr std::array<BalloonSettings, 4> SETTINGS = {{
|
||||
BalloonSettings(2.75F / 16.67F, 0.09F / (16.67F * 16.67F)), // Globo 0: vel=0.165 pixels/ms, grav=0.00032 pixels/ms²
|
||||
BalloonSettings(3.70F / 16.67F, 0.10F / (16.67F * 16.67F)), // Globo 1: vel=0.222 pixels/ms, grav=0.00036 pixels/ms²
|
||||
BalloonSettings(4.70F / 16.67F, 0.10F / (16.67F * 16.67F)), // Globo 2: vel=0.282 pixels/ms, grav=0.00036 pixels/ms²
|
||||
BalloonSettings(5.45F / 16.67F, 0.10F / (16.67F * 16.67F)) // Globo 3: vel=0.327 pixels/ms, grav=0.00036 pixels/ms²
|
||||
BalloonSettings(165.0F, 320.0F), // Globo 0: vel=165 pixels/s, grav=320 pixels/s²
|
||||
BalloonSettings(222.0F, 360.0F), // Globo 1: vel=222 pixels/s, grav=360 pixels/s²
|
||||
BalloonSettings(282.0F, 360.0F), // Globo 2: vel=282 pixels/s, grav=360 pixels/s²
|
||||
BalloonSettings(327.0F, 360.0F) // Globo 3: vel=327 pixels/s, grav=360 pixels/s²
|
||||
}};
|
||||
|
||||
constexpr std::array<const char*, 4> COLORS = {
|
||||
|
||||
@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#elif _DEBUG
|
||||
Section::name = Section::Name::INSTRUCTIONS;
|
||||
Section::name = Section::Name::CREDITS;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#else // NORMAL GAME
|
||||
Section::name = Section::Name::LOGO;
|
||||
|
||||
@@ -165,9 +165,11 @@ void Player::move(float deltaTime) {
|
||||
handleContinueTimeOut();
|
||||
break;
|
||||
case State::LEAVING_SCREEN:
|
||||
updateStepCounter(deltaTime);
|
||||
handleLeavingScreen();
|
||||
break;
|
||||
case State::ENTERING_SCREEN:
|
||||
updateStepCounter(deltaTime);
|
||||
handleEnteringScreen();
|
||||
break;
|
||||
case State::CREDITS:
|
||||
@@ -184,22 +186,10 @@ void Player::move(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handlePlayingMovement() {
|
||||
// Mueve el jugador a derecha o izquierda
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales, restaura su posición
|
||||
const float MIN_X = play_area_.x - 5;
|
||||
const float MAX_X = play_area_.w + 5 - WIDTH;
|
||||
pos_x_ = std::clamp(pos_x_, MIN_X, MAX_X);
|
||||
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
// Fase 1: Movimiento time-based durante el juego
|
||||
// Movimiento time-based durante el juego
|
||||
void Player::handlePlayingMovement(float deltaTime) {
|
||||
// Mueve el jugador a derecha o izquierda (time-based)
|
||||
pos_x_ += vel_x_ * deltaTime / (1000.0f / 60.0f);
|
||||
// Mueve el jugador a derecha o izquierda (time-based en segundos)
|
||||
pos_x_ += vel_x_ * deltaTime;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales, restaura su posición
|
||||
const float MIN_X = play_area_.x - 5;
|
||||
@@ -286,7 +276,7 @@ void Player::handleContinueTimeOut() {
|
||||
}
|
||||
|
||||
void Player::handleLeavingScreen() {
|
||||
updateStepCounter();
|
||||
// updateStepCounter se llama desde move() con deltaTime
|
||||
setInputBasedOnPlayerId();
|
||||
|
||||
pos_x_ += vel_x_;
|
||||
@@ -301,7 +291,7 @@ void Player::handleLeavingScreen() {
|
||||
}
|
||||
|
||||
void Player::handleEnteringScreen() {
|
||||
updateStepCounter();
|
||||
// updateStepCounter se llama desde move() con deltaTime
|
||||
|
||||
switch (id_) {
|
||||
case Id::PLAYER1:
|
||||
@@ -335,22 +325,9 @@ void Player::handlePlayer2Entering() {
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleCreditsMovement() {
|
||||
pos_x_ += vel_x_ / 2.0F;
|
||||
|
||||
if (vel_x_ > 0) {
|
||||
handleCreditsRightMovement();
|
||||
} else {
|
||||
handleCreditsLeftMovement();
|
||||
}
|
||||
|
||||
updateWalkingStateForCredits();
|
||||
shiftSprite();
|
||||
}
|
||||
|
||||
// Fase 4: Movimiento general en la pantalla de créditos (time-based)
|
||||
// Movimiento general en la pantalla de créditos (time-based)
|
||||
void Player::handleCreditsMovement(float deltaTime) {
|
||||
pos_x_ += (vel_x_ / 2.0F) * deltaTime / (1000.0f / 60.0f); // Convert frame-based movement to time-based
|
||||
pos_x_ += (vel_x_ / 2.0F) * deltaTime;
|
||||
|
||||
if (vel_x_ > 0) {
|
||||
handleCreditsRightMovement();
|
||||
@@ -376,19 +353,11 @@ void Player::handleCreditsLeftMovement() {
|
||||
}
|
||||
}
|
||||
|
||||
void Player::handleWaitingMovement() {
|
||||
++waiting_counter_;
|
||||
if (waiting_counter_ == WAITING_COUNTER) {
|
||||
waiting_counter_ = 0;
|
||||
player_sprite_->resetAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 4: Controla la animación del jugador saludando (time-based)
|
||||
// Controla la animación del jugador saludando (time-based)
|
||||
void Player::handleWaitingMovement(float deltaTime) {
|
||||
waiting_time_accumulator_ += deltaTime;
|
||||
float waiting_duration = static_cast<float>(WAITING_COUNTER) * (1000.0f / 60.0f); // Convert frames to milliseconds
|
||||
if (waiting_time_accumulator_ >= waiting_duration) {
|
||||
const float WAITING_DURATION_S = static_cast<float>(WAITING_COUNTER) / 60.0f; // Convert frames to seconds
|
||||
if (waiting_time_accumulator_ >= WAITING_DURATION_S) {
|
||||
waiting_time_accumulator_ = 0.0f;
|
||||
player_sprite_->resetAnimation();
|
||||
}
|
||||
@@ -415,18 +384,11 @@ void Player::setInputBasedOnPlayerId() {
|
||||
}
|
||||
}
|
||||
|
||||
void Player::updateStepCounter() {
|
||||
++step_counter_;
|
||||
if (step_counter_ % 10 == 0) {
|
||||
playSound("walk.wav");
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 4: Incrementa o ajusta el contador de pasos (time-based)
|
||||
// Incrementa o ajusta el contador de pasos (time-based)
|
||||
void Player::updateStepCounter(float deltaTime) {
|
||||
step_time_accumulator_ += deltaTime;
|
||||
float step_interval = 10.0f / 60.0f; // 10 frames converted to seconds
|
||||
if (step_time_accumulator_ >= step_interval) {
|
||||
const float STEP_INTERVAL_S = 10.0f / 60.0f; // 10 frames converted to seconds
|
||||
if (step_time_accumulator_ >= STEP_INTERVAL_S) {
|
||||
step_time_accumulator_ = 0.0f;
|
||||
playSound("walk.wav");
|
||||
}
|
||||
@@ -435,20 +397,20 @@ void Player::updateStepCounter(float deltaTime) {
|
||||
// Pinta el jugador en pantalla
|
||||
void Player::render() {
|
||||
if (power_up_ && isPlaying()) {
|
||||
// Convertir lógica de parpadeo a deltaTime
|
||||
float total_powerup_time_ms = static_cast<float>(POWERUP_COUNTER) / 60.0f * 1000.0f; // Total time in ms
|
||||
float quarter_time_ms = total_powerup_time_ms / 4.0f; // 25% del tiempo total
|
||||
// Convertir lógica de parpadeo a deltaTime en segundos
|
||||
const float TOTAL_POWERUP_TIME_S = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Total time in seconds
|
||||
const float QUARTER_TIME_S = TOTAL_POWERUP_TIME_S / 4.0f; // 25% del tiempo total
|
||||
|
||||
if (power_up_time_accumulator_ > quarter_time_ms) {
|
||||
if (power_up_time_accumulator_ > QUARTER_TIME_S) {
|
||||
// En los primeros 75% del tiempo, siempre visible
|
||||
power_sprite_->render();
|
||||
} else {
|
||||
// En el último 25%, parpadea cada 20 frames (333ms aprox)
|
||||
constexpr float blink_period_ms = 20.0f / 60.0f * 1000.0f; // 20 frames in ms
|
||||
constexpr float visible_proportion = 4.0f / 20.0f; // 4 frames visible de 20 total
|
||||
// En el último 25%, parpadea cada 20 frames (≈0.333s)
|
||||
constexpr float BLINK_PERIOD_S = 20.0f / 60.0f; // 20 frames in seconds
|
||||
constexpr float VISIBLE_PROPORTION = 4.0f / 20.0f; // 4 frames visible de 20 total
|
||||
|
||||
float cycle_position = fmod(power_up_time_accumulator_, blink_period_ms) / blink_period_ms;
|
||||
if (cycle_position >= visible_proportion) {
|
||||
float cycle_position = fmod(power_up_time_accumulator_, BLINK_PERIOD_S) / BLINK_PERIOD_S;
|
||||
if (cycle_position >= VISIBLE_PROPORTION) {
|
||||
power_sprite_->render();
|
||||
}
|
||||
}
|
||||
@@ -677,7 +639,7 @@ void Player::setPlayingState(State state) {
|
||||
case State::ROLLING: {
|
||||
// Activa la animación de rodar dando botes
|
||||
player_sprite_->setCurrentAnimation("rolling");
|
||||
player_sprite_->setAnimationSpeed(4);
|
||||
player_sprite_->setAnimationSpeed(4.0f / 60.0f); // 4 frames convertido a segundos
|
||||
player_sprite_->setVelY(-6.6F); // Velocidad inicial
|
||||
player_sprite_->setAccelY(0.2F); // Gravedad
|
||||
player_sprite_->setPosY(pos_y_ - 2); // Para "sacarlo" del suelo, ya que está hundido un pixel para ocultar el outline de los pies
|
||||
@@ -701,7 +663,7 @@ void Player::setPlayingState(State state) {
|
||||
player_sprite_->setVelY(-4.0F);
|
||||
player_sprite_->setVelX(0.0F);
|
||||
player_sprite_->setCurrentAnimation("rolling");
|
||||
player_sprite_->setAnimationSpeed(5);
|
||||
player_sprite_->setAnimationSpeed(5.0f / 60.0f); // 5 frames convertido a segundos
|
||||
setScoreboardMode(Scoreboard::Mode::GAME_OVER);
|
||||
playSound("voice_aw_aw_aw.wav");
|
||||
playSound("jump.wav");
|
||||
@@ -772,7 +734,7 @@ void Player::decScoreMultiplier() {
|
||||
void Player::setInvulnerable(bool value) {
|
||||
invulnerable_ = value;
|
||||
invulnerable_counter_ = invulnerable_ ? INVULNERABLE_COUNTER : 0;
|
||||
invulnerable_time_accumulator_ = invulnerable_ ? static_cast<float>(INVULNERABLE_COUNTER) / 60.0f * 1000.0f : 0.0f; // Convert frames to milliseconds
|
||||
invulnerable_time_accumulator_ = invulnerable_ ? static_cast<float>(INVULNERABLE_COUNTER) / 60.0f : 0.0f; // Convert frames to seconds
|
||||
}
|
||||
|
||||
// Monitoriza el estado (time-based)
|
||||
@@ -781,16 +743,16 @@ void Player::updateInvulnerable(float deltaTime) {
|
||||
if (invulnerable_time_accumulator_ > 0) {
|
||||
invulnerable_time_accumulator_ -= deltaTime;
|
||||
|
||||
// Frecuencia fija de parpadeo adaptada a deltaTime (en milisegundos)
|
||||
constexpr float blink_period_ms = 8.0f / 60.0f * 1000.0f; // 8 frames convertidos a ms
|
||||
// Frecuencia fija de parpadeo adaptada a deltaTime (en segundos)
|
||||
constexpr float BLINK_PERIOD_S = 8.0f / 60.0f; // 8 frames convertidos a segundos
|
||||
|
||||
// Calcula proporción decreciente basada en tiempo restante
|
||||
float total_invulnerable_time_ms = static_cast<float>(INVULNERABLE_COUNTER) / 60.0f * 1000.0f;
|
||||
float progress = 1.0f - (invulnerable_time_accumulator_ / total_invulnerable_time_ms);
|
||||
const float TOTAL_INVULNERABLE_TIME_S = static_cast<float>(INVULNERABLE_COUNTER) / 60.0f;
|
||||
float progress = 1.0f - (invulnerable_time_accumulator_ / TOTAL_INVULNERABLE_TIME_S);
|
||||
float white_proportion = 0.5f - progress * 0.2f; // Menos blanco hacia el final
|
||||
|
||||
// Calcula si debe mostrar textura de invulnerabilidad basado en el ciclo temporal
|
||||
float cycle_position = fmod(invulnerable_time_accumulator_, blink_period_ms) / blink_period_ms;
|
||||
float cycle_position = fmod(invulnerable_time_accumulator_, BLINK_PERIOD_S) / BLINK_PERIOD_S;
|
||||
bool should_show_invulnerable = cycle_position < white_proportion;
|
||||
size_t target_texture = should_show_invulnerable ? INVULNERABLE_TEXTURE : coffees_;
|
||||
|
||||
@@ -811,7 +773,7 @@ void Player::updateInvulnerable(float deltaTime) {
|
||||
void Player::setPowerUp() {
|
||||
power_up_ = true;
|
||||
power_up_counter_ = POWERUP_COUNTER;
|
||||
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f * 1000.0f; // Convert frames to milliseconds
|
||||
power_up_time_accumulator_ = static_cast<float>(POWERUP_COUNTER) / 60.0f; // Convert frames to seconds
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable (time-based)
|
||||
@@ -863,9 +825,9 @@ void Player::setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &text
|
||||
void Player::updateContinueCounter(float deltaTime) {
|
||||
if (playing_state_ == State::CONTINUE) {
|
||||
continue_time_accumulator_ += deltaTime;
|
||||
constexpr float CONTINUE_INTERVAL = 1000.0f; // 1 segundo en milisegundos
|
||||
if (continue_time_accumulator_ >= CONTINUE_INTERVAL) {
|
||||
continue_time_accumulator_ -= CONTINUE_INTERVAL;
|
||||
constexpr float CONTINUE_INTERVAL_S = 1.0f; // 1 segundo
|
||||
if (continue_time_accumulator_ >= CONTINUE_INTERVAL_S) {
|
||||
continue_time_accumulator_ -= CONTINUE_INTERVAL_S;
|
||||
decContinueCounter();
|
||||
}
|
||||
}
|
||||
@@ -875,9 +837,9 @@ void Player::updateContinueCounter(float deltaTime) {
|
||||
void Player::updateEnterNameCounter(float deltaTime) {
|
||||
if (playing_state_ == State::ENTERING_NAME || playing_state_ == State::ENTERING_NAME_GAME_COMPLETED) {
|
||||
name_entry_time_accumulator_ += deltaTime;
|
||||
constexpr float NAME_ENTRY_INTERVAL = 1000.0f; // 1 segundo en milisegundos
|
||||
if (name_entry_time_accumulator_ >= NAME_ENTRY_INTERVAL) {
|
||||
name_entry_time_accumulator_ -= NAME_ENTRY_INTERVAL;
|
||||
constexpr float NAME_ENTRY_INTERVAL_S = 1.0f; // 1 segundo
|
||||
if (name_entry_time_accumulator_ >= NAME_ENTRY_INTERVAL_S) {
|
||||
name_entry_time_accumulator_ -= NAME_ENTRY_INTERVAL_S;
|
||||
decNameEntryCounter();
|
||||
}
|
||||
}
|
||||
@@ -887,8 +849,8 @@ void Player::updateEnterNameCounter(float deltaTime) {
|
||||
void Player::updateShowingName(float deltaTime) {
|
||||
if (playing_state_ == State::SHOWING_NAME) {
|
||||
showing_name_time_accumulator_ += deltaTime;
|
||||
constexpr float SHOWING_NAME_DURATION = 5000.0f; // 5 segundos en milisegundos
|
||||
if (showing_name_time_accumulator_ >= SHOWING_NAME_DURATION) {
|
||||
constexpr float SHOWING_NAME_DURATION_S = 5.0f; // 5 segundos
|
||||
if (showing_name_time_accumulator_ >= SHOWING_NAME_DURATION_S) {
|
||||
game_completed_ ? setPlayingState(State::LEAVING_SCREEN) : setPlayingState(State::CONTINUE);
|
||||
}
|
||||
}
|
||||
@@ -909,13 +871,16 @@ void Player::decContinueCounter() {
|
||||
void Player::decNameEntryCounter() {
|
||||
name_entry_time_accumulator_ = 0.0f; // Reset time accumulator
|
||||
|
||||
// Incrementa acumuladores de tiempo (1 segundo = 1000ms)
|
||||
name_entry_idle_time_accumulator_ += 1000.0f;
|
||||
name_entry_total_time_accumulator_ += 1000.0f;
|
||||
// Incrementa acumuladores de tiempo (1 segundo)
|
||||
name_entry_idle_time_accumulator_ += 1.0f;
|
||||
name_entry_total_time_accumulator_ += 1.0f;
|
||||
|
||||
// Comprueba los acumuladores directamente contra los límites en milisegundos
|
||||
if ((name_entry_total_time_accumulator_ >= param.game.name_entry_total_time) ||
|
||||
(name_entry_idle_time_accumulator_ >= param.game.name_entry_idle_time)) {
|
||||
// Convierte límites de param (milisegundos) a segundos para comparación
|
||||
const float NAME_ENTRY_TOTAL_TIME_S = param.game.name_entry_total_time / 1000.0f;
|
||||
const float NAME_ENTRY_IDLE_TIME_S = param.game.name_entry_idle_time / 1000.0f;
|
||||
|
||||
if ((name_entry_total_time_accumulator_ >= NAME_ENTRY_TOTAL_TIME_S) ||
|
||||
(name_entry_idle_time_accumulator_ >= NAME_ENTRY_IDLE_TIME_S)) {
|
||||
name_entry_total_time_accumulator_ = 0.0f;
|
||||
name_entry_idle_time_accumulator_ = 0.0f;
|
||||
if (playing_state_ == State::ENTERING_NAME) {
|
||||
@@ -1036,7 +1001,7 @@ void Player::updateVisualLine(float deltaTime) {
|
||||
// Inicia un disparo en ambas líneas
|
||||
void Player::startFiringSystem(int cooldown_frames) {
|
||||
// LÍNEA 1: Inicia cooldown funcional
|
||||
fire_cooldown_timer_ = static_cast<float>(cooldown_frames) / 60.0f * 1000.0f; // Convertir frames a ms
|
||||
fire_cooldown_timer_ = static_cast<float>(cooldown_frames) / 60.0f; // Convertir frames a segundos
|
||||
can_fire_new_system_ = false;
|
||||
|
||||
// LÍNEA 2: Resetea completamente el estado visual
|
||||
|
||||
@@ -207,7 +207,7 @@ class Player {
|
||||
|
||||
private:
|
||||
// --- Constantes de física y movimiento ---
|
||||
static constexpr float BASE_SPEED = 1.5F; // Velocidad base del jugador
|
||||
static constexpr float BASE_SPEED = 90.0f; // Velocidad base del jugador (pixels/segundo)
|
||||
|
||||
// --- Constantes de power-ups y estados especiales ---
|
||||
static constexpr int POWERUP_COUNTER = 1500; // Duración del estado PowerUp (frames)
|
||||
@@ -224,8 +224,8 @@ class Player {
|
||||
// --- Constantes del nuevo sistema de disparo de dos líneas ---
|
||||
static constexpr float AIMING_DURATION_FACTOR = 0.5f; // 50% del cooldown funcional
|
||||
static constexpr float RECOILING_DURATION_MULTIPLIER = 4.0f; // 4 veces la duración de aiming
|
||||
static constexpr float THREAT_POSE_DURATION = 833.33f; // 50 frames = ~833ms (duración base)
|
||||
static constexpr float MIN_THREAT_POSE_DURATION = 100.0f; // Duración mínima para threat pose
|
||||
static constexpr float THREAT_POSE_DURATION = 50.0f / 60.0f; // 50 frames = ~0.833s (duración base)
|
||||
static constexpr float MIN_THREAT_POSE_DURATION = 6.0f / 60.0f; // 6 frames = ~0.1s (duración mínima)
|
||||
|
||||
// --- Objetos y punteros ---
|
||||
std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador
|
||||
|
||||
@@ -49,16 +49,17 @@ Credits::Credits()
|
||||
|
||||
fade_in_->setColor(param.fade.color);
|
||||
fade_in_->setType(Fade::Type::FULLSCREEN);
|
||||
fade_in_->setPostDuration(50);
|
||||
fade_in_->setPostDuration(static_cast<int>(50 * (1000.0f / 60.0f))); // 50 frames = ~833ms
|
||||
fade_in_->setMode(Fade::Mode::IN);
|
||||
fade_in_->activate();
|
||||
|
||||
fade_out_->setColor(0, 0, 0);
|
||||
fade_out_->setType(Fade::Type::FULLSCREEN);
|
||||
fade_out_->setPostDuration(400);
|
||||
fade_out_->setPostDuration(static_cast<int>(400 * (1000.0f / 60.0f))); // 400 frames = ~6667ms
|
||||
|
||||
updateRedRect();
|
||||
tiled_bg_->setColor(Color(255, 96, 96));
|
||||
tiled_bg_->setSpeed(60.0F);
|
||||
|
||||
initPlayers();
|
||||
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
|
||||
@@ -81,7 +82,7 @@ Credits::~Credits() {
|
||||
// Calcula el deltatime
|
||||
auto Credits::calculateDeltaTime() -> float {
|
||||
const Uint64 current_time = SDL_GetTicks();
|
||||
const float delta_time = static_cast<float>(current_time - last_time_);
|
||||
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convertir ms a segundos
|
||||
last_time_ = current_time;
|
||||
return delta_time;
|
||||
}
|
||||
@@ -112,8 +113,8 @@ void Credits::update(float deltaTime) {
|
||||
updatePlayers(adjusted_delta_time);
|
||||
updateAllFades(adjusted_delta_time);
|
||||
|
||||
// Convertir deltaTime a factor de frame (asumiendo 60fps)
|
||||
const float frameFactor = adjusted_delta_time / (1000.0f / 60.0f);
|
||||
// Convertir deltaTime a equivalente de frames (60fps)
|
||||
const float frameFactor = adjusted_delta_time * 60.0f;
|
||||
counter_ += frameFactor;
|
||||
|
||||
Screen::get()->update();
|
||||
@@ -287,43 +288,14 @@ void Credits::fillCanvas() {
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||
}
|
||||
|
||||
// Actualiza el destino de los rectangulos de las texturas (frame-based)
|
||||
void Credits::updateTextureDstRects() {
|
||||
if (static_cast<int>(counter_) % 10 == 0) {
|
||||
// Comprueba la posición de la textura con los titulos de credito
|
||||
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) {
|
||||
--credits_rect_dst_.y;
|
||||
}
|
||||
|
||||
// Comprueba la posición de la textura con el mini_logo
|
||||
if (mini_logo_rect_dst_.y == mini_logo_final_pos_) {
|
||||
mini_logo_on_position_ = true;
|
||||
|
||||
// Si el jugador quiere pasar los titulos de credito, el fade se inicia solo
|
||||
if (want_to_pass_) {
|
||||
fading_ = true;
|
||||
}
|
||||
|
||||
// Se activa el contador para evitar que la sección sea infinita
|
||||
if (counter_prevent_endless_ == 1000) {
|
||||
fading_ = true;
|
||||
} else {
|
||||
++counter_prevent_endless_;
|
||||
}
|
||||
} else {
|
||||
--mini_logo_rect_dst_.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el destino de los rectangulos de las texturas (time-based)
|
||||
void Credits::updateTextureDstRects(float deltaTime) {
|
||||
constexpr float TEXTURE_UPDATE_INTERVAL = 10 * (1000.0f / 60.0f); // 166.67ms (cada 10 frames)
|
||||
constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames)
|
||||
static float texture_accumulator = 0.0f;
|
||||
texture_accumulator += deltaTime;
|
||||
|
||||
if (texture_accumulator >= TEXTURE_UPDATE_INTERVAL) {
|
||||
texture_accumulator -= TEXTURE_UPDATE_INTERVAL;
|
||||
if (texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) {
|
||||
texture_accumulator -= TEXTURE_UPDATE_INTERVAL_S;
|
||||
|
||||
// Comprueba la posición de la textura con los titulos de credito
|
||||
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) {
|
||||
@@ -351,31 +323,12 @@ void Credits::updateTextureDstRects(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
// Tira globos al escenario (frame-based)
|
||||
void Credits::throwBalloons() {
|
||||
constexpr int SPEED = 200;
|
||||
const std::vector<int> SETS = {0, 63, 25, 67, 17, 75, 13, 50};
|
||||
|
||||
if (counter_ > ((SETS.size() - 1) * SPEED) * 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (static_cast<int>(counter_) % SPEED == 0) {
|
||||
const int INDEX = (static_cast<int>(counter_) / SPEED) % SETS.size();
|
||||
balloon_manager_->deployFormation(SETS.at(INDEX), -60);
|
||||
}
|
||||
|
||||
if (static_cast<int>(counter_) % (SPEED * 4) == 0 && counter_ > 0) {
|
||||
balloon_manager_->createPowerBall();
|
||||
}
|
||||
}
|
||||
|
||||
// Tira globos al escenario (time-based)
|
||||
void Credits::throwBalloons(float deltaTime) {
|
||||
constexpr int SPEED = 200;
|
||||
const std::vector<int> SETS = {0, 63, 25, 67, 17, 75, 13, 50};
|
||||
constexpr float BALLOON_INTERVAL = SPEED * (1000.0f / 60.0f); // 3333.33ms (cada 200 frames)
|
||||
constexpr float POWERBALL_INTERVAL = (SPEED * 4) * (1000.0f / 60.0f); // 13333.33ms (cada 800 frames)
|
||||
constexpr float BALLOON_INTERVAL_S = SPEED / 60.0f; // ~3.33s (cada 200 frames)
|
||||
constexpr float POWERBALL_INTERVAL_S = (SPEED * 4) / 60.0f; // ~13.33s (cada 800 frames)
|
||||
|
||||
if (counter_ > ((SETS.size() - 1) * SPEED) * 3) {
|
||||
return;
|
||||
@@ -387,14 +340,14 @@ void Credits::throwBalloons(float deltaTime) {
|
||||
balloon_accumulator += deltaTime;
|
||||
powerball_accumulator += deltaTime;
|
||||
|
||||
if (balloon_accumulator >= BALLOON_INTERVAL) {
|
||||
balloon_accumulator -= BALLOON_INTERVAL;
|
||||
if (balloon_accumulator >= BALLOON_INTERVAL_S) {
|
||||
balloon_accumulator -= BALLOON_INTERVAL_S;
|
||||
const int INDEX = (static_cast<int>(counter_ / SPEED)) % SETS.size();
|
||||
balloon_manager_->deployFormation(SETS.at(INDEX), -60);
|
||||
}
|
||||
|
||||
if (powerball_accumulator >= POWERBALL_INTERVAL && counter_ > 0) {
|
||||
powerball_accumulator -= POWERBALL_INTERVAL;
|
||||
if (powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) {
|
||||
powerball_accumulator -= POWERBALL_INTERVAL_S;
|
||||
balloon_manager_->createPowerBall();
|
||||
}
|
||||
}
|
||||
@@ -466,60 +419,17 @@ void Credits::initPlayers() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los rectangulos negros (frame-based)
|
||||
void Credits::updateBlackRects() {
|
||||
static int current_step_ = steps_;
|
||||
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1) {
|
||||
// Si los rectangulos superior e inferior no han llegado al centro
|
||||
if (static_cast<int>(counter_) % 4 == 0) {
|
||||
// Incrementa la altura del rectangulo superior
|
||||
top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1);
|
||||
|
||||
// Incrementa la altura y modifica la posición del rectangulo inferior
|
||||
++bottom_black_rect_.h;
|
||||
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1, param.game.game_area.center_y + 1);
|
||||
|
||||
--current_step_;
|
||||
setVolume((initial_volume_ * current_step_ / steps_));
|
||||
}
|
||||
} else {
|
||||
// Si los rectangulos superior e inferior han llegado al centro
|
||||
if (left_black_rect_.w != param.game.game_area.center_x && right_black_rect_.x != param.game.game_area.center_x) {
|
||||
constexpr int SPEED = 2;
|
||||
// Si los rectangulos izquierdo y derecho no han llegado al centro
|
||||
// Incrementa la anchura del rectangulo situado a la izquierda
|
||||
left_black_rect_.w = std::min(left_black_rect_.w + SPEED, param.game.game_area.center_x);
|
||||
|
||||
// Incrementa la anchura y modifica la posición del rectangulo situado a la derecha
|
||||
right_black_rect_.w += SPEED;
|
||||
right_black_rect_.x = std::max(right_black_rect_.x - SPEED, param.game.game_area.center_x);
|
||||
|
||||
--current_step_;
|
||||
setVolume((initial_volume_ * current_step_ / steps_));
|
||||
} else {
|
||||
// Si los rectangulos izquierdo y derecho han llegado al centro
|
||||
setVolume(0);
|
||||
Audio::get()->stopMusic();
|
||||
if (counter_pre_fade_ == 400) {
|
||||
fade_out_->activate();
|
||||
} else {
|
||||
++counter_pre_fade_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los rectangulos negros (time-based)
|
||||
void Credits::updateBlackRects(float deltaTime) {
|
||||
static float current_step_ = static_cast<float>(steps_);
|
||||
constexpr float BLACK_RECT_INTERVAL = 4 * (1000.0f / 60.0f); // 66.67ms (cada 4 frames)
|
||||
constexpr float BLACK_RECT_INTERVAL_S = 4.0f / 60.0f; // ~0.067s (cada 4 frames)
|
||||
static float black_rect_accumulator = 0.0f;
|
||||
|
||||
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1) {
|
||||
// Si los rectangulos superior e inferior no han llegado al centro
|
||||
black_rect_accumulator += deltaTime;
|
||||
if (black_rect_accumulator >= BLACK_RECT_INTERVAL) {
|
||||
black_rect_accumulator -= BLACK_RECT_INTERVAL;
|
||||
if (black_rect_accumulator >= BLACK_RECT_INTERVAL_S) {
|
||||
black_rect_accumulator -= BLACK_RECT_INTERVAL_S;
|
||||
|
||||
// Incrementa la altura del rectangulo superior
|
||||
top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1);
|
||||
@@ -552,8 +462,8 @@ void Credits::updateBlackRects(float deltaTime) {
|
||||
if (counter_pre_fade_ == 400) {
|
||||
fade_out_->activate();
|
||||
} else {
|
||||
// Convertir deltaTime a factor de frame
|
||||
const float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
// Convertir deltaTime a equivalente de frames
|
||||
const float frameFactor = deltaTime * 60.0f;
|
||||
counter_pre_fade_ += frameFactor;
|
||||
}
|
||||
}
|
||||
@@ -568,24 +478,6 @@ void Credits::updateRedRect() {
|
||||
border_rect_.h = bottom_black_rect_.y - border_rect_.y + 1;
|
||||
}
|
||||
|
||||
// Actualiza el estado de fade (frame-based)
|
||||
void Credits::updateAllFades() {
|
||||
if (fading_) {
|
||||
updateBlackRects();
|
||||
updateRedRect();
|
||||
}
|
||||
|
||||
fade_in_->update();
|
||||
if (fade_in_->hasEnded()) {
|
||||
Audio::get()->playMusic("credits.ogg");
|
||||
}
|
||||
|
||||
fade_out_->update();
|
||||
if (fade_out_->hasEnded()) {
|
||||
Section::name = Section::Name::HI_SCORE_TABLE;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado de fade (time-based)
|
||||
void Credits::updateAllFades(float deltaTime) {
|
||||
if (fading_) {
|
||||
|
||||
Reference in New Issue
Block a user