diff --git a/entity/coin_copper/coin_copper.gd b/entity/coin_copper/coin_copper.gd new file mode 100644 index 0000000..5a4a116 --- /dev/null +++ b/entity/coin_copper/coin_copper.gd @@ -0,0 +1,41 @@ +#extends RigidBody2D +# +# +## Called when the node enters the scene tree for the first time. +#func _ready(): +# pass # Replace with function body. +# +# +## Called every frame. 'delta' is the elapsed time since the previous frame. + + +extends RigidBody2D + +@export var sound_touch: AudioStreamPlayer + +var touched=false +var was_sleeping: bool = false + +func set_touched(): + touched=true + +func _on_sleeping_state_changed(): + was_sleeping = true + +func _on_body_entered(body): + + print("touch") + if not was_sleeping: + if touched==false and $Timer.is_stopped(): + print(str(self)+" hits "+str(body)) + #$sound_touch.play() + $Timer.start() + var other_node=body + if other_node.has_method("set_touched"): + other_node.set_touched() + +func _on_body_exited(body): + touched=false + + + diff --git a/entity/coin_copper/coin_copper.tscn b/entity/coin_copper/coin_copper.tscn index f78cdf8..08850eb 100644 --- a/entity/coin_copper/coin_copper.tscn +++ b/entity/coin_copper/coin_copper.tscn @@ -1,22 +1,28 @@ -[gd_scene load_steps=7 format=3 uid="uid://c3kitncwpi42j"] +[gd_scene load_steps=9 format=3 uid="uid://c3kitncwpi42j"] [ext_resource type="PhysicsMaterial" uid="uid://c6kn1an85lccr" path="res://entity/coin_physics_material.tres" id="1_1fypc"] +[ext_resource type="Script" path="res://entity/coin_copper/coin_copper.gd" id="2_1r8w3"] [ext_resource type="Texture2D" uid="uid://dbdkb4vt7dh85" path="res://entity/coin_copper/coin_copper_4.png" id="2_4pvkj"] [ext_resource type="Texture2D" uid="uid://2vtvoj6ua3cb" path="res://entity/coin_copper/coin_copper_outline_2.png" id="3_dq1f7"] [ext_resource type="PackedScene" uid="uid://bk1vvq5rug01m" path="res://collector/collectible.tscn" id="4_npwn2"] [ext_resource type="PackedScene" uid="uid://ujpra0s1kpqi" path="res://value/valuable.tscn" id="5_fd0r7"] +[ext_resource type="AudioStream" uid="uid://wy7f2j0wg1ur" path="res://audio/tap/click5.wav" id="7_fxd28"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_c6byl"] size = Vector2(14, 3) -[node name="CoinCopper" type="RigidBody2D"] +[node name="CoinCopper" type="RigidBody2D" node_paths=PackedStringArray("sound_touch")] collision_layer = 5 collision_mask = 7 inertia = 1000.0 physics_material_override = ExtResource("1_1fypc") continuous_cd = 1 +max_contacts_reported = 1 +contact_monitor = true linear_damp = 0.1 angular_damp = 0.1 +script = ExtResource("2_1r8w3") +sound_touch = NodePath("sound_touch") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] scale = Vector2(2, 2) @@ -37,4 +43,15 @@ type = &"Copper" [node name="Valuable" parent="." instance=ExtResource("5_fd0r7")] value = 1 +[node name="sound_touch" type="AudioStreamPlayer" parent="."] +stream = ExtResource("7_fxd28") +volume_db = -24.397 + +[node name="Timer" type="Timer" parent="."] +wait_time = 2.108 +one_shot = true + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] +[connection signal="body_exited" from="." to="." method="_on_body_exited"] +[connection signal="sleeping_state_changed" from="." to="." method="_on_sleeping_state_changed"] [connection signal="collected" from="Collectible" to="Collectible" method="_on_done"] diff --git a/game/game.tscn b/game/game.tscn index 9d6ead0..32348b2 100644 --- a/game/game.tscn +++ b/game/game.tscn @@ -77,7 +77,7 @@ shape = SubResource("RectangleShape2D_rh35r") debug_color = Color(0, 0.6, 0.701961, 0) [node name="CopperConverter" parent="." instance=ExtResource("7_ipeok")] -position = Vector2(131, 199) +position = Vector2(136, 165) metadata/_edit_group_ = true [node name="Spawner" parent="CopperConverter" index="6" node_paths=PackedStringArray("target")]