.. | ||
assets | ||
scenes | ||
scripts | ||
.gitattributes | ||
.gitignore | ||
icon.svg | ||
icon.svg.import | ||
project.godot | ||
Readme.md |
Stretch Goals
For this game I set two stretch goals for myself based on popular requests:
- Sound Integration
- Bad Guy Death
Sound Integration
I wanted two kinds of sounds in the game, namely music tracks and sound effects for things like footsteps while running.
For both, I was able to use the normal AudioStreamPlayer node.
Game Music
I implemented one AudioStreamPlayer as a child of the SceneManager. This is a good place to control the playing of background audio tracks.
Two audio tracks are in assets/audio/music. These are ogg-vorbis encoded music tracks.
I want to have the ability to play a different track of my choosing per game level. So I add the resource paths to the GameController.
var soundtracks = ["res://assets/audio/music/CrashingOut.ogg","res://assets/audio/music/DragAndDreadTheme.ogg", "res://assets/audio/music/CrashingOut.ogg"]
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
const GRASS_RUNNING = preload("res://assets/audio/footsteps/Grass Running.wav")
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:
if direction:
if not isJumping:
playerGraphic.play("run")
if not audio_stream_player.playing:
audio_stream_player.stream=GRASS_RUNNING
audio_stream_player.playing=true