diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-08 10:47:47 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-08 10:47:47 +0100 |
commit | 65cdd7966c276dd7b1ffec7bf0de243b9370eeb1 (patch) | |
tree | 938c6ed098f2141a6a5c2d56146325938ae868bd /game/player/PlayerScript.cpp | |
parent | 6112da75f973b1099fa95fcd9d3113c00302f5b4 (diff) | |
parent | ad5fb53986fcc3f3b3c5369574e0f8e95051f3d9 (diff) |
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/enemyAI
Diffstat (limited to 'game/player/PlayerScript.cpp')
-rw-r--r-- | game/player/PlayerScript.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 96a0552..4e253f4 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -4,6 +4,7 @@ #include "../Config.h" #include "../enemy/BattleScript.h" #include <crepe/api/Animator.h> +#include <crepe/api/AudioSource.h> #include <crepe/api/ParticleEmitter.h> #include <crepe/api/Rigidbody.h> #include <crepe/api/BoxCollider.h> @@ -38,7 +39,11 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { } play_scr.active = false; end_scr.active = true; - return true; + + AudioSource & audio = this->get_components_by_name<AudioSource>("player").at(0); + audio.play(); + + return false; } else if (ev.info.other.metadata.tag == "laser") { for (Animator & anim : animators) { anim.active = true; @@ -51,7 +56,11 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { } play_scr.active = false; end_scr.active = true; - return true; + + AudioSource & audio = this->get_components_by_name<AudioSource>("player").at(1); + audio.play(); + + return false; } else if (ev.info.other.metadata.tag == "missile") { for (Animator & anim : animators) { anim.active = true; @@ -64,7 +73,11 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { } play_scr.active = false; end_scr.active = true; - return true; + + AudioSource & audio = this->get_components_by_name<AudioSource>("player").at(2); + audio.play(); + + return false; } return false; @@ -108,6 +121,15 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { emitter.data.emission_rate = 30; } } + + AudioSource & audio = this->get_components_by_name<AudioSource>("player").at( + 3 + current_jetpack_sound + ); + audio.play(); + current_jetpack_sound++; + if (current_jetpack_sound > 7) { + current_jetpack_sound = 0; + } } else if (transform.position.y == 195) { if (prev_anim != 0) { for (Animator & anim : animators) { |