jumpnrun_game_state gs;
memset(&gs, 0, sizeof(gs));
- for(gs.lives = 3; gs.status != JUMPNRUN_WON && gs.lives != 0; --gs.lives) {
+ for(gs.lives = 99; gs.status != JUMPNRUN_WON && gs.lives != 0; --gs.lives) {
gs.status = JUMPNRUN_PLAYING;
gs.left = 0;
memset(&gs.player, 0, sizeof(gs.player));
badge_framebuffer fb = { { { 0 } } };
fb.data[0][0] = badge_framebuffer_render_text(&fb, 2, 10, "foobar");
+ fb.data[0][1] = badge_framebuffer_render_number(&fb, 10, 18, 99);
badge_framebuffer_flush(&fb);
}
return 0;
}
+static FRESULT open_font_file(FIL *fd) {
+ return f_open(fd, "font.dat", FA_OPEN_EXISTING | FA_READ);
+}
+
uint8_t badge_framebuffer_render_char(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char c) {
FIL fd;
- if(FR_OK == f_open(&fd, "font.dat", FA_OPEN_EXISTING | FA_READ)) {
+ if(FR_OK == open_font_file(&fd)) {
badge_framebuffer_render_char_with_fd(fb, pos_x, pos_y, c, &fd);
f_close(&fd);
return 0;
uint8_t count = 0;
FIL fd;
- if(FR_OK == f_open(&fd, "font.dat", FA_OPEN_EXISTING | FA_READ)) {
+ if(FR_OK == open_font_file(&fd)) {
while(*text) {
if(0 != badge_framebuffer_render_char_with_fd(fb, pos_x, pos_y, *text, &fd)) {
break;
return count;
}
+
+static uint8_t badge_framebuffer_render_number_with_fd(badge_framebuffer *fb, int8_t *pos_x, int8_t pos_y, uint8_t number, FIL *fd) {
+ if(number > 10) {
+ badge_framebuffer_render_number_with_fd(fb, pos_x, pos_y, number / 10, fd);
+ }
+
+ uint8_t err = badge_framebuffer_render_char_with_fd(fb, *pos_x, pos_y, '0' + number % 10, fd);
+
+ if(err != 0) return err;
+
+ *pos_x += BADGE_FONT_WIDTH;
+ return 0;
+}
+
+uint8_t badge_framebuffer_render_number(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, uint8_t number) {
+ FIL fd;
+
+ if(FR_OK == open_font_file(&fd)) {
+ uint8_t err = badge_framebuffer_render_number_with_fd(fb, &pos_x, pos_y, number, &fd);
+
+ if(err != 0) {
+ return err;
+ }
+ }
+
+ return 0;
+}
uint8_t badge_framebuffer_render_char(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char c);
uint8_t badge_framebuffer_render_text(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char const *text);
+uint8_t badge_framebuffer_render_number(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, uint8_t number);
#endif