tetris.h

Go to the documentation of this file.
00001 /*      $OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert Exp $      */
00002 /*      $NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd Exp $   */
00003 
00004 /*-
00005  * Copyright (c) 1992, 1993
00006  *      The Regents of the University of California.  All rights reserved.
00007  *
00008  * This code is derived from software contributed to Berkeley by
00009  * Chris Torek and Darren F. Provine.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in the
00018  *    documentation and/or other materials provided with the distribution.
00019  * 3. Neither the name of the University nor the names of its contributors
00020  *    may be used to endorse or promote products derived from this software
00021  *    without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00024  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00029  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00032  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  *      @(#)tetris.h    8.1 (Berkeley) 5/31/93
00036  */
00037 
00044 /*
00045  * Definitions for Tetris.
00046  */
00047 
00048 /*
00049  * The display (`board') is composed of 23 rows of 12 columns of characters
00050  * (numbered 0..22 and 0..11), stored in a single array for convenience.
00051  * Columns 1 to 10 of rows 1 to 20 are the actual playing area, where
00052  * shapes appear.  Columns 0 and 11 are always occupied, as are all
00053  * columns of rows 21 and 22.  Rows 0 and 22 exist as boundary areas
00054  * so that regions `outside' the visible area can be examined without
00055  * worrying about addressing problems.
00056  */
00057 
00058 /* The board */
00059 #define B_COLS  12
00060 #define B_ROWS  23
00061 #define B_SIZE  (B_ROWS * B_COLS)
00062 
00063 typedef uint32_t cell;
00064 
00065 extern cell board[B_SIZE];  /* 1 => occupied, 0 => empty */
00066 
00067 /* The displayed area (rows) */
00068 #define D_FIRST  1
00069 #define D_LAST   22
00070 
00071 /* The active area (rows) */
00072 #define A_FIRST  1
00073 #define A_LAST   21
00074 
00075 /*
00076  * Minimum display size.
00077  */
00078 #define MINROWS  23
00079 #define MINCOLS  40
00080 
00081 /* Current screen size */
00082 extern int Rows;
00083 extern int Cols;
00084 
00085 /*
00086  * Translations from board coordinates to display coordinates.
00087  * As with board coordinates, display coordiates are zero origin.
00088  */
00089 #define RTOD(x)  ((x) - 1)
00090 #define CTOD(x)  ((x) * 2 + (((Cols - 2 * B_COLS) >> 1) - 1))
00091 
00092 /*
00093  * A `shape' is the fundamental thing that makes up the game.  There
00094  * are 7 basic shapes, each consisting of four `blots':
00095  *
00096  *      X.X       X.X           X.X
00097  *        X.X   X.X     X.X.X   X.X     X.X.X   X.X.X   X.X.X.X
00098  *                        X             X           X
00099  *
00100  *          0     1       2       3       4       5       6
00101  *
00102  * Except for 3 and 6, the center of each shape is one of the blots.
00103  * This blot is designated (0, 0).  The other three blots can then be
00104  * described as offsets from the center.  Shape 3 is the same under
00105  * rotation, so its center is effectively irrelevant; it has been chosen
00106  * so that it `sticks out' upward and leftward.  Except for shape 6,
00107  * all the blots are contained in a box going from (-1, -1) to (+1, +1);
00108  * shape 6's center `wobbles' as it rotates, so that while it `sticks out'
00109  * rightward, its rotation---a vertical line---`sticks out' downward.
00110  * The containment box has to include the offset (2, 0), making the overall
00111  * containment box range from offset (-1, -1) to (+2, +1).  (This is why
00112  * there is only one row above, but two rows below, the display area.)
00113  *
00114  * The game works by choosing one of these shapes at random and putting
00115  * its center at the middle of the first display row (row 1, column 5).
00116  * The shape is moved steadily downward until it collides with something:
00117  * either  another shape, or the bottom of the board.  When the shape can
00118  * no longer be moved downwards, it is merged into the current board.
00119  * At this time, any completely filled rows are elided, and blots above
00120  * these rows move down to make more room.  A new random shape is again
00121  * introduced at the top of the board, and the whole process repeats.
00122  * The game ends when the new shape will not fit at (1, 5).
00123  *
00124  * While the shapes are falling, the user can rotate them counterclockwise
00125  * 90 degrees (in addition to moving them left or right), provided that the
00126  * rotation puts the blots in empty spaces.  The table of shapes is set up
00127  * so that each shape contains the index of the new shape obtained by
00128  * rotating the current shape.  Due to symmetry, each shape has exactly
00129  * 1, 2, or 4 rotations total; the first 7 entries in the table represent
00130  * the primary shapes, and the remaining 12 represent their various
00131  * rotated forms.
00132  */
00133 struct shape {
00134         int rot;     /* index of rotated version of this shape */
00135         int rotc;    /* -- " -- in classic version  */
00136         int off[3];  /* offsets to other blots if center is at (0,0) */
00137         uint32_t color;
00138 };
00139 
00140 extern const struct shape shapes[];
00141 
00142 extern const struct shape *curshape;
00143 extern const struct shape *nextshape;
00144 
00145 /*
00146  * Shapes fall at a rate faster than once per second.
00147  *
00148  * The initial rate is determined by dividing 1 million microseconds
00149  * by the game `level'.  (This is at most 1 million, or one second.)
00150  * Each time the fall-rate is used, it is decreased a little bit,
00151  * depending on its current value, via the `faster' macro below.
00152  * The value eventually reaches a limit, and things stop going faster,
00153  * but by then the game is utterly impossible.
00154  */
00155 extern long fallrate;  /* less than 1 million; smaller => faster */
00156 
00157 #define faster()  (fallrate -= fallrate / 3000)
00158 
00159 /*
00160  * Game level must be between 1 and 9.  This controls the initial fall rate
00161  * and affects scoring.
00162  */
00163 #define MINLEVEL  1
00164 #define MAXLEVEL  9
00165 
00166 /*
00167  * Scoring is as follows:
00168  *
00169  * When the shape comes to rest, and is integrated into the board,
00170  * we score one point.  If the shape is high up (at a low-numbered row),
00171  * and the user hits the space bar, the shape plummets all the way down,
00172  * and we score a point for each row it falls (plus one more as soon as
00173  * we find that it is at rest and integrate it---until then, it can
00174  * still be moved or rotated).
00175  *
00176  * If previewing has been turned on, the score is multiplied by PRE_PENALTY.
00177  */
00178 #define PRE_PENALTY  0.75
00179 
00180 extern int score;  /* The obvious thing */
00181 
00182 extern char key_msg[100];
00183 extern int showpreview;
00184 extern int classic;
00185 
00186 extern int fits_in(const struct shape *, int);
00187 extern void place(const struct shape *, int, int);
00188 extern void stop(const char *);
00189 

Generated on Thu Jun 2 07:45:43 2011 for HelenOS/USB by  doxygen 1.4.7