aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar David <david003@gmx.net>2022-07-16 11:42:39 +0200
committerLibravatar David <david003@gmx.net>2022-07-16 11:42:39 +0200
commit5678a04042b7b2ea52a927101cf66064535dc272 (patch)
tree8d2cb1625452f0ad3f4ca53bbe523e1b5562a9cb
parentbc0a59f2955b1e8bfd0870860d33c04205e6389e (diff)
download2022-5678a04042b7b2ea52a927101cf66064535dc272.tar.gz
2022-5678a04042b7b2ea52a927101cf66064535dc272.tar.bz2
2022-5678a04042b7b2ea52a927101cf66064535dc272.zip
add separate shooting intensity
-rw-r--r--godot/scenes/Game.tscn8
-rwxr-xr-xlib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.sobin25309816 -> 28011904 bytes
-rw-r--r--rust/src/basic_die.rs (renamed from rust/src/BasicDie.rs)101
-rw-r--r--rust/src/game.rs2
-rw-r--r--rust/src/lib.rs4
5 files changed, 77 insertions, 38 deletions
diff --git a/godot/scenes/Game.tscn b/godot/scenes/Game.tscn
index f569f85..ca90458 100644
--- a/godot/scenes/Game.tscn
+++ b/godot/scenes/Game.tscn
@@ -17,11 +17,11 @@ script = ExtResource( 1 )
[node name="RigidBody" type="RigidBody" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.25589, 0 )
script = ExtResource( 2 )
-camera/camera_clamp = Vector2( 0, -1.5 )
-shooting/max_force = 100.0
+camera/camera_clamp = Vector2( 1.608, -2.526 )
+shooting/max_force = 30.0
shooting/up_angle = 1.0
-shooting/stopping_velocity = 10.0
-input/mouse_sensitivity = Vector2( 0.05, 0.05 )
+input/camera_mouse_sensitivity = Vector2( 0.01, 0.008 )
+input/shoot_sensitivity = 0.069
[node name="MeshInstance" type="MeshInstance" parent="RigidBody"]
mesh = SubResource( 1 )
diff --git a/lib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.so b/lib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.so
index 140affc..dcceb97 100755
--- a/lib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.so
+++ b/lib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.so
Binary files differ
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;
diff --git a/rust/src/game.rs b/rust/src/game.rs
index 16c93d8..61b23ed 100644
--- a/rust/src/game.rs
+++ b/rust/src/game.rs
@@ -40,5 +40,5 @@ impl Game {
// This function will be called in every frame
#[export]
- unsafe fn _process(&self, _owner: &Spatial, delta: f64) {}
+ unsafe fn _process(&self, _owner: &Spatial, _delta: f64) { }
}
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index e2ed1ac..1041272 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -1,6 +1,6 @@
mod game;
mod spinning_cube;
-mod BasicDie;
+mod basic_die;
use gdnative::prelude::{godot_init, InitHandle};
@@ -8,7 +8,7 @@ use gdnative::prelude::{godot_init, InitHandle};
fn init(handle: InitHandle) {
handle.add_class::<game::Game>();
handle.add_class::<spinning_cube::SpinningCube>();
- handle.add_class::<BasicDie::BasicDie>();
+ handle.add_class::<basic_die::BasicDie>();
}
// macros that create the entry-points of the dynamic library.