Schrift fest in Firmware eingebacken, damit die auch funktioniert, wenn auf dem
[hackover2013-badge-firmware.git] / badge / jumpnrun / stats.c
1 #include "stats.h"
2
3 #include "items.h"
4 #include "jumpnrun.h"
5 #include "render.h"
6
7 #include "../ui/display.h"
8 #include "../ui/event.h"
9 #include "../ui/font.h"
10
11 void jumpnrun_show_lives_screen(jumpnrun_game_state const *state) {
12 badge_framebuffer fb = { { { 0 } } };
13
14 int8_t y_upper = BADGE_DISPLAY_HEIGHT / 2 - BADGE_FONT_HEIGHT;
15 int8_t y_lower = (BADGE_DISPLAY_HEIGHT + BADGE_FONT_HEIGHT) / 2;
16 int8_t x_mid = (BADGE_DISPLAY_WIDTH - BADGE_FONT_WIDTH ) / 2;
17 int8_t x_left = x_mid - BADGE_FONT_WIDTH - 5;
18 int8_t x_right = x_mid + BADGE_FONT_WIDTH + 5;
19
20 char buf[] = "x";
21 if(state->player.keys != 0) {
22 y_upper -= BADGE_FONT_HEIGHT;
23 }
24
25 jumpnrun_render_player_symbol(&fb, x_left, y_upper);
26 badge_framebuffer_render_text (&fb, x_mid , y_upper, buf);
27 badge_framebuffer_render_number(&fb, x_right, y_upper, state->player.lives);
28
29 if(state->player.keys != 0) {
30 jumpnrun_render_key_symbol(&fb, x_left, y_lower);
31 badge_framebuffer_render_text (&fb, x_mid , y_lower, buf);
32 badge_framebuffer_render_number(&fb, x_right, y_lower, state->player.keys);
33 }
34
35 badge_framebuffer_flush(&fb);
36
37 for(uint8_t i = 0; i < 75; ) {
38 badge_event_t ev = badge_event_wait();
39 if(badge_event_type(ev) == BADGE_EVENT_GAME_TICK) {
40 ++i;
41 } else if(i > 25) {
42 uint8_t old_state = badge_event_old_input_state(ev);
43 uint8_t new_state = badge_event_new_input_state(ev);
44 uint8_t new_buttons = new_state & (old_state ^ new_state);
45
46 if(new_buttons != 0) break;
47 }
48 }
49 }
50
51 static void jumpnrun_show_message(char const *msg) {
52 badge_framebuffer fb = { { { 0 } } };
53
54 size_t len = strlen(msg);
55 size_t wid = len * BADGE_FONT_WIDTH;
56 size_t off = (BADGE_DISPLAY_WIDTH - wid + 1) / 2;
57
58 badge_framebuffer_render_text(&fb, off, BADGE_DISPLAY_HEIGHT / 2 - BADGE_FONT_WIDTH, msg);
59 badge_framebuffer_flush(&fb);
60
61 for(uint8_t i = 0; i < 75; ) {
62 badge_event_t ev = badge_event_wait();
63 if(badge_event_type(ev) == BADGE_EVENT_GAME_TICK) {
64 ++i;
65 }
66 }
67 }
68
69 void jumpnrun_show_game_over(void) {
70 char msg[] = "GAME OVER";
71 jumpnrun_show_message(msg);
72 }
73
74 void jumpnrun_show_you_rock (void) {
75 char msg[] = "YOU ROCK!!1!";
76 jumpnrun_show_message(msg);
77 }
This page took 0.057041 seconds and 5 git commands to generate.