aboutsummaryrefslogtreecommitdiff
path: root/game/player/PlayerAudioScript.cpp
blob: 6b5f63024d0549dcae28b4d24c56c2a0fa34a36f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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;
	}
}