diff options
Diffstat (limited to '')
-rw-r--r-- | godot/scenes/levels/test_scene_movement/TestSceneMovement.tscn | 1 | ||||
-rw-r--r-- | godot/scenes/objects/W8.tscn | 21 | ||||
-rwxr-xr-x | lib/x86_64-unknown-linux-gnu/libcode_with_your_friends2022.so | bin | 29349984 -> 30388072 bytes | |||
-rw-r--r-- | rust/src/basic_die.rs | 41 | ||||
-rw-r--r-- | rust/src/buff_ball.rs | 91 | ||||
-rw-r--r-- | rust/src/buff_bounce.rs | 52 | ||||
-rw-r--r-- | rust/src/buff_extra.rs | 4 | ||||
-rw-r--r-- | rust/src/buff_phase.rs | 27 |
8 files changed, 130 insertions, 107 deletions
diff --git a/godot/scenes/levels/test_scene_movement/TestSceneMovement.tscn b/godot/scenes/levels/test_scene_movement/TestSceneMovement.tscn index d23236b..d1c08e3 100644 --- a/godot/scenes/levels/test_scene_movement/TestSceneMovement.tscn +++ b/godot/scenes/levels/test_scene_movement/TestSceneMovement.tscn @@ -28,3 +28,4 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 40, -1, -20 ) transform = Transform( 0.766044, 0, 0.642788, 0, 2, 0, -0.642788, 0, 0.766044, 19.47, 0, -14 ) [node name="PlayerRoot" parent="." instance=ExtResource( 3 )] +input/current_buff_index = 1 diff --git a/godot/scenes/objects/W8.tscn b/godot/scenes/objects/W8.tscn index 91f58eb..8766011 100644 --- a/godot/scenes/objects/W8.tscn +++ b/godot/scenes/objects/W8.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://assets/game_objects/W8baseColor_Mat.material" type="Material" id=2] @@ -20,12 +20,27 @@ surfaces/0 = { [sub_resource type="ConvexPolygonShape" id=2] points = PoolVector3Array( -0.0850063, -0.879389, -0.0282584, 0.0288993, 0.929375, 0.0289349, 0.0288993, 0.929375, -0.0289349, 0.929367, -0.0289314, 0.0289314, -0.0289784, -0.0289338, 0.929338, -0.929369, 0.028929, 0.028929, 0.0288993, -0.0289349, -0.929375, 0.0288993, -0.929375, 0.0289349, -0.0850063, 0.0282584, -0.879389, 0.0282247, 0.084959, 0.87945, 0.857489, 0.056933, -0.0855785, -0.879454, -0.0849424, 0.0282549, 0.0570775, -0.885814, -0.0571088, 0.0570775, -0.0571088, 0.885814, -0.0571532, 0.885743, -0.0571043, -0.0571532, 0.885743, 0.0571043, 0.0570775, 0.0571088, -0.885814, -0.885806, -0.057097, -0.057097, 0.879446, 0.0849494, 0.0282572, 0.857335, -0.0571018, -0.0855632, -0.0571532, 0.0571043, 0.885743, -0.0571532, -0.885743, 0.0571043, -0.885806, 0.057097, -0.057097, -0.0571532, -0.0571043, -0.885743, 0.0570775, 0.0571088, 0.885814, -0.0571532, -0.885743, -0.0571043, -0.0571532, 0.0571043, -0.885743, 0.0570775, -0.885814, 0.0571088, 0.0570775, 0.885814, 0.0571088, -0.0571532, -0.0571043, 0.885743, -0.885806, 0.057097, 0.057097, 0.0570775, 0.885814, -0.0571088, 0.0570775, -0.0571088, -0.885814, 0.857335, -0.0571018, 0.0855632, -0.885806, -0.057097, 0.057097, 0.857489, 0.056933, 0.0855785, 0.929425, 0.0287513, -0.0289333, 0.929367, -0.0289314, -0.0289314, -0.0289784, 0.929338, -0.0289338, 0.0288993, 0.0289349, -0.929375, -0.929369, -0.028929, -0.028929, -0.0283039, -0.87942, -0.0849561, 0.084933, 0.0282608, 0.879461, -0.0289784, 0.929338, 0.0289338, -0.0289784, -0.0289338, -0.929338, -0.0289784, 0.0289338, 0.929338, 0.0288993, -0.0289349, 0.929375, 0.0288993, -0.929375, -0.0289349, -0.0289784, -0.929338, 0.0289338, -0.929369, 0.028929, -0.028929, -0.0283039, 0.0849561, -0.87942, -0.879454, -0.0282549, 0.0849424, 0.879512, 0.0280816, 0.0849558, 0.879446, -0.0849494, -0.0282572, -0.0282988, -0.822574, 0.141805, 0.17021, 0.0280745, -0.794261, -0.879454, 0.0849424, -0.0282549, -0.0283039, 0.87942, 0.0849561, 0.0282247, 0.87945, -0.084959, 0.0282247, -0.084959, -0.87945, -0.879454, -0.0282549, -0.0849424, -0.0850063, 0.0282584, 0.879389, -0.0850063, 0.879389, 0.0282584, 0.084933, -0.0282608, 0.879461 ) +[sub_resource type="SphereShape" id=3] + +[sub_resource type="SphereMesh" id=4] + [node name="RigidBody" type="RigidBody"] -[node name="Cone" type="MeshInstance" parent="."] +[node name="MeshDie" type="MeshInstance" parent="."] mesh = SubResource( 1 ) skeleton = NodePath("../..") material/0 = null -[node name="CollisionShape" type="CollisionShape" parent="."] +[node name="CollisionShapeDie" type="CollisionShape" parent="."] shape = SubResource( 2 ) + +[node name="CollisionShapeSphere" type="CollisionShape" parent="."] +transform = Transform( 0.7, 0, 0, 0, 0.7, 0, 0, 0, 0.7, 0, 0, 0 ) +shape = SubResource( 3 ) +disabled = true + +[node name="MeshSphere" type="MeshInstance" parent="."] +transform = Transform( 0.7, 0, 0, 0, 0.7, 0, 0, 0, 0.7, 0, 0, 0 ) +visible = false +mesh = SubResource( 4 ) +material/0 = ExtResource( 2 ) 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 Binary files differindex 03ade02..78eca51 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 diff --git a/rust/src/basic_die.rs b/rust/src/basic_die.rs index 2a61197..dc425b4 100644 --- a/rust/src/basic_die.rs +++ b/rust/src/basic_die.rs @@ -1,6 +1,11 @@ use std::borrow::Borrow; use gdnative::api::*; use gdnative::prelude::*; +use crate::buff_trait::Buff; +use crate::buff_ball::BuffBall; +use crate::buff_bounce::BuffBounce; +use crate::buff_phase::BuffPhase; +use crate::buff_extra::BuffExtra; /// the input state for the player enum InputState { @@ -31,6 +36,10 @@ pub struct BasicDie { mouse_sensitivity: Vector2, #[property(path="input/shoot_sensitivity")] shoot_sensitivity: f32, + #[property(path="input/current_buff_index")] + current_buff_index: i8, + + all_buffs: [Option<Box<dyn Buff>>; 5], input_state: InputState, current_force: f32, @@ -62,6 +71,8 @@ impl BasicDie { stopping_min_ms: 1000, mouse_sensitivity: Vector2 { x: 1.0, y: 1.0 }, shoot_sensitivity: 1.0, + current_buff_index: 0, + all_buffs: [None, None, None, None, None], input_state: InputState::Default, current_force: 0.0, @@ -116,6 +127,23 @@ impl BasicDie { self.node_die = search_node(&None, String::from("W8")); + let die = match self.node_die { + None => { godot_warn!("No W8 assigned."); return; }, + Some(node) => + match node.assume_safe().cast::<RigidBody>() { + None => { godot_warn!("W8 is not a RigidBody."); return; }, + Some(rb) => rb.claim() + } + }; + + self.all_buffs = [ + None, + Some(Box::new(BuffBall ::new(Box::new(die)))), + Some(Box::new(BuffBounce::new(Box::new(die)))), + Some(Box::new(BuffPhase ::new(Box::new(die)))), + Some(Box::new(BuffExtra ::new())), + ]; + godot_print!("Player is ready"); } @@ -148,6 +176,13 @@ 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 + 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 } }; } @@ -313,6 +348,12 @@ impl BasicDie { } }; + // apply the current buff + match self.all_buffs[self.current_buff_index as usize] { + Some(ref mut buff) => buff.execute_buff(), + None => {} + } + // actually add the force die.apply_impulse(die.transform().origin, impulse_dir); diff --git a/rust/src/buff_ball.rs b/rust/src/buff_ball.rs index 4b89dbb..219e675 100644 --- a/rust/src/buff_ball.rs +++ b/rust/src/buff_ball.rs @@ -2,71 +2,66 @@ use gdnative::api::*; use gdnative::prelude::*; use crate::buff_trait::Buff; -struct BuffBall { +pub struct BuffBall { name: String, description: String, - - die_body: Option<Ref<RigidBody>>, - sphere_body: Option<Ref<RigidBody>> + collision_die: Ref<CollisionShape>, + collision_sphere: Ref<CollisionShape>, + mesh_die: Ref<MeshInstance>, + mesh_sphere: Ref<MeshInstance>, } impl BuffBall { - fn new(die_body: Option<Ref<RigidBody>>, sphere_body: Option<Ref<RigidBody>>) -> Self { + + pub fn new(die_body: Box<Ref<RigidBody>>) -> Self { + + // find a collision shape + fn search<T: SubClass<Node>> (die_body: &Box<Ref<RigidBody>>, name: String) -> Option<Ref<T>> { + unsafe{ + match die_body.assume_safe().get_node(&name) { + None => { + godot_warn!("Could not find {}", name); + None + } + Some(node) => { + match node.assume_safe().cast::<T>() { + None => { + godot_warn!("{} is not a {}", name, std::any::type_name::<T>()); + None + }, + Some(cs) => Some(cs.claim()) + } + } + } + } + } + BuffBall { name: String::from("Ball"), description: String::from("Roll the dice"), - - die_body, - sphere_body + collision_die: search::<CollisionShape>(&die_body, String::from("CollisionShapeDie" )).unwrap(), + collision_sphere: search::<CollisionShape>(&die_body, String::from("CollisionShapeSphere")).unwrap(), + mesh_die: search::<MeshInstance>(&die_body, String::from("MeshDie" )).unwrap(), + mesh_sphere: search::<MeshInstance>(&die_body, String::from("MeshSphere")).unwrap(), } } } impl Buff for BuffBall { unsafe fn execute_buff(&mut self) { - // make sure the sphere rigid body exists - match &self.sphere_body { - Some(sphere) => { - // make sure the dice rigid body exists - match &self.die_body { - Some(die) => { - // get the safe references from the ref<> - let save_sphere = sphere.assume_safe(); - let save_die = die.assume_safe(); - - // set the properties of the rigid bodies - save_die.set_process(false); - save_sphere.set_process(true); - save_sphere.show(); - }, - None => godot_warn!("Die body not assigned") - } - }, - None => godot_warn!("Sphere body not assigned") - } + self.collision_die.assume_safe().set_disabled(true); + self.collision_sphere.assume_safe().set_disabled(false); + self.mesh_die.assume_safe().set_visible(false); + self.mesh_sphere.assume_safe().set_visible(true); + godot_print!("Ball activated"); } unsafe fn revert_buff(&mut self) { - // make sure the sphere rigid body exists - match &self.sphere_body { - Some(sphere) => { - // make sure the dice rigid body exists - match &self.die_body { - Some(die) => { - // get the safe references from the ref<> - let save_sphere = sphere.assume_safe(); - let save_die = die.assume_safe(); - - // set the properties of the rigid bodies - save_die.set_process(true); - save_sphere.set_process(false); - save_sphere.hide(); - }, - None => godot_warn!("Die body not assigned") - } - }, - None => godot_warn!("Sphere body not assigned") - } + self.collision_die.assume_safe().set_disabled(false); + self.collision_sphere.assume_safe().set_disabled(true); + self.mesh_sphere.assume_safe().set_visible(false); + self.mesh_die.assume_safe().set_visible(true); + godot_print!("Ball deactivated"); } fn get_name(self) -> GodotString { diff --git a/rust/src/buff_bounce.rs b/rust/src/buff_bounce.rs index 179642d..cb9ded8 100644 --- a/rust/src/buff_bounce.rs +++ b/rust/src/buff_bounce.rs @@ -2,22 +2,21 @@ use gdnative::api::*; use gdnative::prelude::*; use crate::buff_trait::Buff; -struct BuffBounce { +pub struct BuffBounce { name: String, description: String, - rigid_body: Option<Ref<RigidBody>>, + rigid_body: Box<Ref<RigidBody>>, target_bounciness: f64, previous_bounciness: f64 } impl BuffBounce { - fn new(rigid_body: Option<Ref<RigidBody>>) -> Self { + pub fn new(rigid_body: Box<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 } @@ -25,43 +24,30 @@ impl BuffBounce { } 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") - } + unsafe fn execute_buff(&mut self) { + // get the physics material + match self.rigid_body.assume_safe().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!("No rigid body initialized to apply properties to") + None => godot_warn!("Physics material was not found") } + godot_print!("Bounce activated"); } 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") - } + // get the physics material + match self.rigid_body.assume_safe().physics_material_override() { + Some(mat) => { + let save_mat = mat.assume_safe(); + save_mat.set_bounce(self.previous_bounciness); }, - None => godot_warn!("No rigid body initialized to apply properties to") + None => godot_warn!("Physics material was not found") } + godot_print!("Bounce deactivated"); } fn get_name(self) -> GodotString { diff --git a/rust/src/buff_extra.rs b/rust/src/buff_extra.rs index 473cdde..a7b7902 100644 --- a/rust/src/buff_extra.rs +++ b/rust/src/buff_extra.rs @@ -2,13 +2,13 @@ use gdnative::api::*; use gdnative::prelude::*; use crate::buff_trait::Buff; -struct BuffExtra { +pub struct BuffExtra { name: String, description: String, } impl BuffExtra { - fn new() -> Self { + pub fn new() -> Self { BuffExtra { name: String::from("Extra Stroke"), description: String::from("One additional stroke that doesn't count"), diff --git a/rust/src/buff_phase.rs b/rust/src/buff_phase.rs index e64508e..f69fecc 100644 --- a/rust/src/buff_phase.rs +++ b/rust/src/buff_phase.rs @@ -2,16 +2,16 @@ use gdnative::api::*; use gdnative::prelude::*; use crate::buff_trait::Buff; -struct BuffPhase { +pub struct BuffPhase { name: String, description: String, - rigid_body: Option<Ref<RigidBody>>, + rigid_body: Box<Ref<RigidBody>>, wall_layer_bit: i64, } impl BuffPhase { - fn new(rigid_body: Option<Ref<RigidBody>>) -> Self { + pub fn new(rigid_body: Box<Ref<RigidBody>>) -> Self { // calculate the bit for the mask to enable/ disable collision detection let mask_layer = 2; let mask_bit = 2_i64.pow(mask_layer - 1); @@ -20,7 +20,6 @@ impl BuffPhase { name: String::from("Phase"), description: String::from("Phases through thin fences"), rigid_body, - wall_layer_bit: mask_bit, } } @@ -28,26 +27,12 @@ impl BuffPhase { impl Buff for BuffPhase { unsafe fn execute_buff(&mut self) { - match &self.rigid_body { - Some(body) => { - // actually disable the collision to the fences - let save_body = body.assume_safe(); - save_body.set_collision_mask_bit(self.wall_layer_bit, false); - }, - None => godot_warn!("Rigid body not found") - } + // actually disable the collision to the fences + self.rigid_body.assume_safe().set_collision_mask_bit(self.wall_layer_bit, false); } unsafe fn revert_buff(& mut self) { - // make sure the rigid body exists - match &self.rigid_body { - Some(body) => { - // actually enable the collision again - let save_body = body.assume_safe(); - save_body.set_collision_mask_bit(self.wall_layer_bit, false); - }, - None => godot_warn!("Rigid body not found") - } + self.rigid_body.assume_safe().set_collision_mask_bit(self.wall_layer_bit, false); } fn get_name(self) -> GodotString { |