This repository has been archived on 2024-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
Jessist/Scripts/BackgroundMusic.gd
2022-06-18 13:05:48 +02:00

50 lines
1.1 KiB
GDScript

######################
### Jessist Script ###
######################
# This script is part of Jessist
# Jessist is licensed under GNU GPLv3
#
# This script manages the background music player
extends AudioStreamPlayer
export var volumeDefault = -5
export var volumePaused = -15
var timerActive = false
var reachedBaseVolume = false
export var verboseMessages = gameController.enableVerbosity
export var enableMusic = true
export var music = "Rocket"
func _ready():
if not enableMusic:
playing = false
return
print("=> Starting music")
stream = load("res://Sounds/Music/" + music + ".ogg")
play(0)
func _process(delta):
if not enableMusic:
return
if timerActive:
return
timerActive = true
yield(get_tree().create_timer(0.05), "timeout")
timerActive = false
volume_db = volume_db
if verboseMessages:
print("=> Current music volume: " + String(volume_db))
if not reachedBaseVolume:
if volume_db >= volumeDefault:
reachedBaseVolume = true
else:
volume_db += 1
return
if get_parent().get_node("Camera").gamePaused:
if volume_db <= volumePaused:
volume_db = volumePaused
else:
volume_db -= 1
else:
reachedBaseVolume = false