win anim + press any k

multi-mode
Ondřej Hruška 9 years ago
parent c0d2b618da
commit 02641ac008
  1. 61
      project/mode_snake.c
  2. 6
      project/scrolltext.c

@ -283,6 +283,20 @@ static void new_game(void)
while(com_rx(gamepad_iface, &x)); while(com_rx(gamepad_iface, &x));
} }
static bool press_any_key(void)
{
bool press = false;
if (com_rx_rdy(gamepad_iface)) {
uint8_t x;
while(com_rx(gamepad_iface, &x)) {
if (x >= 'A' && x <= 'Z') press = true;
}
return press;
}
return false;
}
static void snake_died(void) static void snake_died(void)
{ {
dbg("R.I.P. Snake"); dbg("R.I.P. Snake");
@ -306,27 +320,58 @@ static void snake_died(void)
snake_active = false; // suppress pending callbacks snake_active = false; // suppress pending callbacks
delay_ms(400);
dmtx_clear(dmtx); dmtx_clear(dmtx);
dmtx_blank(dmtx, true); // Screen off
// score
char txt[6]; char txt[6];
sprintf(txt, "%d", score); sprintf(txt, "%d", score);
size_t len = strlen(txt); size_t len = strlen(txt);
printtext(txt, (int)(SCREEN_W / 2 - (len * 5) / 2) - 1, SCREEN_H / 2 - 4); printtext(txt, (int)(SCREEN_W / 2 - (len * 5) / 2) - 1, SCREEN_H / 2 - 4);
delay_ms(400); dmtx_show(dmtx);
dmtx_blank(dmtx, false); // unblank
// discard input
uint8_t x;
while(com_rx(gamepad_iface, &x));
delay_ms(2000); bool interr = false;
until_timeout(10000) {
dmtx_blank(dmtx, true); // blank for (int x = 0; x < SCREEN_W; x++) {
delay_ms(400); dmtx_set(dmtx, SCREEN_W - x - 1, 0, 1);
dmtx_set(dmtx, x, SCREEN_H-1, 1);
dmtx_show(dmtx);
delay_ms(7);
dmtx_set(dmtx, SCREEN_W - x - 1, 0, 0);
dmtx_set(dmtx, x, SCREEN_H-1, 0);
if (press_any_key()) {
interr = true;
break;
}
}
if (interr) break;
for (int y = SCREEN_H-1; y >= 0; y--) {
dmtx_set(dmtx, 0, SCREEN_H - y - 1, 1);
dmtx_set(dmtx, SCREEN_W-1, y, 1);
dmtx_show(dmtx);
delay_ms(7);
dmtx_set(dmtx, 0, SCREEN_H - y - 1, 0);
dmtx_set(dmtx, SCREEN_W-1, y, 0);
if (press_any_key()) {
interr = true;
break;
}
}
if (interr) break;
}
dmtx_clear(dmtx); dmtx_clear(dmtx);
dmtx_show(dmtx); dmtx_show(dmtx);
dmtx_blank(dmtx, false); // unblank
snake_active = true; // resume snake snake_active = true; // resume snake
new_game(); new_game();
} }

@ -6,9 +6,6 @@
void printtext(const char *text, int x, int y) void printtext(const char *text, int x, int y)
{ {
dmtx_clear(dmtx);
dmtx_show(dmtx);
int totalX = 0; int totalX = 0;
for (int textX = 0; textX < (int)strlen(text); textX++) { for (int textX = 0; textX < (int)strlen(text); textX++) {
@ -45,7 +42,6 @@ void printtext(const char *text, int x, int y)
totalX+= 2; // gap totalX+= 2; // gap
} }
dmtx_show(dmtx);
} }
void scrolltext(const char *text, ms_time_t step) void scrolltext(const char *text, ms_time_t step)
@ -55,6 +51,8 @@ void scrolltext(const char *text, ms_time_t step)
for (int i = 0; i < (int)strlen(text)*(FONT_WIDTH+1) + SCREEN_W-1; i++) { for (int i = 0; i < (int)strlen(text)*(FONT_WIDTH+1) + SCREEN_W-1; i++) {
if (i > 0) delay_ms(step); if (i > 0) delay_ms(step);
dmtx_clear(dmtx);
printtext(text, (SCREEN_W-1)-i, SCREEN_H/2-4); printtext(text, (SCREEN_W-1)-i, SCREEN_H/2-4);
dmtx_show(dmtx);
} }
} }

Loading…
Cancel
Save