xiandie/scene/ground/ground.gd

33 lines
811 B
GDScript

class_name Ground2D extends Node2D
@export var scene_config: SceneConfig
@onready var foreground = %ParallaxForeground as ParallaxBackground
var footstep_audio = RandomAudioStreamPlayer.new()
func _ready() -> void:
foreground.layer = GlobalConfig.CANVAS_LAYER_FG
%ColorRectTop.visible = true
%ColorRectBottom.visible = true
add_child(footstep_audio)
reload()
func reload():
if not scene_config:
footstep_audio.audio_collections.clear()
return
var type = scene_config.footstep_type
if type == "none":
return
footstep_audio.audio_collections.clear()
var audio = SceneConfig.FOOTSTEP_AUDIO[type] as AudioStreamCollection
footstep_audio.audio_collections.append(audio)
func play_footstep_sound() -> void:
if not footstep_audio.audio_collections.is_empty():
footstep_audio.play_random()