diff options
Diffstat (limited to '')
-rw-r--r-- | rust/src/buff_bounce.rs | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/rust/src/buff_bounce.rs b/rust/src/buff_bounce.rs index 179642d..cb9ded8 100644 --- a/rust/src/buff_bounce.rs +++ b/rust/src/buff_bounce.rs @@ -2,22 +2,21 @@ use gdnative::api::*; use gdnative::prelude::*; use crate::buff_trait::Buff; -struct BuffBounce { +pub struct BuffBounce { name: String, description: String, - rigid_body: Option<Ref<RigidBody>>, + rigid_body: Box<Ref<RigidBody>>, target_bounciness: f64, previous_bounciness: f64 } impl BuffBounce { - fn new(rigid_body: Option<Ref<RigidBody>>) -> Self { + pub fn new(rigid_body: Box<Ref<RigidBody>>) -> Self { BuffBounce { name: String::from("Bounce"), description: String::from("Let's the die bounce more than usual."), rigid_body, - target_bounciness: 1.0, previous_bounciness: 0.0 } @@ -25,43 +24,30 @@ impl BuffBounce { } impl Buff for BuffBounce { - unsafe fn execute_buff(&mut self) { - // make sure the rigid body exists - match &self.rigid_body { - Some(body) => { - let safe_body = body.assume_safe(); - // get the physics material - match safe_body.physics_material_override() { - Some(mat) => { - let save_mat = mat.assume_safe(); - self.previous_bounciness = save_mat.bounce(); - save_mat.set_bounce(self.target_bounciness); - }, - None => godot_warn!("Physics material was not found") - } + unsafe fn execute_buff(&mut self) { + // get the physics material + match self.rigid_body.assume_safe().physics_material_override() { + Some(mat) => { + let save_mat = mat.assume_safe(); + self.previous_bounciness = save_mat.bounce(); + save_mat.set_bounce(self.target_bounciness); }, - None => godot_warn!("No rigid body initialized to apply properties to") + None => godot_warn!("Physics material was not found") } + godot_print!("Bounce activated"); } unsafe fn revert_buff(&mut self) { - // make sure the rigid body exists - match &self.rigid_body { - Some(body) => { - let safe_body = body.assume_safe(); - - // get the physics material - match safe_body.physics_material_override() { - Some(mat) => { - let save_mat = mat.assume_safe(); - save_mat.set_bounce(self.previous_bounciness); - }, - None => godot_warn!("Physics material was not found") - } + // get the physics material + match self.rigid_body.assume_safe().physics_material_override() { + Some(mat) => { + let save_mat = mat.assume_safe(); + save_mat.set_bounce(self.previous_bounciness); }, - None => godot_warn!("No rigid body initialized to apply properties to") + None => godot_warn!("Physics material was not found") } + godot_print!("Bounce deactivated"); } fn get_name(self) -> GodotString { |