-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_resource.c
92 lines (85 loc) · 3.2 KB
/
menu_resource.c
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
87
88
89
90
91
92
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* menu_resource.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhedeon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/19 20:27:47 by mhedeon #+# #+# */
/* Updated: 2019/01/31 17:26:38 by mhedeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
int free_menu_screen(t_menu *menu)
{
if (menu->menu[0].sur != NULL)
destroy_texture(&menu->menu[0]);
if (menu->menu[1].sur != NULL)
destroy_texture(&menu->menu[1]);
if (menu->level[0].sur != NULL)
destroy_texture(&menu->level[0]);
if (menu->level[1].sur != NULL)
destroy_texture(&menu->level[1]);
if (menu->start[0].sur != NULL)
destroy_texture(&menu->start[0]);
if (menu->start[1].sur != NULL)
destroy_texture(&menu->start[1]);
if (menu->start[2].sur != NULL)
destroy_texture(&menu->start[2]);
if (menu->cursor.sur != NULL)
destroy_texture(&menu->cursor);
return (0);
}
int init_menu_screen(t_menu *menu)
{
if (!load_texture(&menu->menu[0], "resource/img/menu/menu-1.jpg"))
return (free_menu_screen(menu));
if (!load_texture(&menu->menu[1], "resource/img/menu/menu-2.jpg"))
return (free_menu_screen(menu));
if (!load_texture(&menu->level[0], "resource/img/menu/level-1.jpg"))
return (free_menu_screen(menu));
if (!load_texture(&menu->level[1], "resource/img/menu/level-2.jpg"))
return (free_menu_screen(menu));
if (!load_texture(&menu->start[0], "resource/img/menu/start-1.jpg"))
return (free_menu_screen(menu));
if (!load_texture(&menu->start[1], "resource/img/menu/start-2.jpg"))
return (free_menu_screen(menu));
if (!load_texture(&menu->start[2], "resource/img/menu/start-3.jpg"))
return (free_menu_screen(menu));
if (!load_texture(&menu->cursor, "resource/img/menu/cursor.png"))
return (free_menu_screen(menu));
return (1);
}
int free_menu_sound(t_menu *menu)
{
if (menu->music != NULL)
Mix_FreeMusic(menu->music);
if (menu->toggle != NULL)
Mix_FreeChunk(menu->toggle);
if (menu->select != NULL)
Mix_FreeChunk(menu->select);
return (0);
}
int init_menu_sound(t_menu *menu)
{
menu->music = Mix_LoadMUS("resource/sounds/music/menu.mid");
if (menu->music == NULL)
return (free_menu_sound(menu));
menu->toggle = Mix_LoadWAV("resource/sounds/chunk/Menu Toggle.wav");
if (menu->toggle == NULL)
return (free_menu_sound(menu));
menu->select = Mix_LoadWAV("resource/sounds/chunk/Menu Select.wav");
if (menu->select == NULL)
return (free_menu_sound(menu));
return (1);
}
int start_menu(t_wolf *wolf, t_menu *menu)
{
int lvl;
lvl = -1;
if (init_menu_screen(menu) && init_menu_sound(menu))
lvl = m_menu(wolf, menu);
free_menu_screen(menu);
free_menu_sound(menu);
return (lvl);
}