86 lines
2.1 KiB
GDScript
86 lines
2.1 KiB
GDScript
extends Spatial
|
|
|
|
var active = false
|
|
onready var fsm: AnimationNodeStateMachinePlayback = $Animations/AnimationTree.get("parameters/playback")
|
|
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")
|
|
|
|
func _ready():
|
|
is_screen_on = false
|
|
turn_screen_off()
|
|
fsm.start("WalkieTalkieStart")
|
|
|
|
func turn_screen_off():
|
|
var mat = $Animations/walkie_talkie/Body.get_active_material(1)
|
|
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
|
|
is_screen_on = true
|
|
|
|
func toggle_screen():
|
|
if is_screen_on:
|
|
turn_screen_off()
|
|
else:
|
|
turn_screen_on()
|
|
|
|
func make_active():
|
|
if active:
|
|
return
|
|
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:
|
|
return
|
|
fsm.travel("WalkieTalkieLeave")
|
|
$StaticBuzz.stop()
|
|
$StaticFizz.stop()
|
|
$Talk.stop()
|
|
$Whale1.stop()
|
|
$Whale2.stop()
|
|
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 _process(_delta):
|
|
if Input.is_action_just_pressed("toggle_walkie_talkie"):
|
|
toggle_active()
|
|
if not active or not fsm.is_playing():
|
|
return
|
|
if Util.player.is_ground_walking():
|
|
fsm.travel("WalkieTalkieWalking")
|
|
else:
|
|
fsm.travel("WalkieTalkieIdle")
|
|
|
|
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)
|