diff --git a/overlay/rootfs/usr/bin/snake b/overlay/rootfs/usr/bin/snake index a77184b..aafc972 100755 Binary files a/overlay/rootfs/usr/bin/snake and b/overlay/rootfs/usr/bin/snake differ diff --git a/overlay/rootfs/usr/bin/tetris b/overlay/rootfs/usr/bin/tetris index 76d4023..4828d86 100755 Binary files a/overlay/rootfs/usr/bin/tetris and b/overlay/rootfs/usr/bin/tetris differ diff --git a/prebuilt/games/usr/bin/snake b/prebuilt/games/usr/bin/snake index a77184b..aafc972 100755 Binary files a/prebuilt/games/usr/bin/snake and b/prebuilt/games/usr/bin/snake differ diff --git a/prebuilt/games/usr/bin/tetris b/prebuilt/games/usr/bin/tetris index 76d4023..4828d86 100755 Binary files a/prebuilt/games/usr/bin/tetris and b/prebuilt/games/usr/bin/tetris differ diff --git a/src/games/snake.cpp b/src/games/snake.cpp index 0fe1128..77dabe6 100644 --- a/src/games/snake.cpp +++ b/src/games/snake.cpp @@ -70,6 +70,11 @@ static const Glyph GLYPHS[] = { {'7', {0b11111,0b00001,0b00010,0b00100,0b01000,0b01000,0b01000}}, {'8', {0b01110,0b10001,0b10001,0b01110,0b10001,0b10001,0b01110}}, {'9', {0b01110,0b10001,0b10001,0b01111,0b00001,0b00010,0b01100}}, + {'/', {0b00001,0b00010,0b00100,0b00100,0b01000,0b01000,0b10000}}, + {'#', {0b01010,0b01010,0b11111,0b01010,0b11111,0b01010,0b01010}}, + {'*', {0b00100,0b01010,0b11111,0b01010,0b00100,0b00000,0b00000}}, + {'+', {0b00000,0b00100,0b00100,0b11111,0b00100,0b00100,0b00000}}, + {'=', {0b00000,0b00000,0b11111,0b00000,0b11111,0b00000,0b00000}}, }; static const int NGLYPH = int(sizeof(GLYPHS) / sizeof(GLYPHS[0])); @@ -101,8 +106,8 @@ static int ndirx = 1, ndiry = 0; // buffered next direction static int foodx, foody; static int score = 0; static int best = 0; -static int speed = 130; // ms per step (derived from pps below) -static int pps = 70; // base speed px/sec; +1 px/sec per 5 food eaten +static int speed = 90; // ms per step (derived from pps below) +static int pps = 100; // base speed px/sec; +1 px/sec per 5 food eaten static unsigned long nextTick = 0; static bool running = true; static unsigned long now_ms() { @@ -160,7 +165,7 @@ static void reset_game() { dirx = 1; diry = 0; ndirx = 1; ndiry = 0; score = 0; - pps = 70; + pps = 100; update_speed(); place_food(); state = PLAYING; @@ -174,7 +179,9 @@ static void step() { } int hx = snake[snakelen - 1][0] + dirx; int hy = snake[snakelen - 1][1] + diry; - if (hx < 0 || hx >= COLS || hy < 0 || hy >= ROWS) { state = GAMEOVER; return; } + // wrap through the opposite edge instead of dying at the wall + hx = (hx + COLS) % COLS; + hy = (hy + ROWS) % ROWS; // self collision (ignore current tail cell since it will move, unless growing) for (int i = 0; i < snakelen - 1; i++) { if (snake[i][0] == hx && snake[i][1] == hy) { state = GAMEOVER; return; } @@ -204,16 +211,14 @@ static void step() { static void draw_text(int x, int y, int scale, unsigned long col, const char* s) { int cx = x; + XSetForeground(dpy, gc, col); for (const char* p = s; *p; p++) { const unsigned char* g = glyph(*p); for (int r = 0; r < 7; r++) { unsigned char row = g[r]; - for (int b = 0; b < 5; b++) { - if (row & (1 << (4 - b))) { - XSetForeground(dpy, gc, col); + for (int b = 0; b < 5; b++) + if (row & (1 << (4 - b))) XFillRectangle(dpy, back, gc, cx + b * scale, y + r * scale, scale, scale); - } - } } cx += 6 * scale; } diff --git a/src/games/tetris.cpp b/src/games/tetris.cpp index bc6be0c..b92358b 100644 --- a/src/games/tetris.cpp +++ b/src/games/tetris.cpp @@ -72,6 +72,11 @@ static const Glyph GLYPHS[] = { {'7', {0b11111,0b00001,0b00010,0b00100,0b01000,0b01000,0b01000}}, {'8', {0b01110,0b10001,0b10001,0b01110,0b10001,0b10001,0b01110}}, {'9', {0b01110,0b10001,0b10001,0b01111,0b00001,0b00010,0b01100}}, + {'/', {0b00001,0b00010,0b00100,0b00100,0b01000,0b01000,0b10000}}, + {'#', {0b01010,0b01010,0b11111,0b01010,0b11111,0b01010,0b01010}}, + {'*', {0b00100,0b01010,0b11111,0b01010,0b00100,0b00000,0b00000}}, + {'+', {0b00000,0b00100,0b00100,0b11111,0b00100,0b00100,0b00000}}, + {'=', {0b00000,0b00000,0b11111,0b00000,0b11111,0b00000,0b00000}}, }; static const int NGLYPH = int(sizeof(GLYPHS) / sizeof(GLYPHS[0])); static const unsigned char* glyph(char c) { @@ -245,15 +250,14 @@ static void reset_game() { static void draw_text(int x, int y, int scale, unsigned long col, const char* s) { int cx = x; + XSetForeground(dpy, gc, col); for (const char* p = s; *p; p++) { const unsigned char* g = glyph(*p); for (int r = 0; r < 7; r++) { unsigned char row = g[r]; for (int b = 0; b < 5; b++) - if (row & (1 << (4 - b))) { - XSetForeground(dpy, gc, col); + if (row & (1 << (4 - b))) XFillRectangle(dpy, back, gc, cx + b * scale, y + r * scale, scale, scale); - } } cx += 6 * scale; }