Zahlenrendern für Prototyp.
authorWintermute <wintermute@hannover.ccc.de>
Sat, 19 Oct 2013 16:42:44 +0000 (18:42 +0200)
committerWintermute <wintermute@hannover.ccc.de>
Sat, 19 Oct 2013 16:42:44 +0000 (18:42 +0200)
badge/jumpnrun/gnobbel.lv
badge/jumpnrun/jumpnrun.c
badge/jumpnrun/levels.txt
badge/main.c
badge/ui/font.c
badge/ui/font.h

index d31670d..f6cf1dc 100644 (file)
@@ -1,16 +1,16 @@
+                                                                                                                           X
 
+                                                                                                                                                                      
 
-
-
-                                                                                                                                                   ###    #   ###
-                     ##                                                                                                           #####                           ###
-                    ###                                                                                                          #
-                   ####                                                          ###      #######                             #
-                  #####                 ##      ##     ##        ##     ###  ##                             ###              #                                                       ######
-                 ######                                   ##     ###                                                ####
+                                                                                                                                          ###    #   ###              
+                     ##                                        V                                                         #####      #                    ###          V
+                    ###                                                                                                 #                                  #  M
+                   ####                                                 ###      #######        W  c                 #                                     ####   
+                  #####        ##      ##     ##        ##     ###  ##           V              ######              #                                                ##     ######
+                 ######                          ##     ###                                                ####                                                           V
                 #######
-               ########                                                                                                                                                                                                                        DC           
-######################################                                                                                                                                                              #################   ##      ##      #########                                            
+    P          ########                       W                                                                                                                                                G                                      dC
+#######################                                                                                                                                                                    #################   ##      ##      #########
 
 [tiles]
 0 tube_top_left
 3 tube_right
 # brick
 ? square
+^ spike_up
+v spike_down
+> spike_right
+< spike_left
 
 [items]
-D doc
+d doc
+c checkpoint
+k key
+e doc_encrypted
 
 [enemies]
 C cat
+M mushroom
+B bunny
+S snake
+@ spiral
+R rotor
+H dog
+G giraffe
+V bird
+W bird_straight
+X bird_dip
index d3fa992..0bdac94 100644 (file)
@@ -338,7 +338,7 @@ uint8_t jumpnrun_play(char const *lvname) {
   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));
index ab05360..93150ce 100644 (file)
@@ -1,5 +1,5 @@
-smb
 gnobbel
+smb
 wrongturn
 foo
 mean
index be4ad7a..25a4356 100644 (file)
@@ -231,6 +231,7 @@ int main(void)
     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);
   }
index 1ea57ad..2b60477 100644 (file)
@@ -21,10 +21,14 @@ static uint8_t badge_framebuffer_render_char_with_fd(badge_framebuffer *fb, int8
   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;
@@ -37,7 +41,7 @@ uint8_t badge_framebuffer_render_text(badge_framebuffer *fb, int8_t pos_x, int8_
   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;
@@ -53,3 +57,30 @@ uint8_t badge_framebuffer_render_text(badge_framebuffer *fb, int8_t pos_x, int8_
 
   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;
+}
index 12b43a1..e6fe0b4 100644 (file)
@@ -10,5 +10,6 @@ enum {
 
 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
This page took 0.030682 seconds and 4 git commands to generate.