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
93
94
95
96
97
98
99
100
101
102
|
#include "input.h"
#include "init.h"
#include "menu.h"
#include "player.h"
#include "rodeo.h"
rodeo_texture_2d_t splash_texture;
rodeo_texture_2d_t main_menu_texture;
rodeo_texture_2d_t gameover_texture;
menu_state_t menu_state;
float splash_timer;
rodeo_rectangle_t screen_dimensions = (rodeo_rectangle_t){.x = 0, .y = 0, .width = 1600, .height = 900};
void
init_menu(void)
{
splash_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/splash.png"));
main_menu_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/mainmenu.png"));
gameover_texture = rodeo_texture_2d_create_from_path(cstr_lit("assets/gameover.png"));
menu_state = menu_state_splash;
splash_timer = 3000.0f;
rodeo_input_scene_activate(get_command_inputs()->menu_scene);
}
void
deinit_menu(void)
{
rodeo_texture_2d_destroy(&splash_texture);
rodeo_texture_2d_destroy(&main_menu_texture);
rodeo_texture_2d_destroy(&gameover_texture);
}
void
draw_menu(void)
{
if (splash_timer > 0 && menu_state == menu_state_splash)
{
splash_timer -= rodeo_frame_time_get();
rodeo_texture_2d_draw(
&screen_dimensions,
&screen_dimensions,
NULL,
&splash_texture
);
if (splash_timer <= 0) {
menu_state = menu_state_main;
}
}
else if (menu_state == menu_state_main)
{
rodeo_texture_2d_draw(
&screen_dimensions,
&screen_dimensions,
NULL,
&main_menu_texture
);
}
else if (menu_state == menu_state_gameover)
{
rodeo_texture_2d_draw(
&screen_dimensions,
&screen_dimensions,
NULL,
&gameover_texture
);
}
}
void
parse_menu_input(void)
{
int32_t hp = get_player_hp();
bool input = *(bool*)menu_accept_input(NULL, NULL);
if (input)
{
rodeo_input_scene_activate(get_command_inputs()->scene);
if (menu_state == menu_state_gameover && hp <= 0)
{
reset_game_systems();
menu_state = menu_state_inactive;
}
else if (menu_state == menu_state_main)
{
init_game_systems();
menu_state = menu_state_inactive;
}
}
}
menu_state_t
get_menu_state(void)
{
return menu_state;
}
void
set_menu_state(menu_state_t state)
{
menu_state = state;
}
|