xiandie/scene/ground/ground.gd

39 lines
1021 B
GDScript3
Raw Normal View History

@tool
class_name Ground2D extends Node2D
@export var scene_config: SceneConfig
@export var reload := false:
set(new_val):
reload = false
load_config()
@onready var directional_light := %DirectionalLight2D as DirectionalLight2D
@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)
load_config()
func load_config():
if not scene_config:
return
var type = scene_config.footstep_type
# foot step sound
footstep_audio.audio_collections.clear()
if type != "none":
var audio = SceneConfig.FOOTSTEP_AUDIO[type] as AudioStreamCollection
footstep_audio.audio_collections.append(audio)
# light color
# directional_light.color = scene_config.light_color
func play_footstep_sound() -> void:
if not footstep_audio.audio_collections.is_empty():
footstep_audio.play_random()