aboutsummaryrefslogtreecommitdiff
path: root/game/player/PlayerScript.cpp
diff options
context:
space:
mode:
authorWboerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-07 14:12:28 +0100
committerGitHub <noreply@github.com>2025-01-07 14:12:28 +0100
commit80b2c59068f97ff69a2ba77788c4861b10535328 (patch)
tree30500bf55a2a8d3b1995b72675f0321bd364b9ce /game/player/PlayerScript.cpp
parent77d02bf2e2d5d04e8cacb3c783446541517e8e76 (diff)
parenta2d9f875a219d6d1c53784a307b4915cc4e1ee14 (diff)
Merge pull request #103 from lonkaars/max/game
Max/game (audio)
Diffstat (limited to 'game/player/PlayerScript.cpp')
-rw-r--r--game/player/PlayerScript.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp
index 472d7c8..4404bd8 100644
--- a/game/player/PlayerScript.cpp
+++ b/game/player/PlayerScript.cpp
@@ -3,6 +3,7 @@
#include "../Config.h"
#include <crepe/api/Animator.h>
+#include <crepe/api/AudioSource.h>
#include <crepe/api/ParticleEmitter.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Transform.h>
@@ -36,6 +37,10 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) {
}
play_scr.active = false;
end_scr.active = true;
+
+ AudioSource & audio = this->get_components_by_name<AudioSource>("player").at(0);
+ audio.play();
+
return true;
} else if (ev.info.other.metadata.tag == "laser") {
for (Animator & anim : animators) {
@@ -49,6 +54,10 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) {
}
play_scr.active = false;
end_scr.active = true;
+
+ AudioSource & audio = this->get_components_by_name<AudioSource>("player").at(1);
+ audio.play();
+
return true;
} else if (ev.info.other.metadata.tag == "missile") {
for (Animator & anim : animators) {
@@ -62,6 +71,10 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) {
}
play_scr.active = false;
end_scr.active = true;
+
+ AudioSource & audio = this->get_components_by_name<AudioSource>("player").at(2);
+ audio.play();
+
return true;
}
@@ -92,6 +105,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) {