Rev 3386 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3386 | Rev 4581 | ||
---|---|---|---|
1 | /* $OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert Exp $ */ |
1 | /* $OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert Exp $ */ |
2 | /* $NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd Exp $ */ |
2 | /* $NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd Exp $ */ |
3 | 3 | ||
4 | /*- |
4 | /*- |
5 | * Copyright (c) 1992, 1993 |
5 | * Copyright (c) 1992, 1993 |
6 | * The Regents of the University of California. All rights reserved. |
6 | * The Regents of the University of California. All rights reserved. |
7 | * |
7 | * |
8 | * This code is derived from software contributed to Berkeley by |
8 | * This code is derived from software contributed to Berkeley by |
9 | * Chris Torek and Darren F. Provine. |
9 | * Chris Torek and Darren F. Provine. |
10 | * |
10 | * |
11 | * Redistribution and use in source and binary forms, with or without |
11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions |
12 | * modification, are permitted provided that the following conditions |
13 | * are met: |
13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright |
14 | * 1. Redistributions of source code must retain the above copyright |
15 | * notice, this list of conditions and the following disclaimer. |
15 | * notice, this list of conditions and the following disclaimer. |
16 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * 2. Redistributions in binary form must reproduce the above copyright |
17 | * notice, this list of conditions and the following disclaimer in the |
17 | * notice, this list of conditions and the following disclaimer in the |
18 | * documentation and/or other materials provided with the distribution. |
18 | * documentation and/or other materials provided with the distribution. |
19 | * 3. Neither the name of the University nor the names of its contributors |
19 | * 3. Neither the name of the University nor the names of its contributors |
20 | * may be used to endorse or promote products derived from this software |
20 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. |
21 | * without specific prior written permission. |
22 | * |
22 | * |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
33 | * SUCH DAMAGE. |
33 | * SUCH DAMAGE. |
34 | * |
34 | * |
35 | * @(#)tetris.h 8.1 (Berkeley) 5/31/93 |
35 | * @(#)tetris.h 8.1 (Berkeley) 5/31/93 |
36 | */ |
36 | */ |
37 | 37 | ||
38 | /** @addtogroup tetris |
38 | /** @addtogroup tetris |
39 | * @{ |
39 | * @{ |
40 | */ |
40 | */ |
41 | /** @file |
41 | /** @file |
42 | */ |
42 | */ |
43 | 43 | ||
44 | /* |
44 | /* |
45 | * Definitions for Tetris. |
45 | * Definitions for Tetris. |
46 | */ |
46 | */ |
47 | 47 | ||
48 | /* |
48 | /* |
49 | * The display (`board') is composed of 23 rows of 12 columns of characters |
49 | * The display (`board') is composed of 23 rows of 12 columns of characters |
50 | * (numbered 0..22 and 0..11), stored in a single array for convenience. |
50 | * (numbered 0..22 and 0..11), stored in a single array for convenience. |
51 | * Columns 1 to 10 of rows 1 to 20 are the actual playing area, where |
51 | * Columns 1 to 10 of rows 1 to 20 are the actual playing area, where |
52 | * shapes appear. Columns 0 and 11 are always occupied, as are all |
52 | * shapes appear. Columns 0 and 11 are always occupied, as are all |
53 | * columns of rows 21 and 22. Rows 0 and 22 exist as boundary areas |
53 | * columns of rows 21 and 22. Rows 0 and 22 exist as boundary areas |
54 | * so that regions `outside' the visible area can be examined without |
54 | * so that regions `outside' the visible area can be examined without |
55 | * worrying about addressing problems. |
55 | * worrying about addressing problems. |
56 | */ |
56 | */ |
57 | 57 | ||
58 | /* the board */ |
58 | /* The board */ |
59 | #define B_COLS 12 |
59 | #define B_COLS 12 |
60 | #define B_ROWS 23 |
60 | #define B_ROWS 23 |
61 | #define B_SIZE (B_ROWS * B_COLS) |
61 | #define B_SIZE (B_ROWS * B_COLS) |
62 | 62 | ||
63 | typedef unsigned char cell; |
63 | typedef uint32_t cell; |
- | 64 | ||
64 | extern cell board[B_SIZE]; /* 1 => occupied, 0 => empty */ |
65 | extern cell board[B_SIZE]; /* 1 => occupied, 0 => empty */ |
65 | 66 | ||
66 | /* the displayed area (rows) */ |
67 | /* The displayed area (rows) */ |
67 | #define D_FIRST 1 |
68 | #define D_FIRST 1 |
68 | #define D_LAST 22 |
69 | #define D_LAST 22 |
69 | 70 | ||
70 | /* the active area (rows) */ |
71 | /* The active area (rows) */ |
71 | #define A_FIRST 1 |
72 | #define A_FIRST 1 |
72 | #define A_LAST 21 |
73 | #define A_LAST 21 |
73 | 74 | ||
74 | /* |
75 | /* |
75 | * Minimum display size. |
76 | * Minimum display size. |
76 | */ |
77 | */ |
77 | #define MINROWS 23 |
78 | #define MINROWS 23 |
78 | #define MINCOLS 40 |
79 | #define MINCOLS 40 |
79 | 80 | ||
80 | extern int Rows, Cols; /* current screen size */ |
81 | /* Current screen size */ |
- | 82 | extern int Rows; |
|
- | 83 | extern int Cols; |
|
81 | 84 | ||
82 | /* |
85 | /* |
83 | * Translations from board coordinates to display coordinates. |
86 | * Translations from board coordinates to display coordinates. |
84 | * As with board coordinates, display coordiates are zero origin. |
87 | * As with board coordinates, display coordiates are zero origin. |
85 | */ |
88 | */ |
86 | #define RTOD(x) ((x) - 1) |
89 | #define RTOD(x) ((x) - 1) |
87 | #define CTOD(x) ((x) * 2 + (((Cols - 2 * B_COLS) >> 1) - 1)) |
90 | #define CTOD(x) ((x) * 2 + (((Cols - 2 * B_COLS) >> 1) - 1)) |
88 | 91 | ||
89 | /* |
92 | /* |
90 | * A `shape' is the fundamental thing that makes up the game. There |
93 | * A `shape' is the fundamental thing that makes up the game. There |
91 | * are 7 basic shapes, each consisting of four `blots': |
94 | * are 7 basic shapes, each consisting of four `blots': |
92 | * |
95 | * |
93 | * X.X X.X X.X |
96 | * X.X X.X X.X |
94 | * X.X X.X X.X.X X.X X.X.X X.X.X X.X.X.X |
97 | * X.X X.X X.X.X X.X X.X.X X.X.X X.X.X.X |
95 | * X X X |
98 | * X X X |
96 | * |
99 | * |
97 | * 0 1 2 3 4 5 6 |
100 | * 0 1 2 3 4 5 6 |
98 | * |
101 | * |
99 | * Except for 3 and 6, the center of each shape is one of the blots. |
102 | * Except for 3 and 6, the center of each shape is one of the blots. |
100 | * This blot is designated (0,0). The other three blots can then be |
103 | * This blot is designated (0, 0). The other three blots can then be |
101 | * described as offsets from the center. Shape 3 is the same under |
104 | * described as offsets from the center. Shape 3 is the same under |
102 | * rotation, so its center is effectively irrelevant; it has been chosen |
105 | * rotation, so its center is effectively irrelevant; it has been chosen |
103 | * so that it `sticks out' upward and leftward. Except for shape 6, |
106 | * so that it `sticks out' upward and leftward. Except for shape 6, |
104 | * all the blots are contained in a box going from (-1,-1) to (+1,+1); |
107 | * all the blots are contained in a box going from (-1, -1) to (+1, +1); |
105 | * shape 6's center `wobbles' as it rotates, so that while it `sticks out' |
108 | * shape 6's center `wobbles' as it rotates, so that while it `sticks out' |
106 | * rightward, its rotation---a vertical line---`sticks out' downward. |
109 | * rightward, its rotation---a vertical line---`sticks out' downward. |
107 | * The containment box has to include the offset (2,0), making the overall |
110 | * The containment box has to include the offset (2, 0), making the overall |
108 | * containment box range from offset (-1,-1) to (+2,+1). (This is why |
111 | * containment box range from offset (-1, -1) to (+2, +1). (This is why |
109 | * there is only one row above, but two rows below, the display area.) |
112 | * there is only one row above, but two rows below, the display area.) |
110 | * |
113 | * |
111 | * The game works by choosing one of these shapes at random and putting |
114 | * The game works by choosing one of these shapes at random and putting |
112 | * its center at the middle of the first display row (row 1, column 5). |
115 | * its center at the middle of the first display row (row 1, column 5). |
113 | * The shape is moved steadily downward until it collides with something: |
116 | * The shape is moved steadily downward until it collides with something: |
114 | * either another shape, or the bottom of the board. When the shape can |
117 | * either another shape, or the bottom of the board. When the shape can |
115 | * no longer be moved downwards, it is merged into the current board. |
118 | * no longer be moved downwards, it is merged into the current board. |
116 | * At this time, any completely filled rows are elided, and blots above |
119 | * At this time, any completely filled rows are elided, and blots above |
117 | * these rows move down to make more room. A new random shape is again |
120 | * these rows move down to make more room. A new random shape is again |
118 | * introduced at the top of the board, and the whole process repeats. |
121 | * introduced at the top of the board, and the whole process repeats. |
119 | * The game ends when the new shape will not fit at (1,5). |
122 | * The game ends when the new shape will not fit at (1, 5). |
120 | * |
123 | * |
121 | * While the shapes are falling, the user can rotate them counterclockwise |
124 | * While the shapes are falling, the user can rotate them counterclockwise |
122 | * 90 degrees (in addition to moving them left or right), provided that the |
125 | * 90 degrees (in addition to moving them left or right), provided that the |
123 | * rotation puts the blots in empty spaces. The table of shapes is set up |
126 | * rotation puts the blots in empty spaces. The table of shapes is set up |
124 | * so that each shape contains the index of the new shape obtained by |
127 | * so that each shape contains the index of the new shape obtained by |
125 | * rotating the current shape. Due to symmetry, each shape has exactly |
128 | * rotating the current shape. Due to symmetry, each shape has exactly |
126 | * 1, 2, or 4 rotations total; the first 7 entries in the table represent |
129 | * 1, 2, or 4 rotations total; the first 7 entries in the table represent |
127 | * the primary shapes, and the remaining 12 represent their various |
130 | * the primary shapes, and the remaining 12 represent their various |
128 | * rotated forms. |
131 | * rotated forms. |
129 | */ |
132 | */ |
130 | struct shape { |
133 | struct shape { |
131 | int rot; /* index of rotated version of this shape */ |
134 | int rot; /* index of rotated version of this shape */ |
132 | int rotc; /* -- " -- in classic version */ |
135 | int rotc; /* -- " -- in classic version */ |
133 | int off[3]; /* offsets to other blots if center is at (0,0) */ |
136 | int off[3]; /* offsets to other blots if center is at (0,0) */ |
- | 137 | uint32_t color; |
|
134 | }; |
138 | }; |
135 | 139 | ||
136 | extern const struct shape shapes[]; |
140 | extern const struct shape shapes[]; |
137 | 141 | ||
138 | extern const struct shape *curshape; |
142 | extern const struct shape *curshape; |
139 | extern const struct shape *nextshape; |
143 | extern const struct shape *nextshape; |
140 | 144 | ||
141 | /* |
145 | /* |
142 | * Shapes fall at a rate faster than once per second. |
146 | * Shapes fall at a rate faster than once per second. |
143 | * |
147 | * |
144 | * The initial rate is determined by dividing 1 million microseconds |
148 | * The initial rate is determined by dividing 1 million microseconds |
145 | * by the game `level'. (This is at most 1 million, or one second.) |
149 | * by the game `level'. (This is at most 1 million, or one second.) |
146 | * Each time the fall-rate is used, it is decreased a little bit, |
150 | * Each time the fall-rate is used, it is decreased a little bit, |
147 | * depending on its current value, via the `faster' macro below. |
151 | * depending on its current value, via the `faster' macro below. |
148 | * The value eventually reaches a limit, and things stop going faster, |
152 | * The value eventually reaches a limit, and things stop going faster, |
149 | * but by then the game is utterly impossible. |
153 | * but by then the game is utterly impossible. |
150 | */ |
154 | */ |
151 | extern long fallrate; /* less than 1 million; smaller => faster */ |
155 | extern long fallrate; /* less than 1 million; smaller => faster */ |
- | 156 | ||
152 | #define faster() (fallrate -= fallrate / 3000) |
157 | #define faster() (fallrate -= fallrate / 3000) |
153 | 158 | ||
154 | /* |
159 | /* |
155 | * Game level must be between 1 and 9. This controls the initial fall rate |
160 | * Game level must be between 1 and 9. This controls the initial fall rate |
156 | * and affects scoring. |
161 | * and affects scoring. |
157 | */ |
162 | */ |
158 | #define MINLEVEL 1 |
163 | #define MINLEVEL 1 |
159 | #define MAXLEVEL 9 |
164 | #define MAXLEVEL 9 |
160 | 165 | ||
161 | /* |
166 | /* |
162 | * Scoring is as follows: |
167 | * Scoring is as follows: |
163 | * |
168 | * |
164 | * When the shape comes to rest, and is integrated into the board, |
169 | * When the shape comes to rest, and is integrated into the board, |
165 | * we score one point. If the shape is high up (at a low-numbered row), |
170 | * we score one point. If the shape is high up (at a low-numbered row), |
166 | * and the user hits the space bar, the shape plummets all the way down, |
171 | * and the user hits the space bar, the shape plummets all the way down, |
167 | * and we score a point for each row it falls (plus one more as soon as |
172 | * and we score a point for each row it falls (plus one more as soon as |
168 | * we find that it is at rest and integrate it---until then, it can |
173 | * we find that it is at rest and integrate it---until then, it can |
169 | * still be moved or rotated). |
174 | * still be moved or rotated). |
170 | * |
175 | * |
171 | * If previewing has been turned on, the score is multiplied by PRE_PENALTY. |
176 | * If previewing has been turned on, the score is multiplied by PRE_PENALTY. |
172 | */ |
177 | */ |
173 | #define PRE_PENALTY 0.75 |
178 | #define PRE_PENALTY 0.75 |
- | 179 | ||
- | 180 | extern int score; /* The obvious thing */ |
|
174 | 181 | ||
- | 182 | extern char key_msg[100]; |
|
175 | extern int score; /* the obvious thing */ |
183 | extern int showpreview; |
176 | //extern gid_t gid, egid; |
184 | extern int classic; |
177 | 185 | ||
178 | extern char key_msg[100]; |
- | |
179 | extern int showpreview; |
- | |
180 | extern int classic; |
- | |
181 | - | ||
182 | int fits_in(const struct shape *, int); |
186 | extern int fits_in(const struct shape *, int); |
183 | void place(const struct shape *, int, int); |
187 | extern void place(const struct shape *, int, int); |
184 | void stop(char *); |
188 | extern void stop(char *); |
185 | 189 | ||
186 | /** @} |
190 | /** @} |
187 | */ |
191 | */ |
188 | - | ||
189 | 192 |