diff --git a/island/CanSink.gd b/island/CanSink.gd new file mode 100644 index 0000000..326bd78 --- /dev/null +++ b/island/CanSink.gd @@ -0,0 +1,12 @@ +extends Node +class_name CanSink + + +## This fell in the water. +## Triggers before SinkArea.has_sunk . +signal sank() + + +func sink(): + $SplashSound.play() + emit_signal("sank") diff --git a/island/CanSink.tscn b/island/CanSink.tscn new file mode 100644 index 0000000..0272afb --- /dev/null +++ b/island/CanSink.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=3 uid="uid://c6opu8v6xd660"] + +[ext_resource type="Script" path="res://island/CanSink.gd" id="1_bap2m"] +[ext_resource type="AudioStream" uid="uid://xretxahxbqdr" path="res://assets/splash.ogg" id="2_xqjos"] + +[node name="CanSink" type="Node"] +script = ExtResource("1_bap2m") + +[node name="SplashSound" type="AudioStreamPlayer3D" parent="."] +stream = ExtResource("2_xqjos") diff --git a/island/CanSplash.gd b/island/CanSplash.gd deleted file mode 100644 index 8e5f1f4..0000000 --- a/island/CanSplash.gd +++ /dev/null @@ -1,5 +0,0 @@ -extends Node3D -class_name CanSplash - - -signal splashed() diff --git a/island/CanSplash.tscn b/island/CanSplash.tscn deleted file mode 100644 index 803a526..0000000 --- a/island/CanSplash.tscn +++ /dev/null @@ -1,10 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://bj4d3a0jxgvpu"] - -[ext_resource type="Script" path="res://island/CanSplash.gd" id="1_vsqjx"] -[ext_resource type="AudioStream" uid="uid://xretxahxbqdr" path="res://assets/splash.ogg" id="2_y72wi"] - -[node name="CanSplash" type="Node3D"] -script = ExtResource("1_vsqjx") - -[node name="SplashSound" type="AudioStreamPlayer3D" parent="."] -stream = ExtResource("2_y72wi") diff --git a/island/Pineapple.gd b/island/Pineapple.gd index af5c0bb..3f5b158 100644 --- a/island/Pineapple.gd +++ b/island/Pineapple.gd @@ -6,3 +6,7 @@ extends RigidBody3D func _on_collectible_by_player_collected(): player.collected_fruit += 1 + + +func _on_splash_sound_finished(): + queue_free() diff --git a/island/Pineapple.tscn b/island/Pineapple.tscn index 5647e46..0e2a83a 100644 --- a/island/Pineapple.tscn +++ b/island/Pineapple.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://v7bv81krh12e"] +[gd_scene load_steps=9 format=3 uid="uid://cpqebnfkv5ee"] [ext_resource type="PackedScene" uid="uid://bwwpi0itor6cw" path="res://island/PineappleMesh.tscn" id="1_ndmmp"] [ext_resource type="Script" path="res://island/Pineapple.gd" id="1_sbec5"] @@ -6,9 +6,9 @@ [ext_resource type="Script" path="res://island/Pop.gd" id="4_rn5e2"] [ext_resource type="PackedScene" uid="uid://cvou86mnmtloe" path="res://island/MoveTowardsPlayer.tscn" id="4_xnsun"] [ext_resource type="PackedScene" uid="uid://ci0hy0d4d1476" path="res://island/CollectibleByPlayer.tscn" id="5_yps0c"] -[ext_resource type="PackedScene" uid="uid://bj4d3a0jxgvpu" path="res://island/CanSplash.tscn" id="7_3mgie"] +[ext_resource type="PackedScene" uid="uid://c6opu8v6xd660" path="res://island/CanSink.tscn" id="7_la8g5"] -[sub_resource type="CylinderShape3D" id="CylinderShape3D_q83gf"] +[sub_resource type="CylinderShape3D" id="CylinderShape3D_8v3m4"] height = 0.9 radius = 0.3 @@ -21,7 +21,7 @@ script = ExtResource("1_sbec5") [node name="Shape" type="CollisionShape3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.45, 0) -shape = SubResource("CylinderShape3D_q83gf") +shape = SubResource("CylinderShape3D_8v3m4") [node name="PineappleMesh" parent="." instance=ExtResource("1_ndmmp")] @@ -36,9 +36,11 @@ target_path = NodePath("..") [node name="CollectibleByPlayer" parent="." instance=ExtResource("5_yps0c")] target_path = NodePath("..") -[node name="CanSplash" parent="." instance=ExtResource("7_3mgie")] +[node name="CanSink" parent="." instance=ExtResource("7_la8g5")] [connection signal="collected" from="CollectibleByPlayer" to="." method="_on_collectible_by_player_collected"] +[connection signal="finished" from="CanSink/SplashSound" to="." method="_on_splash_sound_finished"] [editable path="MoveTowardsPlayer"] [editable path="CollectibleByPlayer"] +[editable path="CanSink"] diff --git a/island/Sea.gd b/island/Sea.gd deleted file mode 100644 index 7fbadb4..0000000 --- a/island/Sea.gd +++ /dev/null @@ -1,17 +0,0 @@ -extends Node3D - - -signal splashed(splasher: CanSplash) - - -func splash(splasher: CanSplash): - var splash_sound = splasher.get_node("SplashSound") - splash_sound.play() - splasher.emit_signal("splashed") - emit_signal("splashed", splasher) - - -func _on_splash_area_body_entered(body: Node3D): - var splashers: Array[Node] = body.find_children("*", "CanSplash", false, false) - for splasher in splashers: - splash(splasher) diff --git a/island/Sea.tscn b/island/Sea.tscn index 993c6d0..87f7957 100644 --- a/island/Sea.tscn +++ b/island/Sea.tscn @@ -1,18 +1,18 @@ [gd_scene load_steps=4 format=3 uid="uid://dh5blytk6vmdu"] -[ext_resource type="Script" path="res://island/Sea.gd" id="1_45vpg"] [ext_resource type="PackedScene" uid="uid://c7lblmilr3gob" path="res://island/SeaMesh.tscn" id="1_ej5r1"] +[ext_resource type="Script" path="res://island/SinkArea.gd" id="3_0nuyu"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_hpkdw"] [node name="Sea" type="Node3D"] -script = ExtResource("1_45vpg") [node name="SeaMesh" parent="." instance=ExtResource("1_ej5r1")] -[node name="SplashArea" type="Area3D" parent="."] +[node name="SinkArea" type="Area3D" parent="."] +script = ExtResource("3_0nuyu") -[node name="Shape" type="CollisionShape3D" parent="SplashArea"] +[node name="Shape" type="CollisionShape3D" parent="SinkArea"] shape = SubResource("WorldBoundaryShape3D_hpkdw") -[connection signal="body_entered" from="SplashArea" to="." method="_on_splash_area_body_entered"] +[connection signal="body_entered" from="SinkArea" to="SinkArea" method="_on_body_entered"] diff --git a/island/SinkArea.gd b/island/SinkArea.gd new file mode 100644 index 0000000..b626d55 --- /dev/null +++ b/island/SinkArea.gd @@ -0,0 +1,14 @@ +extends Area3D +class_name SinkArea + + +## A node fell in the water. +## Triggers after CanSink.sunk . +signal has_sunk(splasher: CanSink) + + +func _on_body_entered(body: Node3D): + var sinkables: Array[CanSink] = body.find_children("*", "CanSink", false, false) + for sinkable in sinkables: + sinkable.sink() + emit_signal("has_sunk", sinkable) diff --git a/player/Player.tscn b/player/Player.tscn index 19db56c..384b971 100644 --- a/player/Player.tscn +++ b/player/Player.tscn @@ -1,11 +1,11 @@ -[gd_scene load_steps=14 format=3 uid="uid://b5i1sqd88wlle"] +[gd_scene load_steps=14 format=3 uid="uid://btjp3g623h4y0"] [ext_resource type="Script" path="res://player/Player.gd" id="1_rujcr"] [ext_resource type="Script" path="res://player/Head.gd" id="2_ohlgu"] [ext_resource type="Script" path="res://player/OnHand.gd" id="3_3rcjl"] [ext_resource type="Theme" uid="uid://c5a1nyqumj46j" path="res://menu/menu_theme.tres" id="4_d7ru6"] [ext_resource type="Shader" path="res://player/crosshair.gdshader" id="4_dut1p"] -[ext_resource type="PackedScene" uid="uid://bj4d3a0jxgvpu" path="res://island/CanSplash.tscn" id="6_la1ga"] +[ext_resource type="PackedScene" uid="uid://c6opu8v6xd660" path="res://island/CanSink.tscn" id="6_c0n0a"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_aqp8x"] metallic_specular = 0.0 @@ -79,6 +79,7 @@ grow_horizontal = 2 grow_vertical = 2 [node name="CameraViewportContainer" type="SubViewportContainer" parent="Head/Viewport"] +layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 @@ -118,6 +119,7 @@ theme = SubResource("Theme_smyke") [node name="SubViewportContainer" type="SubViewportContainer" parent="HUD"] show_behind_parent = true +layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 @@ -147,6 +149,7 @@ scale = Vector2(1.65, 1) metadata/_edit_lock_ = true [node name="PineappleLabel" type="Label" parent="HUD"] +layout_mode = 1 anchors_preset = 2 anchor_top = 1.0 anchor_bottom = 1.0 @@ -161,6 +164,7 @@ text = "0 harvested" vertical_alignment = 2 [node name="AmmoLabel" type="Label" parent="HUD"] +layout_mode = 1 anchors_preset = 3 anchor_left = 1.0 anchor_top = 1.0 @@ -180,6 +184,7 @@ vertical_alignment = 2 [node name="Crosshair" type="ColorRect" parent="HUD"] material = SubResource("ShaderMaterial_2p6rt") +layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 @@ -195,6 +200,6 @@ metadata/_edit_lock_ = true [node name="RigidDynamicBody3D" type="RigidBody3D" parent="."] -[node name="CanSplash" parent="." instance=ExtResource("6_la1ga")] +[node name="CanSink" parent="." instance=ExtResource("6_c0n0a")] -[connection signal="splashed" from="CanSplash" to="." method="respawn"] +[connection signal="sank" from="CanSink" to="." method="respawn"] diff --git a/project.godot b/project.godot index 3f0ffa1..7488bc6 100644 --- a/project.godot +++ b/project.godot @@ -19,10 +19,10 @@ _global_script_classes=[{ "language": &"GDScript", "path": "res://player/onhand/BaseWeapon.gd" }, { -"base": "Node3D", -"class": &"CanSplash", +"base": "Node", +"class": &"CanSink", "language": &"GDScript", -"path": "res://island/CanSplash.gd" +"path": "res://island/CanSink.gd" }, { "base": "Node3D", "class": &"CropTile", @@ -43,15 +43,21 @@ _global_script_classes=[{ "class": &"PlayerInputData", "language": &"GDScript", "path": "res://player/PlayerInputData.gd" +}, { +"base": "Area3D", +"class": &"SinkArea", +"language": &"GDScript", +"path": "res://island/SinkArea.gd" }] _global_script_class_icons={ "BaseScene": "", "BaseWeapon": "", -"CanSplash": "", +"CanSink": "", "CropTile": "", "PeaShooter": "", "Player": "", -"PlayerInputData": "" +"PlayerInputData": "", +"SinkArea": "" } [application]