-
Notifications
You must be signed in to change notification settings - Fork 1
/
game_over.c
64 lines (51 loc) · 1.34 KB
/
game_over.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
#include "game_over.h"
#include "draw.h"
#include "text.h"
#include "io.h"
#include <stdio.h>
scene_t *game_over_scene(void)
{
scene_t *s = malloc(sizeof(scene_t));
s->init = &game_over_init;
s->update = &game_over_update;
s->draw = &game_over_draw;
return s;
}
void game_over_init(game_state_t *state)
{
(void)state;
graphics_redraw(state->device);
}
int game_over_update(game_state_t *state)
{
(void)state;
if (state->time > 1.0f)
if (state->p1_right_clicked) {
io_handle_click_right(state);
return 0;
}
return 1;
}
void game_over_draw(game_state_t *state)
{
rect_t banner = (rect_t){{0, 170}, {state->area.x, 90} };
color_t col = (color_t){0, 0, 0, 255};
draw_rect(state, &banner, &col);
banner = (rect_t){{0, state->area.y}, {state->area.x, 32} };
draw_rect(state, &banner, &col);
print_text(state, "GAME OVER", &(vector2_t){165, 181});
char str[16];
if (state->player_count == 1) {
sprintf(str, "TIME: %.1f", (double)state->timer_game);
print_text(state, str, &(vector2_t){145, 231});
} else {
for (int i = 0; i < state->player_count; i++)
if (state->player[i].lives > 0) {
col = player_number_color(i + 1);
sprintf(str, "PLAYER %i WINS!", i + 1);
}
print_text_color(state, str, &(vector2_t){136, 231}, &col);
}
if (state->time > 1.0f)
print_text(state, "PRESS R TO RESTART", &(vector2_t){66, 484});
}