games: snappier Snake turns + Gameboy-style Tetris blocks
Snake: add a turn queue (up to 4 pending direction changes) so rapid key presses are never lost, and raise base speed from 70->130 px/sec (~128ms -> ~69ms per step) for snappier, more responsive play. Progressive difficulty (+1 px/sec per 5 food) is unchanged. Tetris: replace solid-green blocks with Gameboy-style 4-shade beveled cells (pale top/left highlight, medium body, dark bottom/right shadow). Settled blocks use C_GB_MED, the active piece uses C_GB_LIGHT, and the next-piece preview is beveled too.
This commit is contained in:
1 parent
8eccef3060
commit
0abf305dff
6 files changed
+50
-20
No files matched your search
+23
-8
@@ -93,6 +93,7 @@ static Pixmap back;
|
||||
static int screen;
|
||||
static int winW = 240, winH = 296; // overridden at runtime from the actual screen
|
||||
static unsigned long C_BG, C_FG, C_HEAD, C_FOOD, C_DIM;
|
||||
static unsigned long C_GB_DARK, C_GB_MED, C_GB_LIGHT, C_GB_PALE;
|
||||
|
||||
// ---- tetromino definitions (state 0 within a 4x4 box) ----
|
||||
// type 0..6 -> I,O,T,S,Z,J,L
|
||||
@@ -263,6 +264,19 @@ static void draw_text(int x, int y, int scale, unsigned long col, const char* s)
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a Gameboy-style beveled cell: medium body, pale top/left highlight,
|
||||
// dark bottom/right shadow. bodycol is the fill shade (settled vs active).
|
||||
static void draw_gb_cell(int x, int y, int size, unsigned long bodycol) {
|
||||
XSetForeground(dpy, gc, bodycol);
|
||||
XFillRectangle(dpy, back, gc, x + 1, y + 1, size - 2, size - 2);
|
||||
XSetForeground(dpy, gc, C_GB_PALE);
|
||||
XFillRectangle(dpy, back, gc, x + 1, y, size - 2, 1);
|
||||
XFillRectangle(dpy, back, gc, x, y + 1, 1, size - 2);
|
||||
XSetForeground(dpy, gc, C_GB_DARK);
|
||||
XFillRectangle(dpy, back, gc, x + 1, y + size - 1, size - 2, 1);
|
||||
XFillRectangle(dpy, back, gc, x + size - 1, y + 1, 1, size - 2);
|
||||
}
|
||||
|
||||
static void render() {
|
||||
int px0 = 8, py0 = 8;
|
||||
XSetForeground(dpy, gc, C_BG);
|
||||
@@ -275,21 +289,18 @@ static void render() {
|
||||
// settled blocks
|
||||
for (int x = 0; x < PCOLS; x++)
|
||||
for (int y = 0; y < PROWS; y++)
|
||||
if (board[x][y]) {
|
||||
XSetForeground(dpy, gc, C_FG);
|
||||
XFillRectangle(dpy, back, gc, px0 + x * CELL, py0 + y * CELL, CELL, CELL);
|
||||
}
|
||||
if (board[x][y])
|
||||
draw_gb_cell(px0 + x * CELL, py0 + y * CELL, CELL, C_GB_MED);
|
||||
|
||||
// active piece
|
||||
if (state == PLAYING) {
|
||||
int cells[4][2];
|
||||
piece_cells(curType, curRot, cells);
|
||||
XSetForeground(dpy, gc, C_HEAD);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int cx = curX + cells[i][0];
|
||||
int cy = curY + cells[i][1];
|
||||
if (cy >= 0)
|
||||
XFillRectangle(dpy, back, gc, px0 + cx * CELL, py0 + cy * CELL, CELL, CELL);
|
||||
draw_gb_cell(px0 + cx * CELL, py0 + cy * CELL, CELL, C_GB_LIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,11 +331,10 @@ static void render() {
|
||||
int prows = maxy - miny + 1;
|
||||
int nx0 = sx + ((winW - sx - 4) - pcols * pcell) / 2;
|
||||
int ny0 = boxY + (boxH - prows * pcell) / 2 + 12; // sit lower in the frame
|
||||
XSetForeground(dpy, gc, C_HEAD);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int cx = nx0 + (nc[i][0] - minx) * pcell;
|
||||
int cy = ny0 + (nc[i][1] - miny) * pcell;
|
||||
XFillRectangle(dpy, back, gc, cx, cy, pcell, pcell);
|
||||
draw_gb_cell(cx, cy, pcell, C_HEAD);
|
||||
}
|
||||
int ty = boxY + boxH + 6;
|
||||
char buf[32];
|
||||
@@ -402,6 +412,11 @@ static void setup_window() {
|
||||
C_HEAD = 0x99ff99;
|
||||
C_FOOD = 0x66ff66;
|
||||
C_DIM = 0x2f9f2f;
|
||||
// Gameboy-style four-shade green palette
|
||||
C_GB_DARK = 0x1f7f1f; // bottom/right shadow
|
||||
C_GB_MED = 0x3faf3f; // settled block body
|
||||
C_GB_LIGHT = 0x7fdf7f; // active piece body
|
||||
C_GB_PALE = 0xbfffbf; // top/left highlight
|
||||
|
||||
XSelectInput(dpy, win, KeyPressMask | StructureNotifyMask | ExposureMask);
|
||||
XMapWindow(dpy, win);
|
||||
|
||||
Reference in new issue
Block a user