diff options
author | David <david003@gmx.net> | 2022-07-16 11:42:39 +0200 |
---|---|---|
committer | David <david003@gmx.net> | 2022-07-16 11:42:39 +0200 |
commit | 5678a04042b7b2ea52a927101cf66064535dc272 (patch) | |
tree | 8d2cb1625452f0ad3f4ca53bbe523e1b5562a9cb /rust/src/basic_die.rs | |
parent | bc0a59f2955b1e8bfd0870860d33c04205e6389e (diff) | |
download | 2022-5678a04042b7b2ea52a927101cf66064535dc272.tar.gz 2022-5678a04042b7b2ea52a927101cf66064535dc272.tar.bz2 2022-5678a04042b7b2ea52a927101cf66064535dc272.zip |
add separate shooting intensity
Diffstat (limited to '')
-rw-r--r-- | rust/src/basic_die.rs (renamed from rust/src/BasicDie.rs) | 101 |
1 files changed, 70 insertions, 31 deletions
diff --git a/rust/src/BasicDie.rs b/rust/src/basic_die.rs index 3f15de5..9dab3ce 100644 --- a/rust/src/BasicDie.rs +++ b/rust/src/basic_die.rs @@ -22,8 +22,10 @@ pub struct BasicDie { up_angle: f32, #[property(path="shooting/stopping_velocity")] stopping_velocity: f32, - #[property(path="input/mouse_sensitivity")] + #[property(path="input/camera_mouse_sensitivity")] mouse_sensitivity: Vector2, + #[property(path="input/shoot_sensitivity")] + shoot_sensitivity: f32, input_state: InputState, current_force: f32, @@ -49,6 +51,7 @@ impl BasicDie { up_angle: 5.0, stopping_velocity: 0.0, mouse_sensitivity: Vector2 { x: 1.0, y: 1.0 }, + shoot_sensitivity: 1.0, input_state: InputState::Default, current_force: 0.0, @@ -65,20 +68,6 @@ impl BasicDie { unsafe fn _ready(&mut self, owner: &RigidBody) { owner.set_physics_process(true); - // look for the horizontal camera arm - match owner.get_node(NodePath::from_str("CameraArmHorizontal")) { - Some(node) => { - let save_node = node.assume_safe(); - match save_node.cast::<Spatial>() { - Some(casted) => { - let save_casted = casted.claim(); - self.node_camera_arm_horizontal = Some(save_casted)}, - _ => godot_warn!("Camera Arm was not of type 'Spatial'"), - } - }, - _ => godot_warn!("No child node called 'Camera found'") - } - // look for the vertical camera arm match self.node_camera_arm_horizontal { Some(arm) => { @@ -121,8 +110,9 @@ impl BasicDie { } #[export] - unsafe fn _physics_process(&mut self, owner: &RigidBody, delta: f64) { + unsafe fn _physics_process(&mut self, owner: &RigidBody, _delta: f64) { + // detect if the die stops moving if matches!(self.input_state, InputState::Moving) { // get the current velocity let current_vel = owner.linear_velocity().length(); @@ -146,14 +136,68 @@ impl BasicDie { InputState::Shooting => self.shooting_input(owner, event), InputState::Moving => self.moving_input(event), } + + // look for the horizontal camera arm + match owner.get_node(NodePath::from_str("CameraArmHorizontal")) { + Some(node) => { + let save_node = node.assume_safe(); + match save_node.cast::<Spatial>() { + Some(casted) => { + let save_casted = casted.claim(); + self.node_camera_arm_horizontal = Some(save_casted)}, + _ => godot_warn!("Camera Arm was not of type 'Spatial'"), + } + }, + _ => godot_warn!("No horizontal arm found") + } + + // look for the vertical camera arm + match self.node_camera_arm_horizontal { + Some(arm) => { + let save_arm = arm.assume_safe(); + match save_arm.get_node(NodePath::from_str("CameraArmVertical")) { + Some(node) => { + let save_node = node.assume_safe(); + match save_node.cast::<Spatial>() { + Some(casted) => { + let save_casted = casted.claim(); + self.node_camera_arm_vertical = Some(save_casted)}, + _ => godot_warn!("Camera Arm was not of type 'Spatial'"), + } + }, + _ => godot_warn!("No vertical arm found.") + } + }, + _ => godot_warn!("No horizontal arm to look for the vertical arm") + } + + // look for the camera + match self.node_camera_arm_vertical { + Some(arm) => { + let save_arm = arm.assume_safe(); + match save_arm.get_node(NodePath::from_str("Camera")) { + Some(node) => { + let save_node = node.assume_safe(); + match save_node.cast::<Spatial>() { + Some(casted) => { + let save_casted = casted.claim(); + self.node_camera = Some(save_casted)}, + _ => godot_warn!("Camera was not of type 'Spatial'"), + } + }, + _ => godot_warn!("No camera found.") + } + }, + _ => godot_warn!("No vertical arm to look for the camera") + } } /// this input method will always be called, regardless of the input state unsafe fn general_input(&mut self, event: &Ref<InputEvent>) { let save_event = event.assume_safe(); - // get the input as mouse input - let mouse_event = save_event.cast::<InputEventMouseMotion>(); + // rotate camera horizontally + let mouse_event = save_event.cast::<InputEventMouseMotion>(); // get the input as mouse input match mouse_event { Some(motion_event) => { let x_mov = motion_event.relative().x * self.mouse_sensitivity.x; @@ -167,8 +211,6 @@ impl BasicDie { unsafe fn default_input(&mut self, event: Ref<InputEvent>) { let save_event = event.assume_safe(); - godot_print!("default input"); - // left mouse button was pressed => switch to shooting mode if save_event.is_action_pressed(GodotString::from_str(&self.action_shooting), false, false) { godot_print!("mouse_button, switching to shooting mode"); @@ -176,8 +218,8 @@ impl BasicDie { return; } - // get the input as mouse input - let mouse_event = save_event.cast::<InputEventMouseMotion>(); + // rotate camera vertically + let mouse_event = save_event.cast::<InputEventMouseMotion>(); // get the input as mouse input match mouse_event { Some(motion_event) => { let y_mov = -motion_event.relative().y * self.mouse_sensitivity.y; @@ -191,23 +233,22 @@ impl BasicDie { unsafe fn shooting_input(&mut self, owner: &RigidBody, event: Ref<InputEvent>) { let save_event = event.assume_safe(); - godot_print!("shooting input"); - + // mouse released, shoot if save_event.is_action_released(GodotString::from_str(&self.action_shooting), false) { self.input_state = InputState::Moving; self.shoot(owner); return; } - // get the input as mouse input - let mouse_event = save_event.cast::<InputEventMouseMotion>(); + // charge shot with vertical mouse movement + let mouse_event = save_event.cast::<InputEventMouseMotion>(); // get the input as mouse input match mouse_event { Some(motion_event) => { let y_mov = motion_event.relative().y * self.mouse_sensitivity.y; self.current_force = match self.current_force + y_mov { x if x < 0.0 => 0.0, x if x > self.max_force => self.max_force, - _ => self.current_force + y_mov + x => x }; godot_print!("current force: {}", self.current_force); @@ -220,10 +261,8 @@ impl BasicDie { unsafe fn moving_input(&mut self, event: Ref<InputEvent>) { let save_event = event.assume_safe(); - godot_print!("moving input"); - - // get the input as mouse input - let mouse_event = save_event.cast::<InputEventMouseMotion>(); + // rotate camera vertically + let mouse_event = save_event.cast::<InputEventMouseMotion>(); // get the input as mouse input match mouse_event { Some(motion_event) => { let y_mov = motion_event.relative().y * self.mouse_sensitivity.y; |