From f561a1f69d5fda68e0a23ab04f448e9364b2968c Mon Sep 17 00:00:00 2001 From: David Date: Sat, 16 Jul 2022 21:02:56 +0200 Subject: deactivate ball after 5s --- rust/src/basic_die.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'rust') diff --git a/rust/src/basic_die.rs b/rust/src/basic_die.rs index dc425b4..dbcccc8 100644 --- a/rust/src/basic_die.rs +++ b/rust/src/basic_die.rs @@ -13,7 +13,7 @@ enum InputState { Shooting, Moving } - + type SpatialRef = Option>; @@ -37,7 +37,7 @@ pub struct BasicDie { #[property(path="input/shoot_sensitivity")] shoot_sensitivity: f32, #[property(path="input/current_buff_index")] - current_buff_index: i8, + current_buff_index: i32, all_buffs: [Option>; 5], @@ -144,6 +144,7 @@ impl BasicDie { Some(Box::new(BuffExtra ::new())), ]; + godot_print!("Current Buff: {}", self.current_buff_index); godot_print!("Player is ready"); } @@ -166,8 +167,19 @@ impl BasicDie { } } - // detect if the die stops moving let delta_ms = OS::godot_singleton().get_ticks_msec() - self.last_shot_time; + + // deactivate the Ball Buff after 5 seconds + if matches!(self.input_state, InputState::Moving) + && delta_ms > 5000 + && self.current_buff_index == 1 { + match self.all_buffs[1] { + Some(ref mut buff) => buff.revert_buff(), + None => {} + } + } + + // detect if the die stops moving if matches!(self.input_state, InputState::Moving) && (delta_ms > self.stopping_min_ms) { @@ -178,6 +190,7 @@ impl BasicDie { godot_print!("Die stopped moving at velocity {} after {} ms", current_vel, delta_ms); //deactivate the old buff + godot_print!("Current Buff: {}", self.current_buff_index); match self.all_buffs[self.current_buff_index as usize] { Some(ref mut buff) => buff.revert_buff(), None => {} @@ -349,6 +362,7 @@ impl BasicDie { }; // apply the current buff + godot_print!("Current Buff: {}", self.current_buff_index); match self.all_buffs[self.current_buff_index as usize] { Some(ref mut buff) => buff.execute_buff(), None => {} -- cgit