xref: /csrg-svn/games/tetris/shapes.c (revision 57275)
1*57275Sbostic /*-
2*57275Sbostic  * Copyright (c) 1992 The Regents of the University of California.
3*57275Sbostic  * All rights reserved.
4*57275Sbostic  *
5*57275Sbostic  * %sccs.include.redist.c%
6*57275Sbostic  *
7*57275Sbostic  *	@(#)shapes.c	5.1 (Berkeley) 12/22/92
8*57275Sbostic  */
9*57275Sbostic 
10*57275Sbostic /*
11*57275Sbostic  * Tetris shapes and related routines.
12*57275Sbostic  *
13*57275Sbostic  * Note that the first 7 are `well known'.
14*57275Sbostic  */
15*57275Sbostic 
16*57275Sbostic #include <sys/cdefs.h>
17*57275Sbostic #include "tetris.h"
18*57275Sbostic 
19*57275Sbostic #define	TL	-B_COLS-1	/* top left */
20*57275Sbostic #define	TC	-B_COLS		/* top center */
21*57275Sbostic #define	TR	-B_COLS+1	/* top right */
22*57275Sbostic #define	ML	-1		/* middle left */
23*57275Sbostic #define	MR	1		/* middle right */
24*57275Sbostic #define	BL	B_COLS-1	/* bottom left */
25*57275Sbostic #define	BC	B_COLS		/* bottom center */
26*57275Sbostic #define	BR	B_COLS+1	/* bottom right */
27*57275Sbostic 
28*57275Sbostic struct shape shapes[] = {
29*57275Sbostic 	/* 0*/	7,	TL, TC, MR,
30*57275Sbostic 	/* 1*/	8,	TC, TR, ML,
31*57275Sbostic 	/* 2*/	9,	ML, MR, BC,
32*57275Sbostic 	/* 3*/	3,	TL, TC, ML,
33*57275Sbostic 	/* 4*/	12,	ML, BL, MR,
34*57275Sbostic 	/* 5*/	15,	ML, BR, MR,
35*57275Sbostic 	/* 6*/	18,	ML, MR, /* sticks out */ 2,
36*57275Sbostic 	/* 7*/	0,	TC, ML, BL,
37*57275Sbostic 	/* 8*/	1,	TC, MR, BR,
38*57275Sbostic 	/* 9*/	10,	TC, MR, BC,
39*57275Sbostic 	/*10*/	11,	TC, ML, MR,
40*57275Sbostic 	/*11*/	2,	TC, ML, BC,
41*57275Sbostic 	/*12*/	13,	TC, BC, BR,
42*57275Sbostic 	/*13*/	14,	TR, ML, MR,
43*57275Sbostic 	/*14*/	4,	TL, TC, BC,
44*57275Sbostic 	/*15*/	16,	TR, TC, BC,
45*57275Sbostic 	/*16*/	17,	TL, MR, ML,
46*57275Sbostic 	/*17*/	5,	TC, BC, BL,
47*57275Sbostic 	/*18*/	6,	TC, BC, /* sticks out */ 2*B_COLS,
48*57275Sbostic };
49*57275Sbostic 
50*57275Sbostic /*
51*57275Sbostic  * Return true iff the given shape fits in the given position,
52*57275Sbostic  * taking the current board into account.
53*57275Sbostic  */
54*57275Sbostic int
55*57275Sbostic fits_in(shape, pos)
56*57275Sbostic 	struct shape *shape;
57*57275Sbostic 	register int pos;
58*57275Sbostic {
59*57275Sbostic 	register int *o = shape->off;
60*57275Sbostic 
61*57275Sbostic 	if (board[pos] || board[pos + *o++] || board[pos + *o++] ||
62*57275Sbostic 	    board[pos + *o])
63*57275Sbostic 		return 0;
64*57275Sbostic 	return 1;
65*57275Sbostic }
66*57275Sbostic 
67*57275Sbostic /*
68*57275Sbostic  * Write the given shape into the current board, turning it on
69*57275Sbostic  * if `onoff' is 1, and off if `onoff' is 0.
70*57275Sbostic  */
71*57275Sbostic void
72*57275Sbostic place(shape, pos, onoff)
73*57275Sbostic 	struct shape *shape;
74*57275Sbostic 	register int pos, onoff;
75*57275Sbostic {
76*57275Sbostic 	register int *o = shape->off;
77*57275Sbostic 
78*57275Sbostic 	board[pos] = onoff;
79*57275Sbostic 	board[pos + *o++] = onoff;
80*57275Sbostic 	board[pos + *o++] = onoff;
81*57275Sbostic 	board[pos + *o] = onoff;
82*57275Sbostic }
83