aboutsummaryrefslogtreecommitdiff
path: root/game/player/PlayerAudioScript.cpp
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2025-01-07 14:14:21 +0100
committerJAROWMR <jarorutjes07@gmail.com>2025-01-07 14:14:21 +0100
commitca456c50a6a4f35832d7b9d8d1b8f5eecee0e148 (patch)
tree78163daa8384e18b894491ffc8d18e8f69b88d5d /game/player/PlayerAudioScript.cpp
parent41f890863706ee8ede43021fe83b776b638a18b7 (diff)
parent80b2c59068f97ff69a2ba77788c4861b10535328 (diff)
merged
Diffstat (limited to 'game/player/PlayerAudioScript.cpp')
-rw-r--r--game/player/PlayerAudioScript.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/game/player/PlayerAudioScript.cpp b/game/player/PlayerAudioScript.cpp
new file mode 100644
index 0000000..6b5f630
--- /dev/null
+++ b/game/player/PlayerAudioScript.cpp
@@ -0,0 +1,62 @@
+#include "PlayerAudioScript.h"
+
+#include <crepe/api/Animator.h>
+#include <crepe/api/AudioSource.h>
+
+using namespace crepe;
+using namespace std;
+
+void PlayerAudioScript::fixed_update(crepe::duration_t dt) {
+ Animator & animator = this->get_components_by_name<Animator>("player").front();
+
+ if (animator.data.col == 0) {
+ if (animator.data.row != this->last_row) {
+ if (animator.data.row == 0) {
+ // right footstep
+ if (current_footstep == 0) {
+ AudioSource & audio
+ = this->get_components_by_name<AudioSource>("player_audio").at(0);
+ audio.play();
+ } else if (current_footstep == 1) {
+ AudioSource & audio
+ = this->get_components_by_name<AudioSource>("player_audio").at(2);
+ audio.play();
+ } else if (current_footstep == 2) {
+ AudioSource & audio
+ = this->get_components_by_name<AudioSource>("player_audio").at(4);
+ audio.play();
+ } else if (current_footstep == 3) {
+ AudioSource & audio
+ = this->get_components_by_name<AudioSource>("player_audio").at(6);
+ audio.play();
+ }
+ } else if (animator.data.row == 2) {
+ // left footstep
+ if (current_footstep == 0) {
+ AudioSource & audio
+ = this->get_components_by_name<AudioSource>("player_audio").at(1);
+ audio.play();
+ current_footstep = 1;
+ } else if (current_footstep == 1) {
+ AudioSource & audio
+ = this->get_components_by_name<AudioSource>("player_audio").at(3);
+ audio.play();
+ current_footstep = 2;
+ } else if (current_footstep == 2) {
+ AudioSource & audio
+ = this->get_components_by_name<AudioSource>("player_audio").at(5);
+ audio.play();
+ current_footstep = 3;
+ } else if (current_footstep == 3) {
+ AudioSource & audio
+ = this->get_components_by_name<AudioSource>("player_audio").at(7);
+ audio.play();
+ current_footstep = 0;
+ }
+ }
+ this->last_row = animator.data.row;
+ }
+ } else {
+ this->last_row = -1;
+ }
+}