Fix walkie talkie screen

This commit is contained in:
Spencer Killen 2022-12-05 09:46:58 -07:00
parent 272fcc390f
commit effbe7dc83
Signed by: sjkillen
GPG Key ID: F307025B65C860BA
3 changed files with 62 additions and 34 deletions

View File

@ -2,12 +2,12 @@ extends Spatial
var active = false var active = false
onready var fsm: AnimationNodeStateMachinePlayback = $Animations/AnimationTree.get("parameters/playback") onready var fsm: AnimationNodeStateMachinePlayback = $Animations/AnimationTree.get("parameters/playback")
export var default_screen_color = Color(226, 255, 0, 255) export var default_screen_color = Color(0.886275, 1, 0, 1)
export var screen_off_color = Color(0.0, 0.0, 0.0) export var screen_off_color = Color(0.0, 0.0, 0.0)
var is_screen_on: bool var is_screen_on: bool
# Screen flicker is buggy it glitches and does new things when you modify the albedo colour onready var util = get_node("/root/Util")
# Seems like a Godot bug onready var player = util.player
func _ready(): func _ready():
is_screen_on = false is_screen_on = false
@ -15,14 +15,14 @@ func _ready():
func turn_screen_off(): func turn_screen_off():
var mat = $Animations/walkie_talkie/Body.get_active_material(1) var mat = $Animations/walkie_talkie/Body.get_active_material(1)
#mat.albedo_color = screen_off_color mat.albedo_color = screen_off_color
#mat.emission_enabled = false mat.emission_enabled = false
is_screen_on = false is_screen_on = false
func turn_screen_on(): func turn_screen_on():
var mat = $Animations/walkie_talkie/Body.get_active_material(1) var mat = $Animations/walkie_talkie/Body.get_active_material(1)
#mat.albedo_color = default_screen_color mat.albedo_color = default_screen_color
#mat.emission_enabled = true mat.emission_enabled = true
is_screen_on = true is_screen_on = true
func toggle_screen(): func toggle_screen():
@ -31,16 +31,10 @@ func toggle_screen():
else: else:
turn_screen_on() turn_screen_on()
func toggle():
func make_active():
if active: if active:
fsm.travel("WalkieTalkieLeave") return
$StaticBuzz.stop()
$StaticFizz.stop()
$Talk.stop()
$Whale1.stop()
$Whale2.stop()
turn_screen_off()
else:
if fsm.is_playing(): if fsm.is_playing():
fsm.travel("WalkieTalkieEnter") fsm.travel("WalkieTalkieEnter")
else: else:
@ -51,8 +45,28 @@ func toggle():
$Whale1.play() $Whale1.play()
$Whale2.play() $Whale2.play()
turn_screen_on() turn_screen_on()
$Click.play()
active = true
func make_inactive():
if not active:
return
fsm.travel("WalkieTalkieLeave")
$StaticBuzz.stop()
$StaticFizz.stop()
$Talk.stop()
$Whale1.stop()
$Whale2.stop()
turn_screen_off()
$Click.play()
active = false
func toggle_active():
if active:
make_inactive()
else:
make_active()
active = not active
func put_away(): func put_away():
fsm.travel("WalkieTalkieLeave") fsm.travel("WalkieTalkieLeave")
@ -61,7 +75,13 @@ func put_away():
func _process(_delta): func _process(_delta):
if Input.is_action_just_pressed("toggle_walkie_talkie"): if Input.is_action_just_pressed("toggle_walkie_talkie"):
toggle() toggle_active()
if not active or not fsm.is_playing():
return
if player.is_ground_sprinting():
fsm.travel("WalkieTalkieWalking")
else:
fsm.travel("WalkieTalkieIdle")
func _on_ScreenFlicker_timeout(): func _on_ScreenFlicker_timeout():

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=33 format=2] [gd_scene load_steps=34 format=2]
[ext_resource path="res://assets/models/walkie_talkie/LCDScreen.material" type="Material" id=1] [ext_resource path="res://assets/models/walkie_talkie/LCDScreen.material" type="Material" id=1]
[ext_resource path="res://assets/models/walkie_talkie/WalkieTalkieSpeaker.material" type="Material" id=2] [ext_resource path="res://assets/models/walkie_talkie/WalkieTalkieSpeaker.material" type="Material" id=2]
@ -10,6 +10,7 @@
[ext_resource path="res://assets/audio/walkie_talkie/white_noise_static.ogg" type="AudioStream" id=8] [ext_resource path="res://assets/audio/walkie_talkie/white_noise_static.ogg" type="AudioStream" id=8]
[ext_resource path="res://assets/audio/walkie_talkie/talk.ogg" type="AudioStream" id=9] [ext_resource path="res://assets/audio/walkie_talkie/talk.ogg" type="AudioStream" id=9]
[ext_resource path="res://assets/audio/walkie_talkie/high_whale.ogg" type="AudioStream" id=10] [ext_resource path="res://assets/audio/walkie_talkie/high_whale.ogg" type="AudioStream" id=10]
[ext_resource path="res://assets/audio/flashlight_click.wav" type="AudioStream" id=11]
[sub_resource type="Animation" id=1] [sub_resource type="Animation" id=1]
resource_name = "WalkieTalkieEnter" resource_name = "WalkieTalkieEnter"
@ -251,7 +252,7 @@ light_cull_mask = 4293919232
omni_range = 0.449905 omni_range = 0.449905
[node name="ScreenFlicker" type="Timer" parent="Animations/walkie_talkie/Body"] [node name="ScreenFlicker" type="Timer" parent="Animations/walkie_talkie/Body"]
wait_time = 0.5 wait_time = 0.3
autostart = true autostart = true
[node name="BigKnob" type="MeshInstance" parent="Animations/walkie_talkie"] [node name="BigKnob" type="MeshInstance" parent="Animations/walkie_talkie"]
@ -277,4 +278,7 @@ stream = ExtResource( 6 )
[node name="Whale2" type="AudioStreamPlayer" parent="."] [node name="Whale2" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 10 ) stream = ExtResource( 10 )
[node name="Click" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 11 )
[connection signal="timeout" from="Animations/walkie_talkie/Body/ScreenFlicker" to="." method="_on_ScreenFlicker_timeout"] [connection signal="timeout" from="Animations/walkie_talkie/Body/ScreenFlicker" to="." method="_on_ScreenFlicker_timeout"]

View File

@ -6,6 +6,12 @@ onready var active_physics_node: Spatial = $OnFootPhysics
func is_on_foot(): func is_on_foot():
return active_physics_node == $OnFootPhysics return active_physics_node == $OnFootPhysics
func is_ground_walking():
return is_on_foot() and $OnFootPhysics/Floor.is_on_floor and $MovementInput.input_xz != Vector2.ZERO
func is_ground_sprinting():
return is_ground_walking() and $MovementInput.sprinting
func camera(): func camera():
return $"Smoothing/CameraController/Rotation/Camera" return $"Smoothing/CameraController/Rotation/Camera"
@ -15,8 +21,6 @@ func camera_position() -> Vector3:
func set_physics_node(node: Spatial): func set_physics_node(node: Spatial):
if active_physics_node == node: if active_physics_node == node:
return return
#util.activate_node(node)
#util.deactivate_node(active_physics_node)
$Smoothing.target = NodePath("../" + node.name) $Smoothing.target = NodePath("../" + node.name)
node.global_transform = active_physics_node.global_transform node.global_transform = active_physics_node.global_transform