-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventHandler.h
More file actions
41 lines (31 loc) · 871 Bytes
/
Copy pathEventHandler.h
File metadata and controls
41 lines (31 loc) · 871 Bytes
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
#pragma once
#include "EventBus.h"
#include "Events.h"
#include "SoundManager.h"
#include "ProjectileSystem.h"
#include "Services.h"
class EventHandler {
public:
EventHandler(){}
void processEvents() {
if (!Services::eventBus) return;
Services::eventBus->process<ShootEvent>([&](const ShootEvent shot) {
if (!Services::sound) return;
if (shot.projectileType == "laser_shot") {
Services::sound->play(shot.soundName);
}
else if (shot.projectileType == "enemy_shot") {
Services::sound->play(shot.soundName);
}
});
Services::eventBus->process<SoundEvent>([&](const SoundEvent sound) {
if (!Services::sound) return;
if (sound.stop) {
Services::sound->stopForObject(sound.owner);
}
else {
Services::sound->playForObject(sound.owner, sound.soundName, sound.volume, sound.loop, sound.startTime);
}
});
}
};