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
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)
var is_screen_on: bool
# Screen flicker is buggy it glitches and does new things when you modify the albedo colour
# Seems like a Godot bug
onready var util = get_node("/root/Util")
onready var player = util.player
func _ready():
is_screen_on = false
@ -15,14 +15,14 @@ func _ready():
func turn_screen_off():
var mat = $Animations/walkie_talkie/Body.get_active_material(1)
#mat.albedo_color = screen_off_color
#mat.emission_enabled = false
mat.albedo_color = screen_off_color
mat.emission_enabled = false
is_screen_on = false
func turn_screen_on():
var mat = $Animations/walkie_talkie/Body.get_active_material(1)
#mat.albedo_color = default_screen_color
#mat.emission_enabled = true
mat.albedo_color = default_screen_color
mat.emission_enabled = true
is_screen_on = true
func toggle_screen():
@ -31,29 +31,43 @@ func toggle_screen():
else:
turn_screen_on()
func toggle():
if active:
fsm.travel("WalkieTalkieLeave")
$StaticBuzz.stop()
$StaticFizz.stop()
$Talk.stop()
$Whale1.stop()
$Whale2.stop()
turn_screen_off()
else:
if fsm.is_playing():
fsm.travel("WalkieTalkieEnter")
else:
fsm.start("WalkieTalkieEnter")
$StaticBuzz.play()
$StaticFizz.play()
$Talk.play()
$Whale1.play()
$Whale2.play()
turn_screen_on()
active = not active
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()
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()
func put_away():
fsm.travel("WalkieTalkieLeave")
if $DestroyTimer.is_stopped():
@ -61,7 +75,13 @@ func put_away():
func _process(_delta):
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():

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/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/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/flashlight_click.wav" type="AudioStream" id=11]
[sub_resource type="Animation" id=1]
resource_name = "WalkieTalkieEnter"
@ -251,7 +252,7 @@ light_cull_mask = 4293919232
omni_range = 0.449905
[node name="ScreenFlicker" type="Timer" parent="Animations/walkie_talkie/Body"]
wait_time = 0.5
wait_time = 0.3
autostart = true
[node name="BigKnob" type="MeshInstance" parent="Animations/walkie_talkie"]
@ -277,4 +278,7 @@ stream = ExtResource( 6 )
[node name="Whale2" type="AudioStreamPlayer" parent="."]
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"]

View File

@ -6,6 +6,12 @@ onready var active_physics_node: Spatial = $OnFootPhysics
func is_on_foot():
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():
return $"Smoothing/CameraController/Rotation/Camera"
@ -15,8 +21,6 @@ func camera_position() -> Vector3:
func set_physics_node(node: Spatial):
if active_physics_node == node:
return
#util.activate_node(node)
#util.deactivate_node(active_physics_node)
$Smoothing.target = NodePath("../" + node.name)
node.global_transform = active_physics_node.global_transform