aboutsummaryrefslogtreecommitdiff
path: root/game/player
diff options
context:
space:
mode:
Diffstat (limited to 'game/player')
-rw-r--r--game/player/PlayerAudioScript.cpp62
-rw-r--r--game/player/PlayerAudioScript.h13
-rw-r--r--game/player/PlayerEndScript.cpp7
-rw-r--r--game/player/PlayerScript.cpp28
-rw-r--r--game/player/PlayerScript.h1
-rw-r--r--game/player/PlayerSubScene.cpp52
6 files changed, 158 insertions, 5 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;
+ }
+}
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/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp
index fc3b8a1..92e48e3 100644
--- a/game/player/PlayerEndScript.cpp
+++ b/game/player/PlayerEndScript.cpp
@@ -2,6 +2,7 @@
#include "PlayerEndScript.h"
#include "../Config.h"
+#include "../Events.h"
#include "manager/LoopTimerManager.h"
#include <crepe/api/Animator.h>
@@ -91,7 +92,11 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) {
jump++;
}
- return true;
+ if (rb_player.data.linear_velocity.x < 5) {
+ this->trigger_event<EndGameEvent>();
+ }
+
+ return false;
}
return false;
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) {
diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h
index cec27ce..30f39c6 100644
--- a/game/player/PlayerScript.h
+++ b/game/player/PlayerScript.h
@@ -17,4 +17,5 @@ private:
std::chrono::time_point<std::chrono::steady_clock> last_fired;
std::chrono::duration<float> shot_delay = std::chrono::duration<float>(0.5);
+ int current_jetpack_sound = 0;
};
diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp
index 99a0fb4..be104b5 100644
--- a/game/player/PlayerSubScene.cpp
+++ b/game/player/PlayerSubScene.cpp
@@ -1,10 +1,14 @@
#include "PlayerSubScene.h"
+#include "PlayerAudioScript.h"
#include "PlayerEndScript.h"
#include "PlayerScript.h"
#include "../Config.h"
+#include "../coins/CoinScript.h"
+#include "api/Asset.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>
@@ -148,6 +152,52 @@ PlayerSubScene::PlayerSubScene(Scene & scn) {
= {COLL_LAY_BOT_TOP, COLL_LAY_ZAPPER, COLL_LAY_LASER, COLL_LAY_MISSILE,COLL_LAY_BULLET},
.collision_layer = COLL_LAY_PLAYER,
});
- player.add_component<BehaviorScript>().set_script<PlayerScript>().active = true;
+ player.add_component<BehaviorScript>().set_script<PlayerScript>().active = false;
+ player.add_component<BehaviorScript>().set_script<CoinScript>();
player.add_component<BehaviorScript>().set_script<PlayerEndScript>().active = false;
+
+ player.add_component<AudioSource>(Asset("asset/sfx/dud_zapper_lp.ogg"));
+ player.add_component<AudioSource>(Asset("asset/sfx/dud_zapper_pop.ogg"));
+ player.add_component<AudioSource>(Asset("asset/sfx/dud_fire.ogg"));
+ player.add_component<AudioSource>(Asset("asset/sfx/jetpack_firecracker_lp_01.ogg")).volume
+ = 0.1;
+ player.add_component<AudioSource>(Asset("asset/sfx/jetpack_firecracker_lp_02.ogg")).volume
+ = 0.1;
+ player.add_component<AudioSource>(Asset("asset/sfx/jetpack_firecracker_lp_03.ogg")).volume
+ = 0.1;
+ player.add_component<AudioSource>(Asset("asset/sfx/jetpack_firecracker_lp_04.ogg")).volume
+ = 0.1;
+ player.add_component<AudioSource>(Asset("asset/sfx/jetpack_firecracker_lp_05.ogg")).volume
+ = 0.1;
+ player.add_component<AudioSource>(Asset("asset/sfx/jetpack_firecracker_lp_06.ogg")).volume
+ = 0.1;
+ player.add_component<AudioSource>(Asset("asset/sfx/jetpack_firecracker_lp_07.ogg")).volume
+ = 0.1;
+ player.add_component<AudioSource>(Asset("asset/sfx/jetpack_firecracker_lp_08.ogg")).volume
+ = 0.1;
+
+ 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")).volume
+ = 3.0;
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_right_1.ogg"))
+ .volume
+ = 3.0;
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_left_2.ogg")).volume
+ = 3.0;
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_right_2.ogg"))
+ .volume
+ = 3.0;
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_left_3.ogg")).volume
+ = 3.0;
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_right_3.ogg"))
+ .volume
+ = 3.0;
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_left_4.ogg")).volume
+ = 3.0;
+ player_audio.add_component<AudioSource>(Asset("asset/sfx/barefoot_step_right_4.ogg"))
+ .volume
+ = 3.0;
+
+ player_audio.add_component<BehaviorScript>().set_script<PlayerAudioScript>().active
+ = false;
}