87 lines
1.8 KiB
GDScript
87 lines
1.8 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
|
|
|
|
onready var util = get_node("/root/Util")
|
|
onready var player = util.player
|
|
|
|
func _ready():
|
|
is_screen_on = false
|
|
turn_screen_off()
|
|
|
|
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
|
|
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():
|
|
$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():
|
|
fsm.travel("WalkieTalkieWalking")
|
|
else:
|
|
fsm.travel("WalkieTalkieIdle")
|
|
|
|
func _on_ScreenFlicker_timeout():
|
|
if active:
|
|
toggle_screen()
|