Flopsy/scenes/main.gd

51 lines
1.3 KiB
GDScript3
Raw Normal View History

2022-07-17 14:24:15 +02:00
extends Node2D
export(String, FILE, "*.tscn") var level_path
var current_level = null
var current_bgm = null
var score = 0
func _ready():
load_level()
func load_level(next_scene := level_path, fade_out : bool = false):
if fade_out:
$HUD.scene_fadeout()
$BGM/Fader.play("fade_out")
yield(get_tree().create_timer(2.0), "timeout")
if current_level != null:
current_level.hide()
current_level.queue_free()
remove_child(current_level)
current_level = load(next_scene).instance()
2022-07-19 22:22:16 +02:00
GlobalState.player = current_level.get_node("Player")
2022-07-17 14:24:15 +02:00
level_path = next_scene
$HUD.hud_visible(current_level.hud_visible)
2022-07-17 17:08:39 +02:00
$HUD.set_font_color(current_level.hud_color)
2022-07-17 14:24:15 +02:00
add_child(current_level)
play_bgm(current_level.bgm_path)
$HUD.scene_fadein()
2022-07-18 03:28:10 +02:00
$BGM.volume_db = -5
2022-07-17 14:24:15 +02:00
func play_bgm(bgm_path):
var stream
var file = File.new()
if current_bgm == null or current_bgm != bgm_path and file.file_exists(bgm_path):
current_bgm = bgm_path
file.open(bgm_path, file.READ)
var buffer = file.get_buffer(file.get_len())
stream = AudioStreamOGGVorbis.new()
stream.data = buffer
file.close()
stream.loop = true
$BGM.stream = stream
$BGM.play()
func player_died():
$HUD.scene_fadeout()
yield(get_tree().create_timer(1.0), "timeout")
2022-07-18 20:36:48 +02:00
GlobalState.health = 100
2022-07-17 14:24:15 +02:00
load_level()