-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsounds.c
More file actions
86 lines (79 loc) · 2.38 KB
/
sounds.c
File metadata and controls
86 lines (79 loc) · 2.38 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sounds.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bturcott <bturcott@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/22 17:31:18 by bturcott #+# #+# */
/* Updated: 2019/04/25 10:51:54 by bturcott ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf.h"
#define OPEN_MAP "./sounds/map.wav"
#define ENCOUNTER_WALLS "./sounds/collision.wav"
#define STEPS "./sounds/steps.wav"
#define CUSTOM "./sounds/custom.wav"
#define MUSIC "./sounds/music.wav"
int init_music(t_sdl *sdl)
{
Mix_Chunk **samples;
Mix_Music *mus;
if ((Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 4096) == -1))
{
ft_putendl("no music :(");
return (-1);
}
if (!(samples = ft_memalloc(sizeof(Mix_Chunk *) * 5)))
return (-1);
mus = Mix_LoadMUS(MUSIC);
samples[0] = Mix_LoadWAV(OPEN_MAP);
samples[1] = Mix_LoadWAV(STEPS);
samples[2] = Mix_LoadWAV(ENCOUNTER_WALLS);
samples[3] = Mix_LoadWAV(CUSTOM);
sdl->samples = samples;
sdl->music = mus;
Mix_PlayMusic(mus, -1);
Mix_AllocateChannels(4);
return (1);
}
int sounds_control_panel(Mix_Chunk **samples, int command)
{
if (command == 1)
{
if (!Mix_Playing(1))
Mix_PlayChannel(1, samples[0], 0);
}
else if (command == 2)
{
if (!Mix_Playing(2))
Mix_PlayChannel(2, samples[1], 0);
}
else if (command == 3)
{
if (!Mix_Playing(3))
Mix_PlayChannel(3, samples[2], 0);
}
else if (command == 4)
{
if (!Mix_Playing(4))
Mix_PlayChannel(4, samples[3], 0);
}
return (0);
}
void sounds(t_sdl *sdl, SDL_Event e)
{
SDL_Scancode key;
key = e.key.keysym.scancode;
if (key == 26 || key == 4 || key == 22 || key == 7)
sounds_control_panel(sdl->samples, 2);
else if (key == 16)
sounds_control_panel(sdl->samples, 1);
else if (key == 48)
{
if (Mix_PausedMusic() == 1)
Mix_ResumeMusic();
else
Mix_PauseMusic();
}
}