1
Fork 0
mirror of https://github.com/Steffo99/pineapple-surf.git synced 2024-11-24 08:44:18 +00:00

Refactor CanSink and SinkArea

This commit is contained in:
Steffo 2023-01-09 12:35:14 +01:00
parent 4e4ce8b14c
commit 03923adc03
Signed by: steffo
GPG key ID: 6965406171929D01
11 changed files with 72 additions and 51 deletions

12
island/CanSink.gd Normal file
View file

@ -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")

10
island/CanSink.tscn Normal file
View file

@ -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")

View file

@ -1,5 +0,0 @@
extends Node3D
class_name CanSplash
signal splashed()

View file

@ -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")

View file

@ -6,3 +6,7 @@ extends RigidBody3D
func _on_collectible_by_player_collected(): func _on_collectible_by_player_collected():
player.collected_fruit += 1 player.collected_fruit += 1
func _on_splash_sound_finished():
queue_free()

View file

@ -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="PackedScene" uid="uid://bwwpi0itor6cw" path="res://island/PineappleMesh.tscn" id="1_ndmmp"]
[ext_resource type="Script" path="res://island/Pineapple.gd" id="1_sbec5"] [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="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://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://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 height = 0.9
radius = 0.3 radius = 0.3
@ -21,7 +21,7 @@ script = ExtResource("1_sbec5")
[node name="Shape" type="CollisionShape3D" parent="."] [node name="Shape" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.45, 0) 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")] [node name="PineappleMesh" parent="." instance=ExtResource("1_ndmmp")]
@ -36,9 +36,11 @@ target_path = NodePath("..")
[node name="CollectibleByPlayer" parent="." instance=ExtResource("5_yps0c")] [node name="CollectibleByPlayer" parent="." instance=ExtResource("5_yps0c")]
target_path = NodePath("..") 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="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="MoveTowardsPlayer"]
[editable path="CollectibleByPlayer"] [editable path="CollectibleByPlayer"]
[editable path="CanSink"]

View file

@ -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)

View file

@ -1,18 +1,18 @@
[gd_scene load_steps=4 format=3 uid="uid://dh5blytk6vmdu"] [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="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"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_hpkdw"]
[node name="Sea" type="Node3D"] [node name="Sea" type="Node3D"]
script = ExtResource("1_45vpg")
[node name="SeaMesh" parent="." instance=ExtResource("1_ej5r1")] [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") 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"]

14
island/SinkArea.gd Normal file
View file

@ -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)

View file

@ -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/Player.gd" id="1_rujcr"]
[ext_resource type="Script" path="res://player/Head.gd" id="2_ohlgu"] [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="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="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="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"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_aqp8x"]
metallic_specular = 0.0 metallic_specular = 0.0
@ -79,6 +79,7 @@ grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
[node name="CameraViewportContainer" type="SubViewportContainer" parent="Head/Viewport"] [node name="CameraViewportContainer" type="SubViewportContainer" parent="Head/Viewport"]
layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
@ -118,6 +119,7 @@ theme = SubResource("Theme_smyke")
[node name="SubViewportContainer" type="SubViewportContainer" parent="HUD"] [node name="SubViewportContainer" type="SubViewportContainer" parent="HUD"]
show_behind_parent = true show_behind_parent = true
layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
@ -147,6 +149,7 @@ scale = Vector2(1.65, 1)
metadata/_edit_lock_ = true metadata/_edit_lock_ = true
[node name="PineappleLabel" type="Label" parent="HUD"] [node name="PineappleLabel" type="Label" parent="HUD"]
layout_mode = 1
anchors_preset = 2 anchors_preset = 2
anchor_top = 1.0 anchor_top = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
@ -161,6 +164,7 @@ text = "0 harvested"
vertical_alignment = 2 vertical_alignment = 2
[node name="AmmoLabel" type="Label" parent="HUD"] [node name="AmmoLabel" type="Label" parent="HUD"]
layout_mode = 1
anchors_preset = 3 anchors_preset = 3
anchor_left = 1.0 anchor_left = 1.0
anchor_top = 1.0 anchor_top = 1.0
@ -180,6 +184,7 @@ vertical_alignment = 2
[node name="Crosshair" type="ColorRect" parent="HUD"] [node name="Crosshair" type="ColorRect" parent="HUD"]
material = SubResource("ShaderMaterial_2p6rt") material = SubResource("ShaderMaterial_2p6rt")
layout_mode = 1
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
@ -195,6 +200,6 @@ metadata/_edit_lock_ = true
[node name="RigidDynamicBody3D" type="RigidBody3D" parent="."] [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"]

View file

@ -19,10 +19,10 @@ _global_script_classes=[{
"language": &"GDScript", "language": &"GDScript",
"path": "res://player/onhand/BaseWeapon.gd" "path": "res://player/onhand/BaseWeapon.gd"
}, { }, {
"base": "Node3D", "base": "Node",
"class": &"CanSplash", "class": &"CanSink",
"language": &"GDScript", "language": &"GDScript",
"path": "res://island/CanSplash.gd" "path": "res://island/CanSink.gd"
}, { }, {
"base": "Node3D", "base": "Node3D",
"class": &"CropTile", "class": &"CropTile",
@ -43,15 +43,21 @@ _global_script_classes=[{
"class": &"PlayerInputData", "class": &"PlayerInputData",
"language": &"GDScript", "language": &"GDScript",
"path": "res://player/PlayerInputData.gd" "path": "res://player/PlayerInputData.gd"
}, {
"base": "Area3D",
"class": &"SinkArea",
"language": &"GDScript",
"path": "res://island/SinkArea.gd"
}] }]
_global_script_class_icons={ _global_script_class_icons={
"BaseScene": "", "BaseScene": "",
"BaseWeapon": "", "BaseWeapon": "",
"CanSplash": "", "CanSink": "",
"CropTile": "", "CropTile": "",
"PeaShooter": "", "PeaShooter": "",
"Player": "", "Player": "",
"PlayerInputData": "" "PlayerInputData": "",
"SinkArea": ""
} }
[application] [application]