From a63c8e03e9f536d78d321cdd234297fd6ce64773 Mon Sep 17 00:00:00 2001 From: Spencer Killen Date: Tue, 27 Dec 2022 13:24:35 -0700 Subject: [PATCH] various fixes --- godot/assets/meat_creek/side_tunnel_1.tscn | 10 ++++++- .../models/walkie_talkie/signal_generator.gd | 11 +++++++ .../walkie_talkie/signal_generator.tscn | 8 +++++ .../models/walkie_talkie/walkie_talkie.gd | 30 +++++++++---------- .../models/walkie_talkie/walkie_talkie.tscn | 1 + godot/global_event_bus.gd | 6 +++- godot/player/ObjectiveTracker.gd | 13 ++++++++ godot/player/player.gd | 6 +++- godot/player/player.tscn | 6 +++- godot/util.gd | 3 +- 10 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 godot/assets/models/walkie_talkie/signal_generator.gd create mode 100644 godot/assets/models/walkie_talkie/signal_generator.tscn create mode 100644 godot/player/ObjectiveTracker.gd diff --git a/godot/assets/meat_creek/side_tunnel_1.tscn b/godot/assets/meat_creek/side_tunnel_1.tscn index 59093c9..130e7f4 100644 --- a/godot/assets/meat_creek/side_tunnel_1.tscn +++ b/godot/assets/meat_creek/side_tunnel_1.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=15 format=2] [ext_resource path="res://assets/meat_creek/side_tunnel_1.glb" type="PackedScene" id=1] [ext_resource path="res://player/player.tscn" type="PackedScene" id=2] @@ -10,6 +10,8 @@ [ext_resource path="res://assets/meat_creek/StaticBody.tscn" type="PackedScene" id=8] [ext_resource path="res://assets/meat_creek/creek_cage.tscn" type="PackedScene" id=9] [ext_resource path="res://assets/models/meat_creek_elevator.tscn" type="PackedScene" id=10] +[ext_resource path="res://assets/audio/walkie_talkie/buzz_static.ogg" type="AudioStream" id=11] +[ext_resource path="res://assets/models/walkie_talkie/signal_generator.tscn" type="PackedScene" id=12] [sub_resource type="PanoramaSky" id=2] panorama = ExtResource( 4 ) @@ -123,3 +125,9 @@ transform = Transform( 0.65383, 0, 0.756641, 0, 1, 0, -0.756641, 0, 0.65383, 18. [node name="elevator" parent="." index="8" instance=ExtResource( 10 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0735546, -35.4611, -41.1766 ) + +[node name="SignalGenerator" parent="." index="9" instance=ExtResource( 12 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.489914, -35.0689, -41.5684 ) +stream = ExtResource( 11 ) +max_db = 6.0 +max_distance = 200.0 diff --git a/godot/assets/models/walkie_talkie/signal_generator.gd b/godot/assets/models/walkie_talkie/signal_generator.gd new file mode 100644 index 0000000..49fd2a1 --- /dev/null +++ b/godot/assets/models/walkie_talkie/signal_generator.gd @@ -0,0 +1,11 @@ +extends AudioStreamPlayer3D + +func _ready(): + var _ignore = GlobalEventBus.connect("player_walkie_talkie_state_change", self, "state") + +func state(is_active: bool): + stream_paused = not is_active + +func _process(_delta): + var distance = (transform.origin - Util.player.camera_position()).length() + GlobalEventBus.emit_signal("player_objective_ping", self, distance) diff --git a/godot/assets/models/walkie_talkie/signal_generator.tscn b/godot/assets/models/walkie_talkie/signal_generator.tscn new file mode 100644 index 0000000..fcf3edf --- /dev/null +++ b/godot/assets/models/walkie_talkie/signal_generator.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://assets/models/walkie_talkie/signal_generator.gd" type="Script" id=1] + +[node name="SignalGenerator" type="AudioStreamPlayer3D"] +autoplay = true +stream_paused = true +script = ExtResource( 1 ) diff --git a/godot/assets/models/walkie_talkie/walkie_talkie.gd b/godot/assets/models/walkie_talkie/walkie_talkie.gd index 5e382ba..4884ee5 100644 --- a/godot/assets/models/walkie_talkie/walkie_talkie.gd +++ b/godot/assets/models/walkie_talkie/walkie_talkie.gd @@ -5,9 +5,10 @@ onready var fsm: AnimationNodeStateMachinePlayback = $Animations/AnimationTree.g export var default_screen_color = Color(0.886275, 1, 0, 1) export var screen_off_color = Color(0.0, 0.0, 0.0) var is_screen_on: bool +export var screen_flicker_fastest: float = 0.1 +export var screen_flicker_slowest: float = 1.0 onready var util = get_node("/root/Util") -onready var player = util.player func _ready(): is_screen_on = false @@ -35,18 +36,16 @@ func toggle_screen(): func make_active(): if active: return - if fsm.is_playing(): - fsm.travel("WalkieTalkieEnter") - else: - fsm.start("WalkieTalkieEnter") - $StaticBuzz.play() - $StaticFizz.play() - $Talk.play() - $Whale1.play() - $Whale2.play() + fsm.travel("WalkieTalkieEnter") + #$StaticBuzz.play() + #$StaticFizz.play() + #$Talk.play() + #$Whale1.play() + #$Whale2.play() turn_screen_on() $Click.play() active = true + GlobalEventBus.emit_signal("player_walkie_talkie_state_change", true) func make_inactive(): if not active: @@ -60,24 +59,20 @@ func make_inactive(): turn_screen_off() $Click.play() active = false + GlobalEventBus.emit_signal("player_walkie_talkie_state_change", false) func toggle_active(): if active: make_inactive() else: make_active() - -func put_away(): - fsm.travel("WalkieTalkieLeave") - if $DestroyTimer.is_stopped(): - $DestroyTimer.start(1) func _process(_delta): if Input.is_action_just_pressed("toggle_walkie_talkie"): toggle_active() if not active or not fsm.is_playing(): return - if player.is_ground_walking(): + if Util.player.is_ground_walking(): fsm.travel("WalkieTalkieWalking") else: fsm.travel("WalkieTalkieIdle") @@ -85,3 +80,6 @@ func _process(_delta): func _on_ScreenFlicker_timeout(): if active: toggle_screen() + var weight = Util.player.objective_distance() / 115.0 + var time = Util.clamped_lerp(screen_flicker_fastest, screen_flicker_slowest, weight, 0.0) + $Animations/walkie_talkie/Body/ScreenFlicker.start(time) diff --git a/godot/assets/models/walkie_talkie/walkie_talkie.tscn b/godot/assets/models/walkie_talkie/walkie_talkie.tscn index e524f25..76b4be0 100644 --- a/godot/assets/models/walkie_talkie/walkie_talkie.tscn +++ b/godot/assets/models/walkie_talkie/walkie_talkie.tscn @@ -273,6 +273,7 @@ omni_range = 0.449905 [node name="ScreenFlicker" type="Timer" parent="Animations/walkie_talkie/Body"] wait_time = 0.3 +one_shot = true autostart = true [node name="BigKnob" type="MeshInstance" parent="Animations/walkie_talkie"] diff --git a/godot/global_event_bus.gd b/godot/global_event_bus.gd index cec892a..9249f3a 100644 --- a/godot/global_event_bus.gd +++ b/godot/global_event_bus.gd @@ -3,9 +3,13 @@ extends Node # Player enters or leaves an area for a block where they should start slowly sinking into it signal player_entered_meat_sink signal player_exited_meat_sink +signal player_walkie_talkie_state_change(is_active) +signal player_objective_ping(who, distance) -# This is only here to remove warnings about these signals not getting called (they get called by other nodes +# This is only here to remove warnings about these signals not getting called (they get called by other nodes) func never_called(): emit_signal("player_entered_meat_sink") emit_signal("player_exited_meat_sink") + emit_signal("player_walkie_talkie_state_change", false) + emit_signal("player_objective_ping", null, 0.0) diff --git a/godot/player/ObjectiveTracker.gd b/godot/player/ObjectiveTracker.gd new file mode 100644 index 0000000..82a146e --- /dev/null +++ b/godot/player/ObjectiveTracker.gd @@ -0,0 +1,13 @@ +extends Node + +var objective_who: WeakRef = weakref(null) +var objective_distance: float = 0.0 + +func _ready(): + var _ignored = GlobalEventBus.connect("player_objective_ping", self, "update_objective_distance") + +func update_objective_distance(who: Node, distance: float): + var node = objective_who.get_ref() + if node == null or node == who or distance < objective_distance: + objective_who = weakref(who) + objective_distance = distance diff --git a/godot/player/player.gd b/godot/player/player.gd index 92d4efb..1c0c1f8 100644 --- a/godot/player/player.gd +++ b/godot/player/player.gd @@ -1,8 +1,10 @@ extends Spatial -onready var util = get_node("/root/Util") onready var active_physics_node: Spatial = $OnFootPhysics +func _ready(): + Util.player = self + func is_on_foot(): return active_physics_node == $OnFootPhysics @@ -26,3 +28,5 @@ func set_physics_node(node: Spatial): node.global_transform = active_physics_node.global_transform active_physics_node = node +func objective_distance() -> float: + return $ObjectiveTracker.objective_distance diff --git a/godot/player/player.tscn b/godot/player/player.tscn index 2fda23d..2e9eb5f 100644 --- a/godot/player/player.tscn +++ b/godot/player/player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=29 format=2] +[gd_scene load_steps=30 format=2] [ext_resource path="res://player/CameraController.gd" type="Script" id=1] [ext_resource path="res://player/OnFootPhysics.gd" type="Script" id=2] @@ -20,6 +20,7 @@ [ext_resource path="res://assets/audio/404327__pfranzen__male-grunts-and-groans.ogg" type="AudioStream" id=18] [ext_resource path="res://effects/player/MovementSoundsAnimations.gd" type="Script" id=19] [ext_resource path="res://screens/PauseScreen.tscn" type="PackedScene" id=20] +[ext_resource path="res://player/ObjectiveTracker.gd" type="Script" id=21] [sub_resource type="Animation" id=8] length = 0.001 @@ -254,6 +255,9 @@ anims/opacity = SubResource( 7 ) [node name="PauseScreen" parent="Overlay" instance=ExtResource( 20 )] +[node name="ObjectiveTracker" type="Node" parent="."] +script = ExtResource( 21 ) + [connection signal="area_entered" from="ElevatorPhysics/Area" to="ElevatorPhysics" method="_on_Area_area_entered"] [connection signal="area_exited" from="ElevatorPhysics/Area" to="ElevatorPhysics" method="_on_Area_area_exited"] [connection signal="timeout" from="MovementInput/VerticalTimer" to="MovementInput" method="_on_VerticalTimer_timeout"] diff --git a/godot/util.gd b/godot/util.gd index c919bb5..7b66ad5 100644 --- a/godot/util.gd +++ b/godot/util.gd @@ -1,6 +1,7 @@ extends Node -onready var player = $"/root".find_node("Player", true, false) +# Updated by player +onready var player = null func vec3_componentwise_clamp(vec: Vector3, lower: float, upper: float) -> Vector3: return Vector3(