fix(games): complete font (U/W + A-Z), fix Tetris gravity, frame + center overlays

- Font: add missing glyphs (U, W and complete A-Z) to both Snake and
  Tetris 5x7 bitmap fonts so PAUSE/RESUME/NEW GAME render correctly.
- Tetris: the gravity loop never advanced nextTick after a step, so the
  piece dropped almost instantly every frame. Advance nextTick by speed
  after each step (matching Snake) so gravity honours the configured rate.
- Both: draw a 1px frame around the whole 240x296 window (right/bottom
  edges were previously absent) and clear the playfield to black behind
  PAUSE/GAME OVER text for contrast.
- Both: fix centering of overlay labels (GAME OVER, 5 RESUME, 5 NEW GAME).
This commit is contained in:
Luxferre
2026-10-23 15:30:29 +03:00
parent 3eb54e4306
commit 6bf4139263
6 changed files with 39 additions and 11 deletions
+16 -4
View File
@@ -57,6 +57,10 @@ static const Glyph GLYPHS[] = {
{'V', {0b10001,0b10001,0b10001,0b10001,0b10001,0b01010,0b00100}},
{'W', {0b10001,0b10001,0b10001,0b10101,0b10101,0b11011,0b10001}},
{'Y', {0b10001,0b10001,0b01010,0b00100,0b00100,0b00100,0b00100}},
{'J', {0b00010,0b00010,0b00010,0b00010,0b10010,0b10010,0b01100}},
{'Q', {0b01110,0b10001,0b10001,0b10001,0b10101,0b10010,0b01101}},
{'U', {0b10001,0b10001,0b10001,0b10001,0b10001,0b10001,0b01110}},
{'Z', {0b11111,0b00010,0b00100,0b01000,0b10000,0b10000,0b11111}},
{'0', {0b01110,0b10011,0b10101,0b10101,0b11001,0b10001,0b01110}},
{'1', {0b00100,0b01100,0b00100,0b00100,0b00100,0b00100,0b01110}},
{'2', {0b01110,0b10001,0b00001,0b00110,0b01000,0b10000,0b11111}},
@@ -213,6 +217,10 @@ static void render() {
XSetForeground(dpy, gc, C_DIM);
XDrawRectangle(dpy, back, gc, gx0 - 1, gy0 - 1, gw + 2, gh + 2);
// frame the whole window (right/bottom edges too)
XSetForeground(dpy, gc, C_DIM);
XDrawRectangle(dpy, back, gc, 0, 0, winW - 1, winH - 1);
// food
if (foodx >= 0) {
XSetForeground(dpy, gc, C_FOOD);
@@ -233,14 +241,18 @@ static void render() {
draw_text(gx0 + gw - 11 * 6, 2, 1, C_DIM, buf);
}
if (state == PAUSED || state == GAMEOVER) {
XSetForeground(dpy, gc, C_BG);
XFillRectangle(dpy, back, gc, 0, 0, winW, winH);
}
if (state == PAUSED) {
draw_text(winW / 2 - 3 * 6 * 2, winH / 2 - 7 * 2, 2, C_FG, "PAUSE");
draw_text(winW / 2 - 5 * 6, winH / 2 + 7 * 2, 1, C_DIM, "5 RESUME");
draw_text(winW / 2 - 5 * 6, winH / 2 - 7 * 2, 2, C_FG, "PAUSE");
draw_text(winW / 2 - 4 * 6, winH / 2 + 7 * 2, 1, C_DIM, "5 RESUME");
} else if (state == GAMEOVER) {
draw_text(winW / 2 - 4 * 6 * 2, winH / 2 - 14, 2, C_FG, "GAME OVER");
draw_text(winW / 2 - 9 * 6, winH / 2 - 14, 2, C_FG, "GAME OVER");
snprintf(buf, sizeof(buf), "SCORE %d", score);
draw_text(winW / 2 - 5 * 6, winH / 2 + 4, 1, C_DIM, buf);
draw_text(winW / 2 - 9 * 6, winH / 2 + 4 + 9, 1, C_DIM, "5 NEW GAME");
draw_text(winW / 2 - 5 * 6, winH / 2 + 4 + 9, 1, C_DIM, "5 NEW GAME");
}
XCopyArea(dpy, back, win, gc, 0, 0, winW, winH, 0, 0);