diff options
author | IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com> | 2022-07-16 15:03:50 +0200 |
---|---|---|
committer | IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com> | 2022-07-16 15:03:50 +0200 |
commit | 4435579498beefeb75b524111d24b1cb922cd22a (patch) | |
tree | 026b0ad61d6abb5deb736e69015a897a3283c6cf /rust/src/buff_bounce.rs | |
parent | f2ad01fe09709bc32b9b06a0aecc4c1b4d0a870d (diff) | |
parent | 9739b6d40258440cef4f7664f501efa81497263b (diff) | |
download | 2022-4435579498beefeb75b524111d24b1cb922cd22a.tar.gz 2022-4435579498beefeb75b524111d24b1cb922cd22a.tar.bz2 2022-4435579498beefeb75b524111d24b1cb922cd22a.zip |
Merge branch 'BuffSystem'
Diffstat (limited to '')
-rw-r--r-- | rust/src/buff_bounce.rs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/rust/src/buff_bounce.rs b/rust/src/buff_bounce.rs new file mode 100644 index 0000000..179642d --- /dev/null +++ b/rust/src/buff_bounce.rs @@ -0,0 +1,74 @@ +use gdnative::api::*; +use gdnative::prelude::*; +use crate::buff_trait::Buff; + +struct BuffBounce { + name: String, + description: String, + rigid_body: Option<Ref<RigidBody>>, + + target_bounciness: f64, + previous_bounciness: f64 +} + +impl BuffBounce { + fn new(rigid_body: Option<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 + } + } +} + +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") + } + }, + None => godot_warn!("No rigid body initialized to apply properties to") + } + } + + 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") + } + }, + None => godot_warn!("No rigid body initialized to apply properties to") + } + } + + fn get_name(self) -> GodotString { + GodotString::from_str(self.name) + } + + fn get_description(self) -> GodotString { + GodotString::from_str(self.description) + } +} |