From f2a24bc4f5956d7d59ae42fade277a7826e174da Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 13:21:23 +0100 Subject: First audio --- game/GameScene.cpp | 9 +++++++++ game/StartGameScript.cpp | 9 +++++++++ 2 files changed, 18 insertions(+) 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 #include #include +#include #include #include #include @@ -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().set_script(); + GameObject background_music = new_object("background_music", "audio", vec2(0, 0)); + Asset background_music_asset {"asset/music/level.ogg"}; + background_music.add_component(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(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 +#include #include #include @@ -34,6 +35,10 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { emitter.active = true; } + AudioSource & boom_audio + = this->get_components_by_name("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("player").back(); jetpack_sprite.active = true; + AudioSource & background_music + = this->get_components_by_name("background_music").front(); + background_music.play(); + this->took_jetpack = true; } -- cgit v1.2.3