Refactor scene configurations and add z-index properties for better layering; implement grace period logic in DeadliftSystem
This commit is contained in:
@@ -21,11 +21,15 @@ pub struct DeadliftSystem {
|
||||
start_pos: Vector2,
|
||||
#[export]
|
||||
end_pos: Vector2,
|
||||
#[export]
|
||||
grace_duration: f32,
|
||||
|
||||
current_bar_height: f32,
|
||||
hold_timer: f32,
|
||||
is_lift_complete: bool,
|
||||
active_hazard_count: i32,
|
||||
grace_timer: f32,
|
||||
is_lifting: bool,
|
||||
event_bus: Option<Gd<EventBus>>,
|
||||
|
||||
base: Base<Node>,
|
||||
@@ -44,6 +48,9 @@ impl INode for DeadliftSystem {
|
||||
bar_visual: None,
|
||||
start_pos: Vector2::ZERO,
|
||||
end_pos: Vector2::ZERO,
|
||||
grace_duration: 1.5,
|
||||
grace_timer: 1.5,
|
||||
is_lifting: false,
|
||||
|
||||
current_bar_height: 0.0,
|
||||
hold_timer: 0.0,
|
||||
@@ -74,7 +81,13 @@ impl INode for DeadliftSystem {
|
||||
&self.base().callable("on_lift_completed"),
|
||||
);
|
||||
|
||||
bus.connect(
|
||||
consts::FOCUS_RELEASED,
|
||||
&self.base().callable("on_focus_released"),
|
||||
);
|
||||
|
||||
self.event_bus = Some(bus);
|
||||
self.grace_timer = self.grace_duration;
|
||||
}
|
||||
|
||||
fn process(&mut self, delta: f64) {
|
||||
@@ -89,6 +102,22 @@ impl INode for DeadliftSystem {
|
||||
|
||||
let dt = delta as f32;
|
||||
|
||||
if !self.is_lifting && self.active_hazard_count > 0 {
|
||||
self.grace_timer -= dt;
|
||||
|
||||
if self.grace_timer <= 0.0 {
|
||||
godot_print!("Deadlift Failed: Dropped bar due to hazards!");
|
||||
|
||||
self.current_bar_height = 0.0;
|
||||
|
||||
bus.clone().bind_mut().publish_lift_completed(false);
|
||||
self.is_lift_complete = true;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
self.grace_timer = self.grace_duration;
|
||||
}
|
||||
|
||||
if self.current_bar_height > 0.0 {
|
||||
self.current_bar_height -= self.gravity * dt;
|
||||
self.current_bar_height = self.current_bar_height.max(0.0);
|
||||
@@ -131,6 +160,12 @@ impl DeadliftSystem {
|
||||
return;
|
||||
}
|
||||
|
||||
self.is_lifting = true;
|
||||
|
||||
if self.active_hazard_count > 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
self.current_bar_height += self.power_per_click * delta;
|
||||
self.current_bar_height = self.current_bar_height.min(self.bar_height);
|
||||
}
|
||||
@@ -152,4 +187,9 @@ impl DeadliftSystem {
|
||||
self.active_hazard_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#[func]
|
||||
fn on_focus_released(&mut self) {
|
||||
self.is_lifting = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user