7 #include "../ui/display.h"
8 #include "../ui/event.h"
9 #include "../ui/font.h"
11 void jumpnrun_show_lives_screen(jumpnrun_game_state
const *state
) {
12 badge_framebuffer fb
= { { { 0 } } };
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;
21 if(state
->player
.keys
!= 0) {
22 y_upper
-= BADGE_FONT_HEIGHT
;
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
);
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
);
35 badge_framebuffer_flush(&fb
);
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
) {
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
);
46 if(new_buttons
!= 0) break;
51 static void jumpnrun_show_message(char const *msg
) {
52 badge_framebuffer fb
= { { { 0 } } };
54 size_t len
= strlen(msg
);
55 size_t wid
= len
* BADGE_FONT_WIDTH
;
56 size_t off
= (BADGE_DISPLAY_WIDTH
- wid
+ 1) / 2;
58 badge_framebuffer_render_text(&fb
, off
, BADGE_DISPLAY_HEIGHT
/ 2 - BADGE_FONT_WIDTH
, msg
);
59 badge_framebuffer_flush(&fb
);
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
) {
69 void jumpnrun_show_game_over(void) {
70 char msg
[] = "GAME OVER";
71 jumpnrun_show_message(msg
);
74 void jumpnrun_show_you_rock (void) {
75 char msg
[] = "YOU ROCK!!1!";
76 jumpnrun_show_message(msg
);
This page took 0.066604 seconds and 5 git commands to generate.