diff --git a/scenes/interactivity_outline.gdshader b/scenes/interactivity_outline.gdshader new file mode 100644 index 0000000..a9253ee --- /dev/null +++ b/scenes/interactivity_outline.gdshader @@ -0,0 +1,14 @@ +shader_type spatial; +render_mode blend_mix, cull_front, unshaded; + +uniform vec4 color : source_color = vec4(1,0,0,1); +uniform float size : hint_range(1.0, 1.5, 0.01) = 1.05; + +void vertex() { + VERTEX *= size; +} + +void fragment() { + ALBEDO = color.rgb; + ALPHA = color.a; +} \ No newline at end of file diff --git a/scenes/water_bomb_model.tscn b/scenes/water_bomb_model.tscn index 50b0ae9..85cc2d7 100644 --- a/scenes/water_bomb_model.tscn +++ b/scenes/water_bomb_model.tscn @@ -1,6 +1,17 @@ -[gd_scene load_steps=2 format=3 uid="uid://s2a1pry5fw8f"] +[gd_scene load_steps=4 format=3 uid="uid://s2a1pry5fw8f"] + +[ext_resource type="Shader" path="res://scenes/interactivity_outline.gdshader" id="1_m18kw"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_gi5rt"] +resource_local_to_scene = true +render_priority = 0 +shader = ExtResource("1_m18kw") +shader_parameter/color = Color(1, 1, 1, 0) +shader_parameter/size = 1.24 [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ptaep"] +resource_local_to_scene = true +next_pass = SubResource("ShaderMaterial_gi5rt") albedo_color = Color(0.0936238, 0.825356, 1, 1) metallic = 0.8 roughness = 0.4 diff --git a/src/ingame/player.gd b/src/ingame/player.gd index 1821ed0..ee61af7 100644 --- a/src/ingame/player.gd +++ b/src/ingame/player.gd @@ -21,6 +21,8 @@ var _max_speed := 12 var _mouse_sensitivity := 0.008 # radians/pixel var _projectile_speed := 12.0 +## Could be only one thing at a time to consider. +var _interaction_selection: Node3D var controls_disabled := false var held_thing: String @@ -52,6 +54,18 @@ func _process(_delta: float) -> void: func _physics_process(delta: float) -> void: + ## Process interactivity selection. + var collider: Object = null + if _line_of_sight.is_colliding(): + collider = _line_of_sight.get_collider(0) + if collider != _interaction_selection: + if _interaction_selection != null: + _interaction_selection.get_parent().mark_non_interactive() + if collider != null: + collider.get_parent().mark_interactive() + _interaction_selection = collider + + # Add the gravity. if not is_on_floor(): velocity += get_gravity() * delta @@ -96,12 +110,8 @@ func _unhandled_input(event: InputEvent) -> void: return if event.is_action_pressed("pick") and held_thing == "": - if _line_of_sight.is_colliding(): - if id != 1: - print("test") - # TODO: bad - var picked = _line_of_sight.get_collider(0).get_parent() - picked.get_picked_up.rpc() + if _interaction_selection != null: + _interaction_selection.get_parent().get_picked_up.rpc() hold_thing.rpc() if event.is_action_pressed("fire") and held_thing != "": diff --git a/src/ingame/water_bomb.gd b/src/ingame/water_bomb.gd index ebdd8c6..bc29e8b 100644 --- a/src/ingame/water_bomb.gd +++ b/src/ingame/water_bomb.gd @@ -77,3 +77,11 @@ func set_global_pos(new: Vector3) -> void: func get_picked_up() -> void: if is_multiplayer_authority(): queue_free() + + +func mark_interactive() -> void: + ($Model as CSGSphere3D).material_override.next_pass.set("shader_parameter/color", Color.WHITE) + + +func mark_non_interactive() -> void: + ($Model as CSGSphere3D).material_override.next_pass.set("shader_parameter/color", Color(1, 1, 1, 0)) diff --git a/src/ingame/water_bomb.tscn b/src/ingame/water_bomb.tscn index 630ee0a..1b9f7e0 100644 --- a/src/ingame/water_bomb.tscn +++ b/src/ingame/water_bomb.tscn @@ -1,9 +1,11 @@ -[gd_scene load_steps=11 format=3 uid="uid://tdsbo3e5ic86"] +[gd_scene load_steps=15 format=3 uid="uid://tdsbo3e5ic86"] [ext_resource type="Script" path="res://src/ingame/water_bomb.gd" id="1_lk5fq"] [ext_resource type="PackedScene" uid="uid://s2a1pry5fw8f" path="res://scenes/water_bomb_model.tscn" id="2_0lxuq"] [ext_resource type="AudioStream" uid="uid://dtjpv2b74g24m" path="res://assets/sfx/splash-small.wav" id="2_0wk8g"] [ext_resource type="AudioStream" uid="uid://blgrl2wl05feq" path="res://assets/sfx/splash-small-quiet.wav" id="3_hgy7l"] +[ext_resource type="Shader" path="res://scenes/interactivity_outline.gdshader" id="3_vfl1p"] +[ext_resource type="Script" path="res://src/lib/item_component.gd" id="5_rpnf2"] [sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_0ebrr"] properties/0/path = NodePath(".:position") @@ -25,6 +27,20 @@ properties/5/path = NodePath("SplashParticles:emitting") properties/5/spawn = true properties/5/replication_mode = 2 +[sub_resource type="ShaderMaterial" id="ShaderMaterial_cpgfr"] +resource_local_to_scene = true +render_priority = 0 +shader = ExtResource("3_vfl1p") +shader_parameter/color = Color(1, 1, 1, 0) +shader_parameter/size = 1.24 + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_dykfn"] +resource_local_to_scene = true +next_pass = SubResource("ShaderMaterial_cpgfr") +albedo_color = Color(0.0936238, 0.825356, 1, 1) +metallic = 0.8 +roughness = 0.4 + [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_v7dnr"] albedo_color = Color(0, 1, 1, 1) roughness = 0.2 @@ -59,6 +75,7 @@ body = NodePath("RigidBody3D") replication_config = SubResource("SceneReplicationConfig_0ebrr") [node name="Model" parent="." instance=ExtResource("2_0lxuq")] +material_override = SubResource("StandardMaterial3D_dykfn") [node name="SplashParticles" type="GPUParticles3D" parent="."] material_override = SubResource("StandardMaterial3D_v7dnr") @@ -107,6 +124,10 @@ monitoring = false [node name="CollisionShape3D" type="CollisionShape3D" parent="PickingArea"] shape = SubResource("SphereShape3D_6c830") +[node name="ItemComponent" type="Node" parent="."] +script = ExtResource("5_rpnf2") +id = "water" + [connection signal="body_entered" from="RigidBody3D" to="." method="_on_body_entered"] [connection signal="area_entered" from="RigidBody3D/SplashArea" to="." method="_on_splash_area_entered"] [connection signal="area_exited" from="RigidBody3D/SplashArea" to="." method="_on_splash_area_exited"] diff --git a/src/lib/item_component.gd b/src/lib/item_component.gd new file mode 100644 index 0000000..b577e7f --- /dev/null +++ b/src/lib/item_component.gd @@ -0,0 +1,17 @@ +class_name ItemComponent +extends Node + +## Base identity, properties are defined in item db. +@export var id: String + + +func mark_interactive() -> void: + var parent := get_parent() + if parent.has_method("mark_interactive"): + parent.mark_interactive() + + +func mark_non_interactive(delta: float) -> void: + var parent := get_parent() + if parent.has_method("mark_non_interactive"): + parent.mark_non_interactive()