From c4775d327b563795c9773df19bd2dbe5c3e1286b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 22 Apr 2024 00:56:35 +0200 Subject: [PATCH] Update physics and add some sounds --- NOTICE.md | 2 +- behaviours/move_physics.gd | 17 ++++++++++++----- entities/fall.ogg | 3 +++ entities/fall.ogg.import | 19 +++++++++++++++++++ entities/fall.wav | 3 --- entities/fall.wav.import | 24 ------------------------ entities/monocle.gd | 10 ++++++++++ entities/monocle.tscn | 22 +++++++++++++--------- entities/skull.gd | 10 ++++++++++ entities/skull.tscn | 26 +++++++++++--------------- entities/top_hat.gd | 10 ++++++++++ entities/top_hat.tscn | 21 +++++++++++++-------- scenes/game/cursor.tscn | 1 + 13 files changed, 103 insertions(+), 65 deletions(-) create mode 100644 entities/fall.ogg create mode 100644 entities/fall.ogg.import delete mode 100644 entities/fall.wav delete mode 100644 entities/fall.wav.import diff --git a/NOTICE.md b/NOTICE.md index 0ec74e5..a71ac59 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -10,7 +10,7 @@ This project uses the following external assets: | `./temp/click&pop.wav` | https://freesound.org/people/GammaGool/sounds/730488/ | CC0 | | `./temp/pop.wav` | https://freesound.org/people/NovaSoundTechnology/sounds/727104/ | CC0 | | `./temp/mouth_pop.wav` | https://freesound.org/people/igaopuromalte/sounds/725453/ | Attribution 4 | -| `./temp/puff.wav` | https://freesound.org/people/JustInvoke/sounds/446124/ | Attribution 4 | +| `./entities/fall.ogg` | https://freesound.org/people/JustInvoke/sounds/446124/ | Attribution 4 | | `./temp/place.wav` | https://freesound.org/people/Planman/sounds/208111/ | CC0 | | `./temp/gore.wav` | https://freesound.org/people/MinecraftGamerLR/sounds/728695/ | Attribution 4 | | `./entities/skull_pickup.wav` | https://freesound.org/people/cliftonmcarlson/sounds/392883/ | CC0 | diff --git a/behaviours/move_physics.gd b/behaviours/move_physics.gd index 7e51e39..bb8524a 100644 --- a/behaviours/move_physics.gd +++ b/behaviours/move_physics.gd @@ -7,15 +7,16 @@ signal dropped signal fallen -@export var acceleration = 650.0 -@export var linear_damp = 18.0 +@export var acceleration = 1250.0 +@export var drag_damp = 0.4 +@export var drop_damp = 0.05 +@export var drop_epsilon = 16.0 var cursor: Cursor = null +var falling: bool = false var velocity := Vector2.ZERO -@onready var ticks_per_second = ProjectSettings.get_setting("physics/common/physics_ticks_per_second") - func drag(value: Cursor) -> void: cursor = value @@ -23,10 +24,12 @@ func drag(value: Cursor) -> void: func drop() -> void: cursor = null + falling = true dropped.emit() func fall() -> void: velocity = Vector2.ZERO + falling = false fallen.emit() @@ -35,5 +38,9 @@ func _physics_process(delta: float) -> void: if cursor: var gap = cursor.global_position - global_position velocity += gap * delta * acceleration - velocity *= 1.0 - linear_damp / ticks_per_second + velocity *= 1.0 - drag_damp + else: + velocity *= 1.0 - drop_damp + if falling and velocity.length() < drop_epsilon: + fall() move.emit(velocity * delta) diff --git a/entities/fall.ogg b/entities/fall.ogg new file mode 100644 index 0000000..d0e149b --- /dev/null +++ b/entities/fall.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2ceb2d1acdd2f606bc90bc5b578deec7f8987cc20a23b9e990c515be1dcc4f70 +size 10708 diff --git a/entities/fall.ogg.import b/entities/fall.ogg.import new file mode 100644 index 0000000..6caf55e --- /dev/null +++ b/entities/fall.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://cwsg776c11xfc" +path="res://.godot/imported/fall.ogg-ba2036bd4382e626c27cc3d1d5eb69f1.oggvorbisstr" + +[deps] + +source_file="res://entities/fall.ogg" +dest_files=["res://.godot/imported/fall.ogg-ba2036bd4382e626c27cc3d1d5eb69f1.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/entities/fall.wav b/entities/fall.wav deleted file mode 100644 index 2dbb33c..0000000 --- a/entities/fall.wav +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:39d8e006f4e8c678841a95097425c2452545a19946f40fdf917ce3601baa0d48 -size 359148 diff --git a/entities/fall.wav.import b/entities/fall.wav.import deleted file mode 100644 index 7d0b77e..0000000 --- a/entities/fall.wav.import +++ /dev/null @@ -1,24 +0,0 @@ -[remap] - -importer="wav" -type="AudioStreamWAV" -uid="uid://buxgivpkh8dyl" -path="res://.godot/imported/fall.wav-db08e68086e6fbfdfcb891d3b1804e1e.sample" - -[deps] - -source_file="res://entities/fall.wav" -dest_files=["res://.godot/imported/fall.wav-db08e68086e6fbfdfcb891d3b1804e1e.sample"] - -[params] - -force/8_bit=false -force/mono=false -force/max_rate=false -force/max_rate_hz=44100 -edit/trim=false -edit/normalize=false -edit/loop_mode=0 -edit/loop_begin=0 -edit/loop_end=-1 -compress/mode=0 diff --git a/entities/monocle.gd b/entities/monocle.gd index f129c22..c7d507f 100644 --- a/entities/monocle.gd +++ b/entities/monocle.gd @@ -4,3 +4,13 @@ class_name Monocle func _on_move(movement: Vector2) -> void: move_and_collide(movement) + +func _on_dragged(_cursor: Cursor) -> void: + collision_layer = 16 + collision_mask = 18 + z_index = 1 + +func _on_fallen() -> void: + collision_layer = 8 + collision_mask = 14 + z_index = 0 diff --git a/entities/monocle.tscn b/entities/monocle.tscn index 89c27db..3de9b9d 100644 --- a/entities/monocle.tscn +++ b/entities/monocle.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=7 format=3 uid="uid://b04xhv32ypi42"] +[gd_scene load_steps=8 format=3 uid="uid://b04xhv32ypi42"] [ext_resource type="Script" path="res://entities/monocle.gd" id="1_ehpfj"] [ext_resource type="Texture2D" uid="uid://d3tb6ypb36v8e" path="res://entities/monocle.png" id="1_omrit"] [ext_resource type="PackedScene" uid="uid://rx24bppccih7" path="res://behaviours/move_physics.tscn" id="2_jgnsw"] [ext_resource type="PackedScene" uid="uid://dijcjahkddudv" path="res://behaviours/draggable.tscn" id="3_e0ni5"] +[ext_resource type="AudioStream" uid="uid://cwsg776c11xfc" path="res://entities/fall.ogg" id="5_grwug"] [sub_resource type="CircleShape2D" id="CircleShape2D_o7chm"] radius = 12.0 @@ -12,8 +13,9 @@ radius = 12.0 radius = 24.0 [node name="Monocle" type="CharacterBody2D"] -collision_layer = 32 -collision_mask = 38 +collision_layer = 8 +collision_mask = 14 +motion_mode = 1 script = ExtResource("1_ehpfj") [node name="Sprite" type="Sprite2D" parent="."] @@ -26,18 +28,20 @@ shape = SubResource("CircleShape2D_o7chm") [node name="MovementDrag" parent="." instance=ExtResource("2_jgnsw")] [node name="Draggable" parent="MovementDrag" instance=ExtResource("3_e0ni5")] -collision_layer = 32 [node name="Shape" type="CollisionShape2D" parent="MovementDrag/Draggable"] shape = SubResource("CircleShape2D_juisb") debug_color = Color(1, 1, 1, 0) -[node name="FallTimer" type="Timer" parent="MovementDrag"] -wait_time = 0.5 -one_shot = true +[node name="DragSound" type="AudioStreamPlayer2D" parent="MovementDrag"] -[connection signal="dropped" from="MovementDrag" to="MovementDrag/FallTimer" method="start"] +[node name="FallSound" type="AudioStreamPlayer2D" parent="MovementDrag"] +stream = ExtResource("5_grwug") + +[connection signal="dragged" from="MovementDrag" to="." method="_on_dragged"] +[connection signal="dragged" from="MovementDrag" to="MovementDrag/DragSound" method="play" unbinds=1] +[connection signal="fallen" from="MovementDrag" to="." method="_on_fallen"] +[connection signal="fallen" from="MovementDrag" to="MovementDrag/FallSound" method="play"] [connection signal="move" from="MovementDrag" to="." method="_on_move"] [connection signal="dragged" from="MovementDrag/Draggable" to="MovementDrag" method="drag"] [connection signal="dropped" from="MovementDrag/Draggable" to="MovementDrag" method="drop"] -[connection signal="timeout" from="MovementDrag/FallTimer" to="MovementDrag" method="fall"] diff --git a/entities/skull.gd b/entities/skull.gd index 2f6a16a..9fcbdc6 100644 --- a/entities/skull.gd +++ b/entities/skull.gd @@ -4,3 +4,13 @@ class_name Skull func _on_move(movement: Vector2) -> void: move_and_collide(movement) + +func _on_dragged(_cursor: Cursor) -> void: + collision_layer = 16 + collision_mask = 18 + z_index = 1 + +func _on_fallen() -> void: + collision_layer = 8 + collision_mask = 14 + z_index = 0 diff --git a/entities/skull.tscn b/entities/skull.tscn index 8cdf288..d879aea 100644 --- a/entities/skull.tscn +++ b/entities/skull.tscn @@ -5,7 +5,7 @@ [ext_resource type="PackedScene" uid="uid://dijcjahkddudv" path="res://behaviours/draggable.tscn" id="2_h0icd"] [ext_resource type="PackedScene" uid="uid://rx24bppccih7" path="res://behaviours/move_physics.tscn" id="3_83m1a"] [ext_resource type="AudioStream" uid="uid://dq3xf4i2wpt50" path="res://entities/skull_drag.wav" id="5_duqrf"] -[ext_resource type="AudioStream" uid="uid://buxgivpkh8dyl" path="res://entities/fall.wav" id="6_b7mxf"] +[ext_resource type="AudioStream" uid="uid://cwsg776c11xfc" path="res://entities/fall.ogg" id="6_7yx26"] [sub_resource type="CircleShape2D" id="CircleShape2D_ypibs"] radius = 12.0 @@ -14,8 +14,9 @@ radius = 12.0 radius = 24.0 [node name="Skull" type="CharacterBody2D"] -collision_layer = 32 -collision_mask = 38 +collision_layer = 8 +collision_mask = 14 +motion_mode = 1 script = ExtResource("1_7g8bu") [node name="Sprite" type="Sprite2D" parent="."] @@ -28,26 +29,21 @@ shape = SubResource("CircleShape2D_ypibs") [node name="MovementDrag" parent="." instance=ExtResource("3_83m1a")] [node name="Draggable" parent="MovementDrag" instance=ExtResource("2_h0icd")] -collision_layer = 32 [node name="Shape" type="CollisionShape2D" parent="MovementDrag/Draggable"] shape = SubResource("CircleShape2D_1c7gd") debug_color = Color(1, 1, 1, 0) -[node name="DragSound" type="AudioStreamPlayer2D" parent="MovementDrag/Draggable"] +[node name="DragSound" type="AudioStreamPlayer2D" parent="MovementDrag"] stream = ExtResource("5_duqrf") -[node name="FallTimer" type="Timer" parent="MovementDrag"] -wait_time = 0.5 -one_shot = true +[node name="FallSound" type="AudioStreamPlayer2D" parent="MovementDrag"] +stream = ExtResource("6_7yx26") -[node name="FallSound" type="AudioStreamPlayer2D" parent="MovementDrag/FallTimer"] -stream = ExtResource("6_b7mxf") - -[connection signal="dropped" from="MovementDrag" to="MovementDrag/FallTimer" method="start"] +[connection signal="dragged" from="MovementDrag" to="." method="_on_dragged"] +[connection signal="dragged" from="MovementDrag" to="MovementDrag/DragSound" method="play" unbinds=1] +[connection signal="fallen" from="MovementDrag" to="." method="_on_fallen"] +[connection signal="fallen" from="MovementDrag" to="MovementDrag/FallSound" method="play"] [connection signal="move" from="MovementDrag" to="." method="_on_move"] [connection signal="dragged" from="MovementDrag/Draggable" to="MovementDrag" method="drag"] -[connection signal="dragged" from="MovementDrag/Draggable" to="MovementDrag/Draggable/DragSound" method="play" unbinds=1] [connection signal="dropped" from="MovementDrag/Draggable" to="MovementDrag" method="drop"] -[connection signal="timeout" from="MovementDrag/FallTimer" to="MovementDrag" method="fall"] -[connection signal="timeout" from="MovementDrag/FallTimer" to="MovementDrag/FallTimer/FallSound" method="play"] diff --git a/entities/top_hat.gd b/entities/top_hat.gd index 407bacc..1c66e29 100644 --- a/entities/top_hat.gd +++ b/entities/top_hat.gd @@ -4,3 +4,13 @@ class_name TopHat func _on_move(movement: Vector2) -> void: move_and_collide(movement) + +func _on_dragged(_cursor: Cursor) -> void: + collision_layer = 16 + collision_mask = 18 + z_index = 1 + +func _on_fallen() -> void: + collision_layer = 8 + collision_mask = 14 + z_index = 0 diff --git a/entities/top_hat.tscn b/entities/top_hat.tscn index 03a626e..30601a8 100644 --- a/entities/top_hat.tscn +++ b/entities/top_hat.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=7 format=3 uid="uid://8ejgwtkpaa44"] +[gd_scene load_steps=8 format=3 uid="uid://8ejgwtkpaa44"] [ext_resource type="Script" path="res://entities/top_hat.gd" id="1_0eh11"] [ext_resource type="Texture2D" uid="uid://deqvgvf66grr4" path="res://entities/top_hat.png" id="1_gbqic"] [ext_resource type="PackedScene" uid="uid://rx24bppccih7" path="res://behaviours/move_physics.tscn" id="3_gy414"] [ext_resource type="PackedScene" uid="uid://dijcjahkddudv" path="res://behaviours/draggable.tscn" id="4_fcvjo"] +[ext_resource type="AudioStream" uid="uid://cwsg776c11xfc" path="res://entities/fall.ogg" id="6_6tpnh"] [sub_resource type="CircleShape2D" id="CircleShape2D_o7chm"] radius = 12.0 @@ -12,8 +13,9 @@ radius = 12.0 radius = 24.0 [node name="TopHat" type="CharacterBody2D"] -collision_layer = 32 -collision_mask = 38 +collision_layer = 8 +collision_mask = 14 +motion_mode = 1 script = ExtResource("1_0eh11") [node name="Sprite" type="Sprite2D" parent="."] @@ -32,12 +34,15 @@ collision_layer = 32 shape = SubResource("CircleShape2D_juisb") debug_color = Color(1, 1, 1, 0) -[node name="FallTimer" type="Timer" parent="MovementDrag"] -wait_time = 0.5 -one_shot = true +[node name="DragSound" type="AudioStreamPlayer2D" parent="MovementDrag"] -[connection signal="dropped" from="MovementDrag" to="MovementDrag/FallTimer" method="start"] +[node name="FallSound" type="AudioStreamPlayer2D" parent="MovementDrag"] +stream = ExtResource("6_6tpnh") + +[connection signal="dragged" from="MovementDrag" to="." method="_on_dragged"] +[connection signal="dragged" from="MovementDrag" to="MovementDrag/DragSound" method="play" unbinds=1] +[connection signal="fallen" from="MovementDrag" to="." method="_on_fallen"] +[connection signal="fallen" from="MovementDrag" to="MovementDrag/FallSound" method="play"] [connection signal="move" from="MovementDrag" to="." method="_on_move"] [connection signal="dragged" from="MovementDrag/Draggable" to="MovementDrag" method="drag"] [connection signal="dropped" from="MovementDrag/Draggable" to="MovementDrag" method="drop"] -[connection signal="timeout" from="MovementDrag/FallTimer" to="MovementDrag" method="fall"] diff --git a/scenes/game/cursor.tscn b/scenes/game/cursor.tscn index 53c56f9..a85fb27 100644 --- a/scenes/game/cursor.tscn +++ b/scenes/game/cursor.tscn @@ -6,6 +6,7 @@ radius = 4.0 [node name="Cursor" type="Area2D" groups=["cursor"]] +z_index = 100 collision_layer = 64 collision_mask = 40 script = ExtResource("1_1og6v")