1 | /* |
---|
2 | * $Id: cacatris.h 1 2006-09-22 16:56:18Z jylam $ |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation; either version 2 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the Do What The Fuck You Want To |
---|
11 | * Public License, Version 2, as published by Sam Hocevar. See |
---|
12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifndef __CACATRIS_H_ |
---|
16 | #define __CACATRIS_H_ |
---|
17 | |
---|
18 | #include <stdio.h> |
---|
19 | #include <stdlib.h> |
---|
20 | #include <string.h> |
---|
21 | #include <math.h> |
---|
22 | #ifndef M_PI |
---|
23 | # define M_PI 3.14159265358979323846 |
---|
24 | #endif |
---|
25 | |
---|
26 | |
---|
27 | #include "cucul.h" |
---|
28 | #include "caca.h" |
---|
29 | |
---|
30 | |
---|
31 | #define INFO_WIDTH 20 |
---|
32 | #define FIELD_WIDTH 20 |
---|
33 | #define FIELD_HEIGHT 35 |
---|
34 | #define FIELD_CANVAS_WIDTH 40 |
---|
35 | #define FIELD_CANVAS_HEIGHT 35 |
---|
36 | |
---|
37 | unsigned char playfield[FIELD_WIDTH*FIELD_HEIGHT]; |
---|
38 | static cucul_canvas_t *field, *infos, *screen; |
---|
39 | |
---|
40 | unsigned int blocks_palette[] = { |
---|
41 | CUCUL_COLOR_BLUE, |
---|
42 | CUCUL_COLOR_GREEN, |
---|
43 | CUCUL_COLOR_CYAN, |
---|
44 | CUCUL_COLOR_RED, |
---|
45 | CUCUL_COLOR_MAGENTA, |
---|
46 | CUCUL_COLOR_BROWN, |
---|
47 | CUCUL_COLOR_LIGHTGRAY |
---|
48 | }; |
---|
49 | |
---|
50 | typedef struct piece_t_ { |
---|
51 | unsigned int w, h; |
---|
52 | unsigned int color; |
---|
53 | unsigned int data[4*4]; |
---|
54 | } piece_t; |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | void infos_populate(cucul_canvas_t *); |
---|
60 | void playfield_draw(cucul_canvas_t *); |
---|
61 | void put_piece(unsigned int, unsigned int, unsigned int, unsigned int); |
---|
62 | void remove_piece(unsigned int id, unsigned int x, unsigned int y, unsigned int rot); |
---|
63 | unsigned char movable(unsigned int id, int x, int y, unsigned int rot); |
---|
64 | |
---|
65 | |
---|
66 | piece_t pieces[] = { |
---|
67 | /* I, rot 0*/ |
---|
68 | {4,1, |
---|
69 | 1, |
---|
70 | {1,1,1,1, |
---|
71 | 0,0,0,0, |
---|
72 | 0,0,0,0, |
---|
73 | 0,0,0,0}}, |
---|
74 | /* I, rot 1*/ |
---|
75 | {1,4, |
---|
76 | 1, |
---|
77 | {1,0,0,0, |
---|
78 | 1,0,0,0, |
---|
79 | 1,0,0,0, |
---|
80 | 1,0,0,0}}, |
---|
81 | /* I, rot 2*/ |
---|
82 | {4,1, |
---|
83 | 1, |
---|
84 | {1,1,1,1, |
---|
85 | 0,0,0,0, |
---|
86 | 0,0,0,0, |
---|
87 | 0,0,0,0}}, |
---|
88 | /* I, rot 3*/ |
---|
89 | {1,3, |
---|
90 | 1, |
---|
91 | {1,0,0,0, |
---|
92 | 1,0,0,0, |
---|
93 | 1,0,0,0, |
---|
94 | 1,0,0,0}}, |
---|
95 | /* J, rot 0*/ |
---|
96 | {3,2, |
---|
97 | 2, |
---|
98 | {1,0,0,0, |
---|
99 | 1,1,1,0, |
---|
100 | 0,0,0,0, |
---|
101 | 0,0,0,0}}, |
---|
102 | /* J, rot 1*/ |
---|
103 | {2,3, |
---|
104 | 2, |
---|
105 | {1,1,0,0, |
---|
106 | 1,0,0,0, |
---|
107 | 1,0,0,0, |
---|
108 | 0,0,0,0}}, |
---|
109 | /* J, rot 2*/ |
---|
110 | {3,2, |
---|
111 | 2, |
---|
112 | {1,1,1,0, |
---|
113 | 0,0,1,0, |
---|
114 | 0,0,0,0, |
---|
115 | 0,0,0,0}}, |
---|
116 | /* J, rot 3*/ |
---|
117 | {2,3, |
---|
118 | 2, |
---|
119 | {0,1,0,0, |
---|
120 | 0,1,0,0, |
---|
121 | 1,1,0,0, |
---|
122 | 0,0,0,0}}, |
---|
123 | /* L, rot 0*/ |
---|
124 | {3,2, |
---|
125 | 3, |
---|
126 | {0,0,1,0, |
---|
127 | 1,1,1,0, |
---|
128 | 0,0,0,0, |
---|
129 | 0,0,0,0}}, |
---|
130 | /* L, rot 1*/ |
---|
131 | {2,3, |
---|
132 | 3, |
---|
133 | {1,0,0,0, |
---|
134 | 1,0,0,0, |
---|
135 | 1,1,0,0, |
---|
136 | 0,0,0,0}}, |
---|
137 | /* L, rot 2*/ |
---|
138 | {3,2, |
---|
139 | 3, |
---|
140 | {1,1,1,0, |
---|
141 | 1,0,0,0, |
---|
142 | 0,0,0,0, |
---|
143 | 0,0,0,0}}, |
---|
144 | /* L, rot 3*/ |
---|
145 | {2,3, |
---|
146 | 3, |
---|
147 | {1,1,0,0, |
---|
148 | 0,1,0,0, |
---|
149 | 0,1,0,0, |
---|
150 | 0,0,0,0}}, |
---|
151 | /* O, rot 0*/ |
---|
152 | {2,2, |
---|
153 | 4, |
---|
154 | {1,1,0,0, |
---|
155 | 1,1,0,0, |
---|
156 | 0,0,0,0, |
---|
157 | 0,0,0,0}}, |
---|
158 | /* O, rot 1*/ |
---|
159 | {2,2, |
---|
160 | 4, |
---|
161 | {1,1,0,0, |
---|
162 | 1,1,0,0, |
---|
163 | 0,0,0,0, |
---|
164 | 0,0,0,0}}, |
---|
165 | /* O, rot 2*/ |
---|
166 | {2,2, |
---|
167 | 4, |
---|
168 | {1,1,0,0, |
---|
169 | 1,1,0,0, |
---|
170 | 0,0,0,0, |
---|
171 | 0,0,0,0}}, |
---|
172 | /* O, rot 3*/ |
---|
173 | {2,2, |
---|
174 | 4, |
---|
175 | {1,1,0,0, |
---|
176 | 1,1,0,0, |
---|
177 | 0,0,0,0, |
---|
178 | 0,0,0,0}}, |
---|
179 | /* S, rot 0*/ |
---|
180 | {3,2, |
---|
181 | 5, |
---|
182 | {0,1,1,0, |
---|
183 | 1,1,0,0, |
---|
184 | 0,0,0,0, |
---|
185 | 0,0,0,0}}, |
---|
186 | /* S, rot 1*/ |
---|
187 | {2,3, |
---|
188 | 5, |
---|
189 | {1,0,0,0, |
---|
190 | 1,1,0,0, |
---|
191 | 0,1,0,0, |
---|
192 | 0,0,0,0}}, |
---|
193 | /* S, rot 2*/ |
---|
194 | {3,2, |
---|
195 | 5, |
---|
196 | {0,1,1,0, |
---|
197 | 1,1,0,0, |
---|
198 | 0,0,0,0, |
---|
199 | 0,0,0,0}}, |
---|
200 | /* S, rot 3*/ |
---|
201 | {2,3, |
---|
202 | 5, |
---|
203 | {1,0,0,0, |
---|
204 | 1,1,0,0, |
---|
205 | 0,1,0,0, |
---|
206 | 0,0,0,0}}, |
---|
207 | /* T, rot 0*/ |
---|
208 | {3,2, |
---|
209 | 6, |
---|
210 | {0,1,0,0, |
---|
211 | 1,1,1,0, |
---|
212 | 0,0,0,0, |
---|
213 | 0,0,0,0}}, |
---|
214 | /* T, rot 1*/ |
---|
215 | {2,3, |
---|
216 | 6, |
---|
217 | {1,0,0,0, |
---|
218 | 1,1,0,0, |
---|
219 | 1,0,0,0, |
---|
220 | 0,0,0,0}}, |
---|
221 | /* T, rot 2*/ |
---|
222 | {3,2, |
---|
223 | 6, |
---|
224 | {1,1,1,0, |
---|
225 | 0,1,0,0, |
---|
226 | 0,0,0,0, |
---|
227 | 0,0,0,0}}, |
---|
228 | /* T, rot 3*/ |
---|
229 | {2,3, |
---|
230 | 6, |
---|
231 | {0,1,0,0, |
---|
232 | 1,1,0,0, |
---|
233 | 0,1,0,0, |
---|
234 | 0,0,0,0}}, |
---|
235 | /* Z, rot 0*/ |
---|
236 | {3,2, |
---|
237 | 7, |
---|
238 | {1,1,0,0, |
---|
239 | 0,1,1,0, |
---|
240 | 0,0,0,0, |
---|
241 | 0,0,0,0}}, |
---|
242 | /* Z, rot 1*/ |
---|
243 | {2,3, |
---|
244 | 7, |
---|
245 | {0,1,0,0, |
---|
246 | 1,1,0,0, |
---|
247 | 1,0,0,0, |
---|
248 | 0,0,0,0}}, |
---|
249 | /* Z, rot 2*/ |
---|
250 | {3,2, |
---|
251 | 7, |
---|
252 | {1,1,0,0, |
---|
253 | 0,1,1,0, |
---|
254 | 0,0,0,0, |
---|
255 | 0,0,0,0}}, |
---|
256 | /* Z, rot 3*/ |
---|
257 | {2,3, |
---|
258 | 7, |
---|
259 | {0,1,0,0, |
---|
260 | 1,1,0,0, |
---|
261 | 1,0,0,0, |
---|
262 | 0,0,0,0}}, |
---|
263 | }; |
---|
264 | |
---|
265 | |
---|
266 | #endif /* __CACATRIS_H_ */ |
---|