summaryrefslogtreecommitdiffstats
path: root/tetris
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2014-06-11 16:47:39 +0000
committerchristos <christos@NetBSD.org>2014-06-11 16:47:39 +0000
commit1033fba35c308f3253abd40f163d7c52ef7ac5fb (patch)
tree7188b5503b94cde1c8280e6c0336559d7a778bea /tetris
parentdb7a726b9bff1bdf1fbba8c65d338e1236f854bb (diff)
downloadbsdgames-darwin-1033fba35c308f3253abd40f163d7c52ef7ac5fb.tar.gz
bsdgames-darwin-1033fba35c308f3253abd40f163d7c52ef7ac5fb.tar.zst
bsdgames-darwin-1033fba35c308f3253abd40f163d7c52ef7ac5fb.zip
Add a little color. In order to minimize logic differences, keep 0 as the
empty board value, and since 7 is white, turn white into black (0) when painting.
Diffstat (limited to 'tetris')
-rw-r--r--tetris/screen.c22
-rw-r--r--tetris/shapes.c41
-rw-r--r--tetris/tetris.c4
-rw-r--r--tetris/tetris.h3
4 files changed, 46 insertions, 24 deletions
diff --git a/tetris/screen.c b/tetris/screen.c
index 2d58303b..50a019d3 100644
--- a/tetris/screen.c
+++ b/tetris/screen.c
@@ -1,4 +1,4 @@
-/* $NetBSD: screen.c,v 1.27 2011/10/03 12:32:28 roy Exp $ */
+/* $NetBSD: screen.c,v 1.28 2014/06/11 16:47:39 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -94,6 +94,18 @@ moveto(int r, int c)
putpad(buf);
}
+static void
+setcolor(int c)
+{
+ char *buf;
+ if (set_a_foreground == NULL)
+ return;
+
+ buf = tiparm(set_a_foreground, c == 7 ? 0 : c);
+ if (buf != NULL)
+ putpad(buf);
+}
+
/*
* Set up from termcap.
*/
@@ -312,6 +324,7 @@ scr_update(void)
/* draw */
putpad(enter_standout_mode);
+ setcolor(nextshape->color);
moveto(r, 2*c);
putstr(" ");
for(i=0; i<3; i++) {
@@ -349,7 +362,14 @@ scr_update(void)
exit_standout_mode);
cur_so = so;
}
+ setcolor(so);
+#ifdef DEBUG
+ char buf[3];
+ snprintf(buf, sizeof(buf), "%d%d", so, so);
+ putstr(buf);
+#else
putstr(" ");
+#endif
} else
putstr(so ? "XX" : " ");
ccol = i + 1;
diff --git a/tetris/shapes.c b/tetris/shapes.c
index 0ab43106..ef82771c 100644
--- a/tetris/shapes.c
+++ b/tetris/shapes.c
@@ -1,4 +1,4 @@
-/* $NetBSD: shapes.c,v 1.8 2009/05/25 04:33:53 dholland Exp $ */
+/* $NetBSD: shapes.c,v 1.9 2014/06/11 16:47:39 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -53,25 +53,25 @@
#define BR B_COLS+1 /* bottom right */
const struct shape shapes[] = {
- /* 0*/ { 7, { TL, TC, MR, } },
- /* 1*/ { 8, { TC, TR, ML, } },
- /* 2*/ { 9, { ML, MR, BC, } },
- /* 3*/ { 3, { TL, TC, ML, } },
- /* 4*/ { 12, { ML, BL, MR, } },
- /* 5*/ { 15, { ML, BR, MR, } },
- /* 6*/ { 18, { ML, MR, 2 } }, /* sticks out */
- /* 7*/ { 0, { TC, ML, BL, } },
- /* 8*/ { 1, { TC, MR, BR, } },
- /* 9*/ { 10, { TC, MR, BC, } },
- /*10*/ { 11, { TC, ML, MR, } },
- /*11*/ { 2, { TC, ML, BC, } },
- /*12*/ { 13, { TC, BC, BR, } },
- /*13*/ { 14, { TR, ML, MR, } },
- /*14*/ { 4, { TL, TC, BC, } },
- /*15*/ { 16, { TR, TC, BC, } },
- /*16*/ { 17, { TL, MR, ML, } },
- /*17*/ { 5, { TC, BC, BL, } },
- /*18*/ { 6, { TC, BC, 2*B_COLS } } /* sticks out */
+ /* 0*/ { 7, 7, { TL, TC, MR, } },
+ /* 1*/ { 1, 8, { TC, TR, ML, } },
+ /* 2*/ { 2, 9, { ML, MR, BC, } },
+ /* 3*/ { 3, 3, { TL, TC, ML, } },
+ /* 4*/ { 4, 12, { ML, BL, MR, } },
+ /* 5*/ { 5, 15, { ML, BR, MR, } },
+ /* 6*/ { 6, 18, { ML, MR, 2 } }, /* sticks out */
+ /* 7*/ { 7, 0, { TC, ML, BL, } },
+ /* 8*/ { 1, 1, { TC, MR, BR, } },
+ /* 9*/ { 2, 10, { TC, MR, BC, } },
+ /*10*/ { 2, 11, { TC, ML, MR, } },
+ /*11*/ { 2, 2, { TC, ML, BC, } },
+ /*12*/ { 4, 13, { TC, BC, BR, } },
+ /*13*/ { 4, 14, { TR, ML, MR, } },
+ /*14*/ { 4, 4, { TL, TC, BC, } },
+ /*15*/ { 5, 16, { TR, TC, BC, } },
+ /*16*/ { 5, 17, { TL, MR, ML, } },
+ /*17*/ { 5, 5, { TC, BC, BL, } },
+ /*18*/ { 6, 6, { TC, BC, 2*B_COLS } } /* sticks out */
};
/*
@@ -97,6 +97,7 @@ void
place(const struct shape *shape, int pos, int onoff)
{
const int *o = shape->off;
+ onoff = onoff ? shape->color : 0;
board[pos] = onoff;
board[pos + *o++] = onoff;
diff --git a/tetris/tetris.c b/tetris/tetris.c
index 4943249a..9ccaa2f4 100644
--- a/tetris/tetris.c
+++ b/tetris/tetris.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tetris.c,v 1.24 2011/08/31 16:24:56 plunky Exp $ */
+/* $NetBSD: tetris.c,v 1.25 2014/06/11 16:47:39 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -92,7 +92,7 @@ setup_board(void)
p = board;
for (i = B_SIZE; i; i--)
- *p++ = i <= (2 * B_COLS) || (i % B_COLS) < 2;
+ *p++ = (i <= (2 * B_COLS) || (i % B_COLS) < 2) ? 7 : 0;
}
/*
diff --git a/tetris/tetris.h b/tetris/tetris.h
index 37f0d9ba..4f2fbccd 100644
--- a/tetris/tetris.h
+++ b/tetris/tetris.h
@@ -1,4 +1,4 @@
-/* $NetBSD: tetris.h,v 1.12 2009/08/12 08:51:21 dholland Exp $ */
+/* $NetBSD: tetris.h,v 1.13 2014/06/11 16:47:39 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -123,6 +123,7 @@ extern int Rows, Cols; /* current screen size */
* rotated forms.
*/
struct shape {
+ int color;
int rot; /* index of rotated version of this shape */
int off[3]; /* offsets to other blots if center is at (0,0) */
};