aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/CMakeLists.txt1
-rw-r--r--game/StartGameScript.cpp7
-rw-r--r--game/player/PlayerAudioScript.cpp62
-rw-r--r--game/player/PlayerAudioScript.h13
-rw-r--r--game/player/PlayerSubScene.cpp15
5 files changed, 97 insertions, 1 deletions
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index 8e3692b..0b85b96 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -20,6 +20,7 @@ add_executable(main
player/PlayerSubScene.cpp
StartGameScript.cpp
player/PlayerEndScript.cpp
+ player/PlayerAudioScript.cpp
background/StartSubScene.cpp
main.cpp
)
diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp
index 466dbce..1a7e3e7 100644
--- a/game/StartGameScript.cpp
+++ b/game/StartGameScript.cpp
@@ -1,5 +1,6 @@
#include "StartGameScript.h"
#include "Config.h"
+#include "api/BehaviorScript.h"
#include <crepe/api/Animator.h>
#include <crepe/api/AudioSource.h>
@@ -39,6 +40,10 @@ void StartGameScript::fixed_update(crepe::duration_t dt) {
= this->get_components_by_name<AudioSource>("boom_audio").front();
boom_audio.play();
+ BehaviorScript & player_audio_script
+ = this->get_components_by_name<BehaviorScript>("player_audio").front();
+ player_audio_script.active = true;
+
this->created_hole = true;
}
@@ -52,7 +57,7 @@ void StartGameScript::fixed_update(crepe::duration_t dt) {
AudioSource & background_music
= this->get_components_by_name<AudioSource>("background_music").front();
- background_music.play(true);
+ //background_music.play(true);
this->took_jetpack = true;
}
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;
+ }
+}
diff --git a/game/player/PlayerAudioScript.h b/game/player/PlayerAudioScript.h
new file mode 100644
index 0000000..764cb20
--- /dev/null
+++ b/game/player/PlayerAudioScript.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <crepe/api/Event.h>
+#include <crepe/api/Script.h>
+
+class PlayerAudioScript : public crepe::Script {
+public:
+ void fixed_update(crepe::duration_t dt);
+
+private:
+ int last_row = -1;
+ int current_footstep = 0;
+};
diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp
index c1e5e2f..11575c6 100644
--- a/game/player/PlayerSubScene.cpp
+++ b/game/player/PlayerSubScene.cpp
@@ -1,10 +1,12 @@
#include "PlayerSubScene.h"
+#include "PlayerAudioScript.h"
#include "PlayerEndScript.h"
#include "PlayerScript.h"
#include "../Config.h"
#include <crepe/api/Animator.h>
+#include <crepe/api/AudioSource.h>
#include <crepe/api/BoxCollider.h>
#include <crepe/api/CircleCollider.h>
#include <crepe/api/GameObject.h>
@@ -150,4 +152,17 @@ PlayerSubScene::PlayerSubScene(Scene & scn) {
});
player.add_component<BehaviorScript>().set_script<PlayerScript>().active = false;
player.add_component<BehaviorScript>().set_script<PlayerEndScript>().active = false;
+
+ GameObject player_audio = scn.new_object("player_audio", "player_audio", vec2(0, 0));
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_left_1.ogg"));
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_right_1.ogg"));
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_left_2.ogg"));
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_right_2.ogg"));
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_left_3.ogg"));
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_right_3.ogg"));
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_left_4.ogg"));
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_right_4.ogg"));
+
+ player_audio.add_component<BehaviorScript>().set_script<PlayerAudioScript>().active
+ = false;
}