water combo

This commit is contained in:
veclavtalica 2025-02-12 04:34:07 +03:00
parent afe7f632e8
commit f08f820948
7 changed files with 91 additions and 5 deletions

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=12 format=3 uid="uid://oyvhcwq60v2"] [gd_scene load_steps=13 format=3 uid="uid://oyvhcwq60v2"]
[ext_resource type="Script" path="res://src/ingame/ingame.gd" id="1_akuuj"] [ext_resource type="Script" path="res://src/ingame/ingame.gd" id="1_akuuj"]
[ext_resource type="PackedScene" uid="uid://cs8c570bxh6u" path="res://src/ingame/player.tscn" id="2_w1gjc"] [ext_resource type="PackedScene" uid="uid://cs8c570bxh6u" path="res://src/ingame/player.tscn" id="2_w1gjc"]
[ext_resource type="PackedScene" uid="uid://bysgtksvovyur" path="res://src/ingame/sprout.tscn" id="3_2xvqq"] [ext_resource type="PackedScene" uid="uid://bysgtksvovyur" path="res://src/ingame/sprout.tscn" id="3_2xvqq"]
[ext_resource type="Script" path="res://src/ingame/ui.gd" id="3_p340v"]
[ext_resource type="PackedScene" uid="uid://enukqx63dh2l" path="res://src/ingame/pipe.tscn" id="4_mltw3"] [ext_resource type="PackedScene" uid="uid://enukqx63dh2l" path="res://src/ingame/pipe.tscn" id="4_mltw3"]
[sub_resource type="BoxShape3D" id="BoxShape3D_l0cfx"] [sub_resource type="BoxShape3D" id="BoxShape3D_l0cfx"]
@ -43,7 +44,9 @@ _chat_panel_inactive = NodePath("UI/ChatPanelInactive")
_chat_history_inactive = NodePath("UI/ChatPanelInactive/ChatHistoryScroll/ChatHistory") _chat_history_inactive = NodePath("UI/ChatPanelInactive/ChatHistoryScroll/ChatHistory")
_chat_history_scroll_inactive = NodePath("UI/ChatPanelInactive/ChatHistoryScroll") _chat_history_scroll_inactive = NodePath("UI/ChatPanelInactive/ChatHistoryScroll")
[node name="UI" type="CanvasLayer" parent="."] [node name="UI" type="CanvasLayer" parent="." node_paths=PackedStringArray("_combo_timer")]
script = ExtResource("3_p340v")
_combo_timer = NodePath("ComboTimer")
[node name="ChatPanel" type="Panel" parent="UI"] [node name="ChatPanel" type="Panel" parent="UI"]
visible = false visible = false
@ -137,6 +140,27 @@ layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
[node name="Combo" type="Label" parent="UI"]
visible = false
self_modulate = Color(0.534784, 0.97046, 3.46541e-06, 1)
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -11.5
offset_right = 20.0
offset_bottom = 11.5
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
text = "+5!"
[node name="ComboTimer" type="Timer" parent="UI"]
wait_time = 3.0
one_shot = true
[node name="CSGBox3D" type="CSGBox3D" parent="."] [node name="CSGBox3D" type="CSGBox3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 7.45058e-09, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 7.45058e-09, 0)
collision_mask = 0 collision_mask = 0
@ -266,3 +290,4 @@ transform = Transform3D(0.999929, -0.0119378, 0, -0.0119378, -0.999929, 8.74228e
[connection signal="text_submitted" from="UI/ChatPanel/ChatInput" to="." method="_on_chat_message_submitted"] [connection signal="text_submitted" from="UI/ChatPanel/ChatInput" to="." method="_on_chat_message_submitted"]
[connection signal="pressed" from="UI/ChatPanel/ChatSendButton" to="." method="_on_chat_message_submitted"] [connection signal="pressed" from="UI/ChatPanel/ChatSendButton" to="." method="_on_chat_message_submitted"]
[connection signal="timeout" from="UI/ComboTimer" to="UI" method="_on_combo_timer_timeout"]

View File

@ -120,6 +120,7 @@ func _unhandled_input(event: InputEvent) -> void:
_set_projectile_authority.rpc(new_projectile.get_path(), id) _set_projectile_authority.rpc(new_projectile.get_path(), id)
new_projectile.set_global_pos.rpc(_projectile_point.global_position) new_projectile.set_global_pos.rpc(_projectile_point.global_position)
new_projectile.sender_body = self new_projectile.sender_body = self
new_projectile.sender_id = id
new_projectile.body.process_mode = Node.PROCESS_MODE_INHERIT new_projectile.body.process_mode = Node.PROCESS_MODE_INHERIT
new_projectile.body.linear_velocity = -_camera.global_basis.z * _projectile_speed new_projectile.body.linear_velocity = -_camera.global_basis.z * _projectile_speed

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=9 format=3 uid="uid://cs8c570bxh6u"] [gd_scene load_steps=12 format=3 uid="uid://cs8c570bxh6u"]
[ext_resource type="Script" path="res://src/ingame/player.gd" id="1_isrmf"] [ext_resource type="Script" path="res://src/ingame/player.gd" id="1_isrmf"]
[ext_resource type="PackedScene" uid="uid://tdsbo3e5ic86" path="res://src/ingame/water_bomb.tscn" id="2_naek4"] [ext_resource type="PackedScene" uid="uid://tdsbo3e5ic86" path="res://src/ingame/water_bomb.tscn" id="2_naek4"]
[ext_resource type="AudioStream" uid="uid://3dlhs18w1fa2" path="res://assets/sfx/boom.wav" id="3_u2hxa"] [ext_resource type="AudioStream" uid="uid://3dlhs18w1fa2" path="res://assets/sfx/boom.wav" id="3_u2hxa"]
[ext_resource type="Shader" path="res://scenes/interactivity_outline.gdshader" id="4_a2qfj"]
[ext_resource type="PackedScene" uid="uid://s2a1pry5fw8f" path="res://scenes/water_bomb_model.tscn" id="4_bfvih"] [ext_resource type="PackedScene" uid="uid://s2a1pry5fw8f" path="res://scenes/water_bomb_model.tscn" id="4_bfvih"]
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_2xotl"] [sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_2xotl"]
@ -31,6 +32,20 @@ properties/5/replication_mode = 2
[sub_resource type="SphereShape3D" id="SphereShape3D_rsfjy"] [sub_resource type="SphereShape3D" id="SphereShape3D_rsfjy"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_nch7m"]
resource_local_to_scene = true
render_priority = 0
shader = ExtResource("4_a2qfj")
shader_parameter/color = Color(1, 1, 1, 0)
shader_parameter/size = 1.24
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_x7r08"]
resource_local_to_scene = true
next_pass = SubResource("ShaderMaterial_nch7m")
albedo_color = Color(0.0936238, 0.825356, 1, 1)
metallic = 0.8
roughness = 0.4
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("_projectile_holder", "_projectile_point", "_camera_pivot", "_camera", "_line_of_sight", "_shot_sound")] [node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("_projectile_holder", "_projectile_point", "_camera_pivot", "_camera", "_line_of_sight", "_shot_sound")]
collision_layer = 2 collision_layer = 2
script = ExtResource("1_isrmf") script = ExtResource("1_isrmf")
@ -83,6 +98,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.2, -1)
visible = false visible = false
[node name="Model" parent="CameraPivot/HeldViewmodel" instance=ExtResource("4_bfvih")] [node name="Model" parent="CameraPivot/HeldViewmodel" instance=ExtResource("4_bfvih")]
material_override = SubResource("StandardMaterial3D_x7r08")
[node name="ShotSound" type="AudioStreamPlayer3D" parent="."] [node name="ShotSound" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource("3_u2hxa") stream = ExtResource("3_u2hxa")

View File

@ -16,10 +16,17 @@ func _on_production_timer_timeout() -> void:
_need_water_drop.show() _need_water_drop.show()
@rpc("authority", "call_local", "reliable")
func _reflect_combo() -> void:
GameState.fetch().player_data[multiplayer.get_unique_id()].chain_water_combo(1)
@rpc("any_peer", "call_local", "reliable") @rpc("any_peer", "call_local", "reliable")
func water() -> void: func water(sender_id: int) -> void:
if needs_water: if needs_water:
needs_water = false needs_water = false
_need_water_drop.hide() _need_water_drop.hide()
if sender_id != 0:
_reflect_combo.rpc_id(sender_id)
_production_timer.start() _production_timer.start()

23
src/ingame/ui.gd Normal file
View File

@ -0,0 +1,23 @@
extends CanvasLayer
@export var _combo_timer: Timer
var _id: int
func _ready() -> void:
_id = multiplayer.get_unique_id()
GameState.fetch().player_data[_id].water_combo_update.connect(
func(current: int):
if current == 0:
$Combo.hide()
else:
$Combo.show()
$Combo.text = "+" + str(current) + "!"
_combo_timer.start()
)
func _on_combo_timer_timeout() -> void:
GameState.fetch().player_data[_id].reset_water_combo()
$Combo.hide()

View File

@ -12,6 +12,7 @@ extends Node3D
var _in_splash_range := {} var _in_splash_range := {}
## something to ignore ## something to ignore
var sender_id: int
var sender_body: PhysicsBody3D var sender_body: PhysicsBody3D
func _ready() -> void: func _ready() -> void:
@ -41,7 +42,7 @@ func _on_body_entered(p_body: Node3D) -> void:
return return
for area: Area3D in _in_splash_range: for area: Area3D in _in_splash_range:
area.get_parent_node_3d().water.rpc_id(1) area.get_parent_node_3d().water.rpc_id(1, sender_id)
_splash_small_sound.play() _splash_small_sound.play()
_splash_small_quiet_sound.play() _splash_small_quiet_sound.play()

View File

@ -2,3 +2,16 @@ class_name PlayerData
extends Resource extends Resource
@export var username: String @export var username: String
## How many plants are watered in a time window.
var _water_combo: int
signal water_combo_update(current: int)
func chain_water_combo(amount: int) -> void:
_water_combo += amount
emit_signal("water_combo_update", _water_combo)
func reset_water_combo() -> void:
_water_combo = 0
emit_signal("water_combo_update", _water_combo)