Lebensscreen.
authorWintermute <wintermute@hannover.ccc.de>
Sat, 19 Oct 2013 18:46:22 +0000 (20:46 +0200)
committerWintermute <wintermute@hannover.ccc.de>
Sat, 19 Oct 2013 18:46:22 +0000 (20:46 +0200)
badge/jumpnrun/jumpnrun.c
badge/jumpnrun/jumpnrun.h
badge/jumpnrun/stats.c [new file with mode: 0644]
badge/jumpnrun/stats.h [new file with mode: 0644]
mock/Makefile

index 0bdac94..dc1dc6c 100644 (file)
@@ -1,6 +1,7 @@
 #include "jumpnrun.h"
 #include "collision.h"
 #include "levels.h"
+#include "stats.h"
 
 #include "../ui/display.h"
 #include "../ui/event.h"
@@ -47,6 +48,10 @@ static badge_sprite const anim_hacker[] = {
   */
 };
 
+badge_sprite const *jumpnrun_hacker_symbol(void) {
+  return &anim_hacker[0];
+}
+
 static badge_sprite const anim_sickle[] = {
   { 3, 3, (uint8_t const *) "\xab\x01" },
   { 3, 3, (uint8_t const *) "\xee\x00" }
@@ -339,6 +344,21 @@ uint8_t jumpnrun_play(char const *lvname) {
   memset(&gs, 0, sizeof(gs));
 
   for(gs.lives = 99; gs.status != JUMPNRUN_WON && gs.lives != 0; --gs.lives) {
+    jumpnrun_show_lives_screen(&gs);
+
+    for(uint8_t i = 0; i < 75; ) {
+      badge_event_t ev = badge_event_wait();
+      if(badge_event_type(ev) == BADGE_EVENT_GAME_TICK) {
+        ++i;
+      } else if(i > 25) {
+        uint8_t old_state = badge_event_old_input_state(ev);
+        uint8_t new_state = badge_event_new_input_state(ev);
+        uint8_t new_buttons = new_state & (old_state ^ new_state);
+
+        if(new_buttons != 0) break;
+      }
+    }
+
     gs.status = JUMPNRUN_PLAYING;
     gs.left = 0;
     memset(&gs.player, 0, sizeof(gs.player));
index 899eebc..f2933d9 100644 (file)
@@ -51,6 +51,7 @@ typedef struct jumpnrun_game_state {
 
 vec2d hacker_extents(void);
 void jumpnrun_passive_movement(vec2d *inertia);
+badge_sprite const *jumpnrun_hacker_symbol(void);
 
 uint8_t jumpnrun_play(char const *lvname);
 
diff --git a/badge/jumpnrun/stats.c b/badge/jumpnrun/stats.c
new file mode 100644 (file)
index 0000000..74338ec
--- /dev/null
@@ -0,0 +1,35 @@
+#include "stats.h"
+#include "jumpnrun.h"
+#include "items.h"
+#include "../ui/display.h"
+#include "../ui/font.h"
+
+void jumpnrun_show_lives_screen(jumpnrun_game_state const *state) {
+  badge_framebuffer fb = { { { 0 } } };
+
+  badge_sprite const *hacker =  jumpnrun_hacker_symbol();
+  badge_sprite const *key    = &jumpnrun_item_type_data[JUMPNRUN_ITEM_TYPE_KEY].sprite;
+
+  int8_t y_upper = BADGE_DISPLAY_HEIGHT / 2 - BADGE_FONT_HEIGHT;
+  int8_t y_lower = (BADGE_DISPLAY_HEIGHT + BADGE_FONT_HEIGHT) / 2;
+  int8_t x_left  = BADGE_DISPLAY_WIDTH / 2 - hacker->width - BADGE_FONT_WIDTH - 5;
+  int8_t x_mid   = (BADGE_DISPLAY_WIDTH - BADGE_FONT_WIDTH) / 2;
+  int8_t x_right = x_mid + BADGE_FONT_WIDTH + 5;
+
+  char buf[] = "x";
+  if(state->keys != 0) {
+    y_upper -= BADGE_FONT_HEIGHT;
+  }
+
+  badge_framebuffer_blt          (&fb, x_left , y_upper, hacker, 0);
+  badge_framebuffer_render_text  (&fb, x_mid  , y_upper, buf);
+  badge_framebuffer_render_number(&fb, x_right, y_upper, state->lives);
+
+  if(state->keys != 0) {
+    badge_framebuffer_blt          (&fb, x_left , y_lower, key, 0);
+    badge_framebuffer_render_text  (&fb, x_mid  , y_lower, buf);
+    badge_framebuffer_render_number(&fb, x_right, y_lower, state->keys);
+  }
+
+  badge_framebuffer_flush(&fb);
+}
diff --git a/badge/jumpnrun/stats.h b/badge/jumpnrun/stats.h
new file mode 100644 (file)
index 0000000..e9e8950
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef INCLUDED_BADGE_JUMPNRUN_STATS_H
+#define INCLUDED_BADGE_JUMPNRUN_STATS_H
+
+#include "jumpnrun.h"
+
+void jumpnrun_show_lives_screen(jumpnrun_game_state const *state);
+
+#endif
index 34ddd32..93a7210 100644 (file)
@@ -24,7 +24,8 @@ BADGE_CSRCS   = badge_main_loop.c \
                 jumpnrun/items.c \
                 jumpnrun/jumpnrun.c \
                 jumpnrun/tiles.c \
-                jumpnrun/level_load.c
+                jumpnrun/level_load.c \
+                jumpnrun/stats.c
 
 BADGE_CXXOBJS = $(BADGE_CXXSRCS:%.cc=%.o)
 BADGE_COBJS   = $(BADGE_CSRCS:%.c=%.o)
This page took 0.029795 seconds and 4 git commands to generate.