games: fix font glyphs, Snake edge-wrap, snappier Snake
Font: add missing bitmap glyphs (/ # * + =) to both Snake and Tetris so control labels like '4/6 MOVE' and '# PAUSE' render correctly. Also hoist XSetForeground out of the per-pixel loop in draw_text (both games). Snake: remove the wall-collision death; the head now wraps through the opposite edge ((hx+COLS)%COLS, (hy+ROWS)%ROWS). Base speed raised from 70->100 px/sec (~128ms -> ~90ms per step) so it feels less laggy; the +1 px/sec per 5 food progressive difficulty is unchanged.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user