The SceneManager already calls the GameController's reset function when it loads up, so I gave that function a return value passing the track that the SceneManager should play for that level.
```
func reset():
countdown = timers[currentLevel]
player.health = player.max_health
coinsCollected = 0
return(soundtracks[currentLevel])
```
This is important, because the SceneManager should not try to play a track until the level has fully loaded.
To play the track, the SceneManager needs to load the track using the string supplied by the GameController.
```
func _ready() -> void:
buildLevel()
var track = Gamecontroller.reset()
var audiofile = load(track)
audio_stream_player.stream = audiofile
audio_stream_player.play()
```
We can now have an audio track per level!
Possible improvements to this would be to have the sound tracks have a transition like a cross-fade.
### Game SFX
An AudioStreamPlayer node was added as a child of the Player scene.
Audio files for SFX were added directly to the player, using preload.
```
@onready var audio_stream_player: AudioStreamPlayer = $AudioStreamPlayer
It was then relatively easy to have the footsteps audio play, considering that our code is already tracking if the player is running in order to play the "run" animation. The update looks like this:
Notice that each enemy is given to a function in the GameController called `addEnemyToLevel`
The `addEnemyToLevel` uses a Dictionary object to assign some stats to each enemy, using the enemy itself as a key.
A dictionary object is powerful and easy to create:
`var enemiesDict = {}`
Then the function stores an info object for each enemy like so:
```
func addEnemyToLevel(enemy):
#assign a health using the enemy as a key
var enemyStat = {
"health": slime.health,
"damage": slime.meleeDamage
}
enemiesDict[enemy] = enemyStat
```
Notice how we use the slime CustomResource to get the default stats for slime creatures?
To retrieve the stats of an individual enemy from the dictionary, we just have to use the enemy object itself as a key.
We can do this in the `bulletHit` function, where we can add one additional check. If the bullet is hitting a Slime object, we can use that enemy object to retreive their health from the dictionary. After that it is easy to reduce the health, and optionally destroy them if their health goes to zero or below.