tetris: add vertical separator between playfield and side panel; enlarge next-piece preview
Draw a bright vertical divider in the gap between the playfield and the side panel so the two areas are clearly separated, and render the NEXT piece larger (pcell 6 -> 11) centered inside a framed preview box.
This commit is contained in:
Binary file not shown.
Binary file not shown.
+18
-5
@@ -279,27 +279,40 @@ static void render() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vertical separator line between the playfield and the side panel
|
||||||
|
int sepX = px0 + PCOLS * CELL + 6;
|
||||||
|
XSetForeground(dpy, gc, C_FG);
|
||||||
|
XDrawLine(dpy, back, gc, sepX, py0, sepX, py0 + PROWS * CELL);
|
||||||
|
|
||||||
// side panel
|
// side panel
|
||||||
int sx = px0 + PCOLS * CELL + 12;
|
int sx = px0 + PCOLS * CELL + 12;
|
||||||
draw_text(sx, py0, 1, C_DIM, "NEXT");
|
draw_text(sx, py0, 1, C_DIM, "NEXT");
|
||||||
|
// framed preview box for the next piece
|
||||||
|
int boxY = py0 + 10;
|
||||||
|
int boxH = 48;
|
||||||
|
XSetForeground(dpy, gc, C_DIM);
|
||||||
|
XDrawRectangle(dpy, back, gc, sx, boxY, winW - sx - 4, boxH);
|
||||||
int nc[4][2];
|
int nc[4][2];
|
||||||
piece_cells(nextType, 0, nc);
|
piece_cells(nextType, 0, nc);
|
||||||
int minx = 4, miny = 4, maxx = -1, maxy = -1;
|
int minx = 4, miny = 4, maxx = -1, maxy = -1;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
minx = nc[i][0] < minx ? nc[i][0] : minx;
|
minx = nc[i][0] < minx ? nc[i][0] : minx;
|
||||||
miny = nc[i][1] < miny ? nc[i][1] : miny;
|
miny = nc[i][1] < miny ? miny : miny;
|
||||||
maxx = nc[i][0] > maxx ? nc[i][0] : maxx;
|
maxx = nc[i][0] > maxx ? nc[i][0] : maxx;
|
||||||
maxy = nc[i][1] > maxy ? nc[i][1] : maxy;
|
maxy = nc[i][1] > maxy ? maxy : maxy;
|
||||||
}
|
}
|
||||||
int pcell = 6;
|
int pcell = 11; // larger next-piece preview
|
||||||
int nx0 = sx + 2, ny0 = py0 + 10;
|
int pcols = maxx - minx + 1;
|
||||||
|
int prows = maxy - miny + 1;
|
||||||
|
int nx0 = sx + ((winW - sx - 4) - pcols * pcell) / 2;
|
||||||
|
int ny0 = boxY + (boxH - prows * pcell) / 2;
|
||||||
XSetForeground(dpy, gc, C_HEAD);
|
XSetForeground(dpy, gc, C_HEAD);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
int cx = nx0 + (nc[i][0] - minx) * pcell;
|
int cx = nx0 + (nc[i][0] - minx) * pcell;
|
||||||
int cy = ny0 + (nc[i][1] - miny) * pcell;
|
int cy = ny0 + (nc[i][1] - miny) * pcell;
|
||||||
XFillRectangle(dpy, back, gc, cx, cy, pcell, pcell);
|
XFillRectangle(dpy, back, gc, cx, cy, pcell, pcell);
|
||||||
}
|
}
|
||||||
int ty = py0 + 60;
|
int ty = boxY + boxH + 6;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
snprintf(buf, sizeof(buf), "SCORE %d", score); draw_text(sx, ty, 1, C_DIM, buf);
|
snprintf(buf, sizeof(buf), "SCORE %d", score); draw_text(sx, ty, 1, C_DIM, buf);
|
||||||
snprintf(buf, sizeof(buf), "LINES %d", lines); draw_text(sx, ty + 9, 1, C_DIM, buf);
|
snprintf(buf, sizeof(buf), "LINES %d", lines); draw_text(sx, ty + 9, 1, C_DIM, buf);
|
||||||
|
|||||||
Reference in New Issue
Block a user