aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
authorLibravatar IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com>2022-07-16 23:32:01 +0200
committerLibravatar IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com>2022-07-16 23:32:01 +0200
commit373b0d66678a349d39146262d5b288b39c5cb1e1 (patch)
tree0c8d9aa28450e8b94e014833a94a895fde3258e5 /rust
parent9a750a6688ad923d990d11dc464f783210b50678 (diff)
download2022-373b0d66678a349d39146262d5b288b39c5cb1e1.tar.gz
2022-373b0d66678a349d39146262d5b288b39c5cb1e1.tar.bz2
2022-373b0d66678a349d39146262d5b288b39c5cb1e1.zip
goal zone
the rest is trash
Diffstat (limited to 'rust')
-rw-r--r--rust/src/basic_die.rs60
1 files changed, 43 insertions, 17 deletions
diff --git a/rust/src/basic_die.rs b/rust/src/basic_die.rs
index dbcccc8..304df90 100644
--- a/rust/src/basic_die.rs
+++ b/rust/src/basic_die.rs
@@ -1,6 +1,7 @@
use std::borrow::Borrow;
use gdnative::api::*;
use gdnative::prelude::*;
+use gdnative::core_types::VariantArray;
use crate::buff_trait::Buff;
use crate::buff_ball::BuffBall;
use crate::buff_bounce::BuffBounce;
@@ -16,6 +17,7 @@ enum InputState {
type SpatialRef = Option<Ref<Spatial>>;
+type NodeRef = Option<Ref<Node>>;
/// the basic die used by the player
#[derive(NativeClass)]
@@ -53,6 +55,7 @@ pub struct BasicDie {
node_camera_arm_horizontal: SpatialRef,
node_camera_arm_vertical: SpatialRef,
node_camera: SpatialRef,
+ node_loader: NodeRef,
}
#[methods]
@@ -86,6 +89,7 @@ impl BasicDie {
node_camera_arm_horizontal: None,
node_camera_arm_vertical: None,
node_camera: None,
+ node_loader: None,
}
}
@@ -120,10 +124,14 @@ impl BasicDie {
self.node_camera_arm_vertical = search_node(&self.node_camera_arm_horizontal, String::from("CameraArmVertical"));
self.node_camera = search_node(&self.node_camera_arm_vertical, String::from("Camera"));
+ // look for the level loader in the hierarchy
+ self.node_loader = owner.get_node("/root/Game/LevelLoader");
+
godot_print!("{:?}", self.node_camera_root);
godot_print!("{:?}", self.node_camera_arm_horizontal);
godot_print!("{:?}", self.node_camera_arm_vertical);
godot_print!("{:?}", self.node_camera);
+ godot_print!("{:?}", self.node_loader);
self.node_die = search_node(&None, String::from("W8"));
@@ -173,10 +181,7 @@ impl BasicDie {
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 => {}
- }
+ self.stop_die(_owner);
}
// detect if the die stops moving
@@ -188,14 +193,8 @@ 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
- 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 => {}
- }
- //TODO: find out which side is up and update the current buff index accordingly
+
+ self.stop_die(_owner);
}
};
}
@@ -361,16 +360,43 @@ impl BasicDie {
}
};
- // apply the current buff
+ // actually add the force
+ die.apply_impulse(die.transform().origin, impulse_dir);
+
+ self.last_shot_time = OS::godot_singleton().get_ticks_msec();
+
+ // call the stuff in GDScript
+ match self.node_loader {
+ Some(loader) => {
+ let save_loader = loader.assume_safe();
+ save_loader.call("add_stroke", &[]);
+ },
+ None => godot_warn!("No node loader assigned"),
+ }
+ }
+
+ unsafe fn stop_die(&mut self, owner: &Spatial) {
+ //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.execute_buff(),
+ Some(ref mut buff) => buff.revert_buff(),
None => {}
}
- // actually add the force
- die.apply_impulse(die.transform().origin, impulse_dir);
+ // get the facing direction of the die and determine the next buff based on that
+ match self.node_die {
+ Some(die) => {
+ let forward = die.assume_safe().global_transform().basis.c().normalized();
+ godot_print!("forward: {} | {} | {}", forward.x, forward.y, forward.z);
+ },
+ None => {}
+ }
- self.last_shot_time = OS::godot_singleton().get_ticks_msec();
+ // 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 => {}
+ }
}
}