source: cacatris/trunk/src/cacatris.h @ 3150

Last change on this file since 3150 was 2981, checked in by Sam Hocevar, 14 years ago

Port cacatris to the unified libcaca 0.99.beta15 API.

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