-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoundManager.cs
64 lines (54 loc) · 1.51 KB
/
SoundManager.cs
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
63
64
using System;
using System.Threading.Tasks;
using Microsoft.JSInterop;
namespace BlazorRogue
{
public class SoundManager
{
private readonly IJSRuntime jsRuntime;
private readonly Random random = new Random();
private readonly string footstepDirtPrefix = "Footstep_Dirt_0";
public SoundManager(IJSRuntime jsRuntime)
{
this.jsRuntime = jsRuntime;
}
private async Task PlaySound(string sound)
{
await jsRuntime.InvokeAsync<object>("blazorroguefuncs.playSound", $"sound/{sound}");
}
public async void PlayWalkSound()
{
var soundindex = random.Next(0, 10);
var sound = $"{footstepDirtPrefix}{soundindex}.mp3";
await PlaySound(sound);
}
public async void PlayDoorSound(bool open)
{
var prefix = open ? "open" : "close";
var soundindex = random.Next(1, 3);
var sound = $"{prefix}_door_{soundindex}.mp3";
await PlaySound(sound);
}
public async void PlayCombatSound(bool hit)
{
var sound = hit ? "sfx-attack-sword-001.wav" : "Swoosh.mp3";
await PlaySound(sound);
}
internal async void PlayKillMonsterSound()
{
var sound = "creature_die8.wav";
await PlaySound(sound);
}
internal async void PlayGameLoose()
{
var sound = "Jingle_Lose_00.mp3";
await PlaySound(sound);
}
internal async void PlayPickupMoney()
{
var soundindex = random.Next(0, 5);
var sound = $"Pickup_Gold_0{soundindex}.mp3";
await PlaySound(sound);
}
}
}