diff options
author | David <david003@gmx.net> | 2022-07-16 20:38:58 +0200 |
---|---|---|
committer | David <david003@gmx.net> | 2022-07-16 20:38:58 +0200 |
commit | d1bac1c41a75fdf901e1f7c5f604783f0685190a (patch) | |
tree | 6230dbb9c0526a5efe00f81971acb2697f87c6fb /rust/src/basic_die.rs | |
parent | 717a665a84dd9ca1b545d57976b87ba77bf11d80 (diff) | |
download | 2022-d1bac1c41a75fdf901e1f7c5f604783f0685190a.tar.gz 2022-d1bac1c41a75fdf901e1f7c5f604783f0685190a.tar.bz2 2022-d1bac1c41a75fdf901e1f7c5f604783f0685190a.zip |
make buffs work
Diffstat (limited to 'rust/src/basic_die.rs')
-rw-r--r-- | rust/src/basic_die.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/rust/src/basic_die.rs b/rust/src/basic_die.rs index 2a61197..dc425b4 100644 --- a/rust/src/basic_die.rs +++ b/rust/src/basic_die.rs @@ -1,6 +1,11 @@ use std::borrow::Borrow; use gdnative::api::*; use gdnative::prelude::*; +use crate::buff_trait::Buff; +use crate::buff_ball::BuffBall; +use crate::buff_bounce::BuffBounce; +use crate::buff_phase::BuffPhase; +use crate::buff_extra::BuffExtra; /// the input state for the player enum InputState { @@ -31,6 +36,10 @@ pub struct BasicDie { mouse_sensitivity: Vector2, #[property(path="input/shoot_sensitivity")] shoot_sensitivity: f32, + #[property(path="input/current_buff_index")] + current_buff_index: i8, + + all_buffs: [Option<Box<dyn Buff>>; 5], input_state: InputState, current_force: f32, @@ -62,6 +71,8 @@ impl BasicDie { stopping_min_ms: 1000, mouse_sensitivity: Vector2 { x: 1.0, y: 1.0 }, shoot_sensitivity: 1.0, + current_buff_index: 0, + all_buffs: [None, None, None, None, None], input_state: InputState::Default, current_force: 0.0, @@ -116,6 +127,23 @@ impl BasicDie { self.node_die = search_node(&None, String::from("W8")); + let die = match self.node_die { + None => { godot_warn!("No W8 assigned."); return; }, + Some(node) => + match node.assume_safe().cast::<RigidBody>() { + None => { godot_warn!("W8 is not a RigidBody."); return; }, + Some(rb) => rb.claim() + } + }; + + self.all_buffs = [ + None, + Some(Box::new(BuffBall ::new(Box::new(die)))), + Some(Box::new(BuffBounce::new(Box::new(die)))), + Some(Box::new(BuffPhase ::new(Box::new(die)))), + Some(Box::new(BuffExtra ::new())), + ]; + godot_print!("Player is ready"); } @@ -148,6 +176,13 @@ impl BasicDie { if current_vel <= self.stopping_velocity { self.input_state = InputState::Default; godot_print!("Die stopped moving at velocity {} after {} ms", current_vel, delta_ms); + + //deactivate the old buff + match self.all_buffs[self.current_buff_index as usize] { + Some(ref mut buff) => buff.revert_buff(), + None => {} + } + //TODO: find out which side is up and update the current buff index accordingly } }; } @@ -313,6 +348,12 @@ impl BasicDie { } }; + // apply the current buff + match self.all_buffs[self.current_buff_index as usize] { + Some(ref mut buff) => buff.execute_buff(), + None => {} + } + // actually add the force die.apply_impulse(die.transform().origin, impulse_dir); |