From f08f820948a1142b4bfac4201435d2d940a6db32 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Wed, 12 Feb 2025 04:34:07 +0300 Subject: [PATCH] water combo --- src/ingame/ingame.tscn | 29 +++++++++++++++++++++++++++-- src/ingame/player.gd | 1 + src/ingame/player.tscn | 18 +++++++++++++++++- src/ingame/sprout.gd | 9 ++++++++- src/ingame/ui.gd | 23 +++++++++++++++++++++++ src/ingame/water_bomb.gd | 3 ++- src/lib/player_data.gd | 13 +++++++++++++ 7 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 src/ingame/ui.gd diff --git a/src/ingame/ingame.tscn b/src/ingame/ingame.tscn index 304239f..8c87e95 100644 --- a/src/ingame/ingame.tscn +++ b/src/ingame/ingame.tscn @@ -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="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="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"] [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_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"] visible = false @@ -137,6 +140,27 @@ layout_mode = 2 size_flags_horizontal = 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="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 7.45058e-09, 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="pressed" from="UI/ChatPanel/ChatSendButton" to="." method="_on_chat_message_submitted"] +[connection signal="timeout" from="UI/ComboTimer" to="UI" method="_on_combo_timer_timeout"] diff --git a/src/ingame/player.gd b/src/ingame/player.gd index ee61af7..a60c500 100644 --- a/src/ingame/player.gd +++ b/src/ingame/player.gd @@ -120,6 +120,7 @@ func _unhandled_input(event: InputEvent) -> void: _set_projectile_authority.rpc(new_projectile.get_path(), id) new_projectile.set_global_pos.rpc(_projectile_point.global_position) new_projectile.sender_body = self + new_projectile.sender_id = id new_projectile.body.process_mode = Node.PROCESS_MODE_INHERIT new_projectile.body.linear_velocity = -_camera.global_basis.z * _projectile_speed diff --git a/src/ingame/player.tscn b/src/ingame/player.tscn index ed89fd8..5c812e5 100644 --- a/src/ingame/player.tscn +++ b/src/ingame/player.tscn @@ -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="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="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"] [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="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")] collision_layer = 2 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 [node name="Model" parent="CameraPivot/HeldViewmodel" instance=ExtResource("4_bfvih")] +material_override = SubResource("StandardMaterial3D_x7r08") [node name="ShotSound" type="AudioStreamPlayer3D" parent="."] stream = ExtResource("3_u2hxa") diff --git a/src/ingame/sprout.gd b/src/ingame/sprout.gd index 7a67309..f35a65f 100644 --- a/src/ingame/sprout.gd +++ b/src/ingame/sprout.gd @@ -16,10 +16,17 @@ func _on_production_timer_timeout() -> void: _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") -func water() -> void: +func water(sender_id: int) -> void: if needs_water: needs_water = false _need_water_drop.hide() + if sender_id != 0: + _reflect_combo.rpc_id(sender_id) _production_timer.start() diff --git a/src/ingame/ui.gd b/src/ingame/ui.gd new file mode 100644 index 0000000..cf19e60 --- /dev/null +++ b/src/ingame/ui.gd @@ -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() diff --git a/src/ingame/water_bomb.gd b/src/ingame/water_bomb.gd index bc29e8b..53c3ab8 100644 --- a/src/ingame/water_bomb.gd +++ b/src/ingame/water_bomb.gd @@ -12,6 +12,7 @@ extends Node3D var _in_splash_range := {} ## something to ignore +var sender_id: int var sender_body: PhysicsBody3D func _ready() -> void: @@ -41,7 +42,7 @@ func _on_body_entered(p_body: Node3D) -> void: return 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_quiet_sound.play() diff --git a/src/lib/player_data.gd b/src/lib/player_data.gd index 559accf..0d760df 100644 --- a/src/lib/player_data.gd +++ b/src/lib/player_data.gd @@ -2,3 +2,16 @@ class_name PlayerData extends Resource @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)