diff options
Diffstat (limited to 'game')
-rw-r--r-- | game/GameScene.cpp | 9 | ||||
-rw-r--r-- | game/StartGameScript.cpp | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/game/GameScene.cpp b/game/GameScene.cpp index a8fcb47..e193f44 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -9,6 +9,7 @@ #include <cmath> #include <crepe/api/Animator.h> #include <crepe/api/Asset.h> +#include <crepe/api/AudioSource.h> #include <crepe/api/BehaviorScript.h> #include <crepe/api/BoxCollider.h> #include <crepe/api/Camera.h> @@ -67,6 +68,14 @@ void GameScene::load_scene() { GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); start_game_script.add_component<BehaviorScript>().set_script<StartGameScript>(); + GameObject background_music = new_object("background_music", "audio", vec2(0, 0)); + Asset background_music_asset {"asset/music/level.ogg"}; + background_music.add_component<AudioSource>(background_music_asset).loop = true; + + GameObject boom_audio = new_object("boom_audio", "audio", vec2(0, 0)); + Asset boom_audio_asset {"asset/sfx/window_smash.ogg"}; + boom_audio.add_component<AudioSource>(boom_audio_asset); + // zapper, laser and missile (below) for testing purpose only!!! GameObject zapper = new_object("zapper", "zapper", vec2(1000, 0)); Asset zapper_asset {"asset/obstacles/zapper/regular_zappers/zapEffect.png"}; diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp index c786eb4..273666c 100644 --- a/game/StartGameScript.cpp +++ b/game/StartGameScript.cpp @@ -2,6 +2,7 @@ #include "Config.h" #include <crepe/api/Animator.h> +#include <crepe/api/AudioSource.h> #include <crepe/api/ParticleEmitter.h> #include <crepe/api/Sprite.h> @@ -34,6 +35,10 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { emitter.active = true; } + AudioSource & boom_audio + = this->get_components_by_name<AudioSource>("boom_audio").front(); + boom_audio.play(); + this->created_hole = true; } @@ -45,6 +50,10 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { Sprite & jetpack_sprite = this->get_components_by_name<Sprite>("player").back(); jetpack_sprite.active = true; + AudioSource & background_music + = this->get_components_by_name<AudioSource>("background_music").front(); + background_music.play(); + this->took_jetpack = true; } |