meat_madness_redux/godot/assets/models/walkie_talkie/walkie_talkie.gd

86 lines
2.1 KiB
GDScript3
Raw Normal View History

2022-12-04 18:23:46 -07:00
extends Spatial
var active = false
onready var fsm: AnimationNodeStateMachinePlayback = $Animations/AnimationTree.get("parameters/playback")
2022-12-05 09:46:58 -07:00
export var default_screen_color = Color(0.886275, 1, 0, 1)
2022-12-04 19:20:58 -07:00
export var screen_off_color = Color(0.0, 0.0, 0.0)
var is_screen_on: bool
2022-12-27 13:24:35 -07:00
export var screen_flicker_fastest: float = 0.1
export var screen_flicker_slowest: float = 1.0
2022-12-04 18:23:46 -07:00
2022-12-05 09:46:58 -07:00
onready var util = get_node("/root/Util")
2022-12-04 19:20:58 -07:00
func _ready():
is_screen_on = false
turn_screen_off()
2022-12-26 11:44:13 -07:00
fsm.start("WalkieTalkieStart")
2022-12-04 19:20:58 -07:00
func turn_screen_off():
var mat = $Animations/walkie_talkie/Body.get_active_material(1)
2022-12-05 09:46:58 -07:00
mat.albedo_color = screen_off_color
mat.emission_enabled = false
2022-12-04 19:20:58 -07:00
is_screen_on = false
func turn_screen_on():
var mat = $Animations/walkie_talkie/Body.get_active_material(1)
2022-12-05 09:46:58 -07:00
mat.albedo_color = default_screen_color
mat.emission_enabled = true
2022-12-04 19:20:58 -07:00
is_screen_on = true
func toggle_screen():
if is_screen_on:
turn_screen_off()
else:
turn_screen_on()
2022-12-04 18:23:46 -07:00
2022-12-05 09:46:58 -07:00
func make_active():
2022-12-04 18:23:46 -07:00
if active:
2022-12-05 09:46:58 -07:00
return
2022-12-27 13:24:35 -07:00
fsm.travel("WalkieTalkieEnter")
#$StaticBuzz.play()
#$StaticFizz.play()
#$Talk.play()
#$Whale1.play()
#$Whale2.play()
2022-12-05 09:46:58 -07:00
turn_screen_on()
$Click.play()
active = true
2022-12-27 13:24:35 -07:00
GlobalEventBus.emit_signal("player_walkie_talkie_state_change", true)
2022-12-04 18:23:46 -07:00
2022-12-05 09:46:58 -07:00
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
2022-12-27 13:24:35 -07:00
GlobalEventBus.emit_signal("player_walkie_talkie_state_change", false)
2022-12-05 09:46:58 -07:00
func toggle_active():
if active:
make_inactive()
else:
make_active()
2022-12-04 18:23:46 -07:00
func _process(_delta):
if Input.is_action_just_pressed("toggle_walkie_talkie"):
2022-12-05 09:46:58 -07:00
toggle_active()
if not active or not fsm.is_playing():
return
2022-12-27 13:24:35 -07:00
if Util.player.is_ground_walking():
2022-12-05 09:46:58 -07:00
fsm.travel("WalkieTalkieWalking")
else:
fsm.travel("WalkieTalkieIdle")
2022-12-04 19:20:58 -07:00
func _on_ScreenFlicker_timeout():
if active:
toggle_screen()
2022-12-27 13:24:35 -07:00
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)