diff options
author | IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com> | 2022-07-16 21:12:23 +0200 |
---|---|---|
committer | IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com> | 2022-07-16 21:12:23 +0200 |
commit | 9a750a6688ad923d990d11dc464f783210b50678 (patch) | |
tree | 90d7658c5e6173946bfb89c46d2cd43fd3f9bf90 /rust/src/buff_bounce.rs | |
parent | 9c061b9997d0add3298b1230426dd7332b91420f (diff) | |
parent | f561a1f69d5fda68e0a23ab04f448e9364b2968c (diff) | |
download | 2022-9a750a6688ad923d990d11dc464f783210b50678.tar.gz 2022-9a750a6688ad923d990d11dc464f783210b50678.tar.bz2 2022-9a750a6688ad923d990d11dc464f783210b50678.zip |
Merge branch 'BuffSystem' into GoalPost
Diffstat (limited to 'rust/src/buff_bounce.rs')
-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 { |