-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.c
74 lines (55 loc) · 1.42 KB
/
menu.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
#include "menu.h"
#include <stdio.h>
#include "player.h"
#include "text.h"
#include "draw.h"
#include "io.h"
scene_t *menu_scene(void)
{
scene_t *s = malloc(sizeof(scene_t));
s->init = &menu_init;
s->update = &menu_update;
s->draw = &menu_draw;
return s;
}
void menu_init(game_state_t *state)
{
(void)state;
}
int menu_update(game_state_t *state)
{
if (state->p1_right_clicked) {
io_handle_click_right(state);
return 0;
}
if (state->p1_left_held) {
io_handle_hold_left(state);
state->player_count = (state->player_count) % 4 + 1;
}
return 1;
}
void menu_draw(game_state_t *state)
{
char player_num[8];
draw_background(state);
color_t col = (color_t){0, 0, 0, 255};
/* graphics_background_color(state->device, &col); */
print_text(state, "MENU",
&(vector2_t){221, 161});
print_text(state, "L : SELECT R : START",
&(vector2_t){36, 484});
for (int i = 0; i < 4; i++) {
col = player_number_color(i + 1);
sprintf(player_num, "%d PLAYER", i + 1);
print_text_color(state, player_num,
&(vector2_t){181, 201 + 30 * i},
&(color_t){255, 255, 255, 255});
}
col = player_number_color(state->player_count);
sprintf(player_num, "%d PLAYER", state->player_count);
print_text_color(state, player_num,
&(vector2_t){181, 201 + 30 * (state->player_count - 1)}, &col);
draw_square(state,
&(vector2_t){160, 210 + 30 * (state->player_count - 1)},
14, (int)(360 * state->time/2.f) % 90, &col);
}