From 4986ea3dd9f1c33f2ba90988b951d169aee1cf3b Mon Sep 17 00:00:00 2001 From: Leandro Schmidt Date: Wed, 10 Jan 2024 16:27:29 -0300 Subject: [PATCH] 0.6.6 --- data/scenes/scenario.rgs | Bin 152657 -> 152681 bytes game/src/bn_engine/game_controller.rs | 0 game/src/bn_engine/mod.rs | 1 - game/src/bn_engine/player_engine.rs | 3 - game/src/bn_scripts/mod.rs | 3 +- game/src/bn_scripts/objects_scripts/mod.rs | 1 + game/src/bn_scripts/objects_scripts/slider.rs | 54 ++++++++++++ .../player_scripts/camera_moviment.rs | 30 +++---- .../player_scripts/foot_collider.rs | 40 ++++++++- .../player_scripts/player_moviment.rs | 63 +++++++++----- game/src/lib.rs | 11 ++- settings.ron | 78 +++++++++++------- 12 files changed, 207 insertions(+), 77 deletions(-) delete mode 100644 game/src/bn_engine/game_controller.rs delete mode 100644 game/src/bn_engine/mod.rs delete mode 100644 game/src/bn_engine/player_engine.rs create mode 100644 game/src/bn_scripts/objects_scripts/mod.rs create mode 100644 game/src/bn_scripts/objects_scripts/slider.rs diff --git a/data/scenes/scenario.rgs b/data/scenes/scenario.rgs index 9c72e0fc830cac56f9b105cc1990d88ab81a98a9..a84db7416a1f7c9f103a26e9cd7f87778aa10702 100644 GIT binary patch delta 888 zcmcb(g7f7H&JEky*gh<{z2G?G=DloAOtxWOOZPGWfrVDReTt@*{o%uQ_O2x{w#6!T z_TRQ^?NH=$12Apg;n?? z)8xv0>CF@N{b!tP@V9HTMnbL#E`@tKkrZZE;a2#6F_OY{Q*bKW?7IesYk_{Ba15v1 z1_dwbD&9PyG9`6xg!cpz?8-g#Gb|ed5)Py{0v-B4kQWj zZ#HaCV%%=0!1Re}@&^IC?K7m9=5w=3gN)n`bVxnp^xf)A9c&J=NFpaRncCSV$RUaR zGGtPo{#~0XmCZm3CcKDoI*T4t3R{87!+r)7&|r_kWoWSH015=;7iX4a=I3!k zBteQC4s5pJT*k!q;d>P0L8i$IOHA1ewr>NOEZ_f;Y4SD&>Fo(@Ow3G^4GP333rP7* z4yaPxyhAXXcXPqaUdGMa6l7R&>HTSiP45crToGJ4Y(g=0C~bb@nuAkEeLglF`UyC7 zY(85qD2~;BCMm4Kz(DZWhiQr8=I`rpd!+jYHXT+caqBqu37d}E$2fItmidjtBOjTz z$BQ!V5X0e}?VkFK$s&^v*m7>)>dfd3i~8woZj2Gr7q~NWPml3t4CP`2rV-DQ)LcWO z=?gs=7qCq@)D27((l^$vBm9daFBQ4@85rKchdR<@AqkjMmd-{eXml52N7p zD{hR!)6KmZrKSh?GHOk?_FzoizSEnro*Ba52U3{s&L}s%%b)Q)+lPxOg%I;~r}qRf z&VeSw?RtTX=Z^3*0$sxna#68=o?~Xw_K$K*p)A`Aq?qniVt=RCAy`73ct{IY1HR>1qZ*g%AFL z+yxTm6B7{tI>A3D#W%mSI2D$ewy$?%+Qzt9ASQ}&`mz8f Uuid { + uuid!("af230ca1-43ea-4024-a25e-93a9a567c6d7") + } +} + +impl ScriptTrait for Slider { + fn on_init(&mut self, _context: &mut ScriptContext) { + // Put initialization logic here. + } + + fn on_start(&mut self, _context: &mut ScriptContext) { + // There should be a logic that depends on other scripts in scene. + // It is called right after **all** scripts were initialized. + } + + fn on_deinit(&mut self, _context: &mut ScriptDeinitContext) { + // Put de-initialization logic here. + } + + fn on_os_event(&mut self, _event: &Event<()>, _context: &mut ScriptContext) { + // Respond to OS events here. + } + + fn on_update(&mut self, _context: &mut ScriptContext) { + // Put object logic here. + } + + fn id(&self) -> Uuid { + Self::type_uuid() + } +} diff --git a/game/src/bn_scripts/player_scripts/camera_moviment.rs b/game/src/bn_scripts/player_scripts/camera_moviment.rs index e9ef8ab..4a10ce9 100644 --- a/game/src/bn_scripts/player_scripts/camera_moviment.rs +++ b/game/src/bn_scripts/player_scripts/camera_moviment.rs @@ -8,6 +8,7 @@ use fyrox::{ }, event::{DeviceEvent, Event}, impl_component_provider, + scene::transform::Transform, script::{ScriptContext, ScriptTrait}, }; @@ -17,17 +18,26 @@ pub struct CameraMoviment { pub yaw: f32, } impl CameraMoviment { - //Mouse Detect Function - pub fn process_input_event(&mut self, event: &Event<()>) { + //Mouse Detect Function Pitch + pub fn process_camera_moviment_pitch(&mut self, event: &Event<()>, camera_node: &mut Transform) { match event { Event::DeviceEvent { event, .. } => { if let DeviceEvent::MouseMotion { delta } = event { self.yaw -= delta.0 as f32; self.pitch = (self.pitch + delta.1 as f32).clamp(-90.0, 90.0); + camera_node.set_rotation(UnitQuaternion::from_axis_angle( + &Vector3::x_axis(), + //The 3 is mouse sensitivy + self.pitch.to_radians() / 3., + )); } } _ => (), } + } + //Mouse Detect Function Yaw + pub fn process_camera_moviment_yaw(camera_node: &mut Transform) { + } pub fn get_pitch(&mut self) -> f32 { return self.pitch; @@ -52,20 +62,10 @@ impl ScriptTrait for CameraMoviment { self.yaw = 0.0; //Horizontal View } - fn on_os_event(&mut self, event: &Event<()>, _context: &mut ScriptContext) { + fn on_os_event(&mut self, event: &Event<()>, context: &mut ScriptContext) { // Enable mouse detection - self.process_input_event(event); - } - - fn on_update(&mut self, context: &mut ScriptContext) { - //Mouse Vertical View - context.scene.graph[context.handle] - .local_transform_mut() - .set_rotation(UnitQuaternion::from_axis_angle( - &Vector3::x_axis(), - //The 3 is mouse sensitivy - self.pitch.to_radians() / 3., - )); + let camera_node = context.scene.graph[context.handle].local_transform_mut(); + self.process_camera_moviment_pitch(event, camera_node); } fn id(&self) -> Uuid { diff --git a/game/src/bn_scripts/player_scripts/foot_collider.rs b/game/src/bn_scripts/player_scripts/foot_collider.rs index e243759..e303c43 100644 --- a/game/src/bn_scripts/player_scripts/foot_collider.rs +++ b/game/src/bn_scripts/player_scripts/foot_collider.rs @@ -1,5 +1,5 @@ use fyrox::{ - core::{ + core::{ pool::Handle, reflect::prelude::*, uuid::{uuid, Uuid}, @@ -7,13 +7,14 @@ use fyrox::{ TypeUuidProvider, }, impl_component_provider, - scene::{collider::Collider, graph::Graph, node::Node}, + scene::{collider::Collider, graph::Graph, node::Node, rigidbody::RigidBody}, script::{ScriptContext, ScriptTrait}, }; #[derive(Visit, Reflect, Default, Debug, Clone)] pub struct FootCollider { pub is_on_air: bool, + pub is_on_slider: bool, } impl FootCollider { pub fn has_ground_contact(&mut self, handle: Handle, graph: &Graph) -> bool { @@ -28,8 +29,38 @@ impl FootCollider { } false } - pub fn is_in_air(&mut self) -> bool { - return self.is_on_air; + pub fn has_slider_contact(&mut self, handle: Handle, graph: &Graph) -> bool { + if let Some(collider) = graph.try_get(handle).and_then(|n| n.cast::()) { + for contact in collider.contacts(&graph.physics) { + for manifold in contact.manifolds.iter() { + // Checking the actual foot collision + if let Some(actual_collider) = graph + .try_get(manifold.rigid_body2) + .and_then(|n| n.cast::()) + { + // If is a slider then + if actual_collider.tag() == "Slider" { + if manifold.local_n1.y.abs() > 0.7 || manifold.local_n2.y.abs() > 0.7 { + return true; + } + } + } + // // This is the player collision so doesnt need it + // if let Some(actual_collider) = graph + // .try_get(manifold.rigid_body1) + // .and_then(|n| n.cast::()) + // { + // if actual_collider.tag() == "Slider" { + // if manifold.local_n1.y.abs() > 0.7 || manifold.local_n2.y.abs() > 0.7 { + // return true; + // } + // } + // } + return false; + } + } + } + return false; } } impl_component_provider!(FootCollider); @@ -49,6 +80,7 @@ impl ScriptTrait for FootCollider { fn on_update(&mut self, context: &mut ScriptContext) { // Updating the variable self.is_on_air = !self.has_ground_contact(context.handle, &context.scene.graph); + self.is_on_slider = self.has_slider_contact(context.handle, &context.scene.graph); } fn id(&self) -> Uuid { diff --git a/game/src/bn_scripts/player_scripts/player_moviment.rs b/game/src/bn_scripts/player_scripts/player_moviment.rs index 5229653..478d853 100644 --- a/game/src/bn_scripts/player_scripts/player_moviment.rs +++ b/game/src/bn_scripts/player_scripts/player_moviment.rs @@ -1,6 +1,7 @@ use fyrox::{ core::{ algebra::{ArrayStorage, Const, Matrix, UnitQuaternion, Vector3}, + log::Log, pool::Handle, reflect::prelude::*, uuid::{uuid, Uuid}, @@ -35,7 +36,8 @@ pub struct PlayerMoviment { ticks_reset_cooldown: i32, acceleration: f32, straffing: bool, - old_mouse_position: f32, + old_camera_yaw: f32, + old_camera_pitch: f32, } impl PlayerMoviment { /// Process all keyboard for player moviment @@ -107,15 +109,17 @@ impl PlayerMoviment { &mut self, velocity: Matrix, Const<1>, ArrayStorage>, is_on_air: bool, + is_on_slide: bool, is_frontal_collide: bool, is_pressing_s: bool, acceleration_mouse: f32, ) -> Matrix, Const<1>, ArrayStorage> { let mut base_velocity = velocity; + let calculate_acceleration: bool = is_on_air || is_on_slide; for i in 0..3 { //If is in the air and moving the camera if i != 1 - && is_on_air + && calculate_acceleration && acceleration_mouse != 0. && !is_pressing_s && !is_frontal_collide @@ -145,7 +149,7 @@ impl PlayerMoviment { self.acceleration += acceleration; base_velocity[i] *= self.acceleration; //If is only in the air - } else if i != 1 && is_on_air && !is_pressing_s && !is_frontal_collide { + } else if i != 1 && calculate_acceleration && !is_pressing_s && !is_frontal_collide { self.ticks_dessaceleration = 0; base_velocity[i] *= self.acceleration; @@ -164,7 +168,9 @@ impl PlayerMoviment { } base_velocity[i] *= self.acceleration; //If is fronta colission - } else if is_frontal_collide { + } + // If is frontal collide + else if is_frontal_collide { self.acceleration /= 3.; if self.acceleration <= 1. { self.acceleration = 1.; @@ -172,14 +178,18 @@ impl PlayerMoviment { } base_velocity[i] *= self.acceleration; //If pressing S - } else if is_pressing_s { + } + // If pressed the S + else if is_pressing_s { self.acceleration /= 2.; if self.acceleration <= 1. { self.acceleration = 1.; self.straffing = false; } base_velocity[i] *= self.acceleration; - } else { + } + // In others cases the velocity multiplys by acceleration + else { base_velocity[i] *= self.acceleration; } } @@ -191,8 +201,10 @@ impl PlayerMoviment { /// to change the player velocity and then change the position of the player pub fn calculate_acceleration(&mut self, context: &mut ScriptContext) { let mut is_on_air: bool = false; + let mut is_on_slide: bool = false; let mut is_frontal_collide: bool = false; let mut camera_yaw: f32 = 0.0; + let mut camera_pitch: f32 = 0.0; //Getting variables from others scripts { // Receiving the cameras @@ -211,6 +223,7 @@ impl PlayerMoviment { .try_get_script_of::(self.foot_collider_node) { is_on_air = foot_collider_node_script_ref.is_on_air; + is_on_slide = foot_collider_node_script_ref.is_on_slider; } // Receiving the frontal collider @@ -235,7 +248,8 @@ impl PlayerMoviment { // Keep only vertical velocity, and drop horizontal. let mut velocity = Vector3::new(0.0, body.lin_vel().y, 0.0); let mut dessacelerate: bool = false; - let mut mouse_accelerate: f32 = 0.; + let mut mouse_accelerate_yaw: f32 = 0.; + let mut mouse_accelerate_pitch: f32 = 0.; // Change the velocity depending on the keys pressed. if self.position_z || self.straffing { @@ -248,16 +262,16 @@ impl PlayerMoviment { velocity -= body.look_vector() * 2.; dessacelerate = true; } - if self.position_x { + if self.position_x && !is_on_slide { // If we moving left then add "side" vector of the body. velocity += body.side_vector() * 2.; } - if self.position_x_negative { + if self.position_x_negative && !is_on_slide { // If we moving right then subtract "side" vector of the body. velocity -= body.side_vector() * 2.; } // Jump System - if self.jump && !is_on_air && self.ticks_jump_cooldown <= 3 { + if self.jump && !is_on_slide && !is_on_air && self.ticks_jump_cooldown <= 3 { //Check if is the first tick if self.ticks_jump_cooldown == -1 { self.ticks_jump_cooldown = 0; @@ -272,32 +286,41 @@ impl PlayerMoviment { self.ticks_jump_cooldown = -1; } // Calculation the acceleration by mouse movement - if self.old_mouse_position != camera_yaw.to_radians() { + if self.old_camera_yaw != camera_yaw.to_radians() { //Calculates the mouse velocity - let mut _player_mouse_position: f32 = 0.; + let mut mouse_position_yaw: f32 = 0.; //Negative to Positive if camera_yaw.to_radians() < 0. { - _player_mouse_position = camera_yaw.to_radians().abs(); + mouse_position_yaw = camera_yaw.to_radians().abs(); } else { - _player_mouse_position = camera_yaw.to_radians(); + mouse_position_yaw = camera_yaw.to_radians(); } //Difference between - if _player_mouse_position != self.old_mouse_position { - if _player_mouse_position < self.old_mouse_position { - mouse_accelerate = self.old_mouse_position - _player_mouse_position; + if mouse_position_yaw != self.old_camera_yaw { + if mouse_position_yaw < self.old_camera_yaw { + mouse_accelerate_yaw = self.old_camera_yaw - mouse_position_yaw; } else { - mouse_accelerate = _player_mouse_position - self.old_mouse_position; + mouse_accelerate_yaw = mouse_position_yaw - self.old_camera_yaw; } } - self.old_mouse_position = _player_mouse_position + self.old_camera_yaw = mouse_position_yaw + } + // Calculation the acceleration by slider moviment + if self.old_camera_pitch != camera_pitch.to_radians() { + let mut mouse_position_pitch: f32 = 0.; + mouse_position_pitch = camera_pitch.to_radians(); + Log::info(mouse_position_pitch.to_string()); + + self.old_camera_pitch = mouse_position_pitch; } // Change the velocity of the player body.set_lin_vel(self.velocity( velocity, is_on_air, + is_on_slide, is_frontal_collide, dessacelerate, - mouse_accelerate, + mouse_accelerate_yaw, )); //Reset Tick Cooldown if self.ticks_reset_cooldown <= 30 { diff --git a/game/src/lib.rs b/game/src/lib.rs index e4ec827..9c893ae 100644 --- a/game/src/lib.rs +++ b/game/src/lib.rs @@ -1,11 +1,10 @@ //Bunny to Rust Dependencies -pub mod bn_engine; pub mod bn_scripts; -use bn_scripts::player_scripts::{ +use bn_scripts::{player_scripts::{ camera_moviment::CameraMoviment, foot_collider::FootCollider, frontal_collider::FrontalCollider, player_hand::PlayerHand, player_moviment::PlayerMoviment, -}; +}, objects_scripts::slider::Slider}; //Dependencies use fyrox::{ core::pool::Handle, @@ -21,6 +20,7 @@ pub struct GameConstructor; impl PluginConstructor for GameConstructor { fn register(&self, context: PluginRegistrationContext) { + // Player context .serialization_context .script_constructors @@ -41,6 +41,11 @@ impl PluginConstructor for GameConstructor { .serialization_context .script_constructors .add::("Frontal Collider"); + // Objects + context + .serialization_context + .script_constructors + .add::("Object Slider"); } fn create_instance(&self, scene_path: Option<&str>, context: PluginContext) -> Box { diff --git a/settings.ron b/settings.ron index 6151b13..c26212c 100644 --- a/settings.ron +++ b/settings.ron @@ -1,7 +1,7 @@ ( selection: ( ignore_back_faces: false, - track_selection: true, + track_selection: false, ), graphics: ( quality: ( @@ -316,133 +316,151 @@ scene_settings: { "data/scenes/scenario.rgs": ( camera_settings: ( - position: (0.0, 1.0, 0.0), - yaw: 0.0, - pitch: 0.0, + position: (-6.722241, 9.869497, 5.9338374), + yaw: 1.4900002, + pitch: 0.72999984, ), node_infos: { ( - index: 31, + index: 10, generation: 1, ): ( is_expanded: false, ), ( - index: 6, + index: 15, generation: 1, ): ( - is_expanded: false, + is_expanded: true, ), ( - index: 2, + index: 6, generation: 1, ): ( is_expanded: true, ), ( - index: 16, + index: 31, generation: 1, ): ( is_expanded: false, ), ( - index: 40, + index: 13, generation: 1, ): ( is_expanded: false, ), ( - index: 22, + index: 3, generation: 1, ): ( - is_expanded: false, + is_expanded: true, ), ( - index: 37, + index: 44, + generation: 1, + ): ( + is_expanded: true, + ), + ( + index: 28, generation: 1, ): ( is_expanded: false, ), ( - index: 25, + index: 37, generation: 1, ): ( is_expanded: false, ), ( - index: 1, + index: 45, generation: 1, ): ( is_expanded: true, ), ( - index: 43, + index: 25, generation: 1, ): ( is_expanded: false, ), ( - index: 10, + index: 7, generation: 1, ): ( is_expanded: false, ), ( - index: 5, + index: 16, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 4, generation: 1, ): ( is_expanded: true, ), ( - index: 0, + index: 5, generation: 1, ): ( is_expanded: true, ), ( - index: 13, + index: 19, generation: 1, ): ( is_expanded: false, ), ( - index: 34, + index: 1, generation: 1, ): ( is_expanded: false, ), ( - index: 15, + index: 43, generation: 1, ): ( is_expanded: true, ), ( - index: 7, + index: 40, generation: 1, ): ( is_expanded: false, ), ( - index: 19, + index: 34, generation: 1, ): ( is_expanded: false, ), ( - index: 3, + index: 22, + generation: 1, + ): ( + is_expanded: false, + ), + ( + index: 0, generation: 1, ): ( is_expanded: true, ), ( - index: 28, + index: 42, generation: 1, ): ( - is_expanded: false, + is_expanded: true, ), ( - index: 4, + index: 2, generation: 1, ): ( is_expanded: true, @@ -456,8 +474,8 @@ ], ), windows: ( - window_position: (0.0, 0.0), - window_size: (740.0, 570.0), + window_position: (6.0, 281.0), + window_size: (1065.0, 739.0), layout: None, ), ) \ No newline at end of file