~ubuntu-branches/ubuntu/natty/gtkboard/natty

« back to all changes in this revision

Viewing changes to .pc/debian-changes-0.11pre0+cvs.2003.11.02-2/src/tetris.c

  • Committer: Bazaar Package Importer
  • Author(s): Barak A. Pearlmutter
  • Date: 2011-02-28 11:25:02 UTC
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20110228112502-e9aah248wxelm7ao
Tags: 0.11pre0+cvs.2003.11.02-2
autotools tweaks, most notably -lSDL to supplement -lSDL_mixer

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  This file is a part of gtkboard, a board games system.
 
2
    Copyright (C) 2003, Arvind Narayanan <arvindn@users.sourceforge.net>
 
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 distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
 
17
 
 
18
*/
 
19
#include <stdio.h>
 
20
#include <string.h>
 
21
#include <assert.h>
 
22
#include <stdlib.h>
 
23
#include <math.h>
 
24
#include <gdk/gdkkeysyms.h>
 
25
 
 
26
#include "game.h"
 
27
#include "aaball.h"
 
28
 
 
29
#define TETRIS_CELL_SIZE 20
 
30
#define TETRIS_NUM_PIECES 32
 
31
 
 
32
#define TETRIS_REAL_WID 10
 
33
#define TETRIS_BOARD_WID 16
 
34
#define TETRIS_BOARD_HEIT 22
 
35
#define TETRIS_PREVIEW_HEIT 3
 
36
 
 
37
char tetris_colors[9] = {50, 50, 50, 50, 50, 50, 150, 150, 150};
 
38
 
 
39
static int tetris_init_pos [TETRIS_BOARD_WID*TETRIS_BOARD_HEIT] = 
 
40
{
 
41
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
42
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
43
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
44
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 0 , 0 , 0 , 0 , 32, 
 
45
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 0 , 0 , 0 , 0 , 32, 
 
46
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 0 , 0 , 0 , 0 , 32, 
 
47
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 0 , 0 , 0 , 0 , 32, 
 
48
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
49
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
50
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
51
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
52
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
53
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
54
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
55
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
56
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
57
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
58
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
59
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
60
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
61
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
62
        0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32, 32, 32, 32, 32, 32, 
 
63
};
 
64
 
 
65
 
 
66
void tetris_init ();
 
67
 
 
68
Game Tetris = { TETRIS_CELL_SIZE, TETRIS_BOARD_WID, TETRIS_BOARD_HEIT, 
 
69
        TETRIS_NUM_PIECES,
 
70
        tetris_colors,  tetris_init_pos, NULL, "Tetris", "Arcade", tetris_init};
 
71
 
 
72
SCORE_FIELD tetris_score_fields[] = {SCORE_FIELD_USER, SCORE_FIELD_SCORE, SCORE_FIELD_DATE, SCORE_FIELD_NONE};
 
73
char *tetris_score_field_names[] = {"User", "Score", "Date", NULL};
 
74
 
 
75
#define TETRIS_EMPTY 0
 
76
#define TETRIS_BRICK_4 1 
 
77
#define TETRIS_BRICK_22 2 
 
78
#define TETRIS_BRICK_121A 3 
 
79
#define TETRIS_BRICK_121B 4
 
80
#define TETRIS_BRICK_T 5 
 
81
#define TETRIS_BRICK_LA 6
 
82
#define TETRIS_BRICK_LB 7
 
83
#define TETRIS_BRICK_INACTIVE 8
 
84
#define TETRIS_BRICK_DYING 9
 
85
#define TETRIS_BRICK_MASK 15
 
86
#define TETRIS_BRICK_MOTION_MASK 16
 
87
#define TETRIS_UNUSED 32
 
88
 
 
89
static void tetris_set_init_pos (Pos *pos);
 
90
static char ** tetris_get_pixmap (int idx, int color);
 
91
static int tetris_getmove_kb (Pos *cur_pos, int key, byte **move, int **);
 
92
static int tetris_animate (Pos *pos, byte **movp);
 
93
static ResultType tetris_who_won (Pos *pos, Player to_play, char **commp);
 
94
static void *tetris_newstate (Pos *, byte *);
 
95
static void tetris_free ();
 
96
 
 
97
typedef struct
 
98
{
 
99
        int score;
 
100
}
 
101
Tetris_state;
 
102
 
 
103
static int num_bricks = 0;
 
104
static int level = 1;
 
105
static int anim_time_left = 0;
 
106
static int anim_time_def = 0;
 
107
 
 
108
void tetris_init ()
 
109
{
 
110
        game_single_player = TRUE;
 
111
        game_get_pixmap = tetris_get_pixmap;
 
112
        game_getmove_kb = tetris_getmove_kb;
 
113
        game_animation_time = 50;
 
114
        game_animate = tetris_animate;
 
115
        game_who_won = tetris_who_won;
 
116
        game_stateful = TRUE;
 
117
        game_state_size = sizeof (Tetris_state);
 
118
        game_newstate = tetris_newstate;
 
119
        game_scorecmp = game_scorecmp_def_dscore;
 
120
        game_allow_back_forw = FALSE;
 
121
        game_scorecmp = game_scorecmp_def_dscore;
 
122
        game_score_fields = tetris_score_fields;
 
123
        game_score_field_names = tetris_score_field_names;
 
124
        game_draw_cell_boundaries = TRUE;
 
125
        game_free = tetris_free;
 
126
        game_doc_about_status = STATUS_COMPLETE;
 
127
        game_doc_about = 
 
128
                "Tetris\n"
 
129
                "Single player game\n"
 
130
                "Status: Fully implemented\n"
 
131
                "URL: "GAME_DEFAULT_URL ("tetris");
 
132
        game_doc_rules =
 
133
                "This is a game of falling bricks. Your objective is to rotate the pieces as they fall in order to make complete rows of bricks. Use the arrow keys to move left or right, Up to rotate, and Space to fall. Completing a row gives you 40 points, two rows simultaneously 100 points, three rows 300 points, and four rows (a tetris) 1200 points.";
 
134
}
 
135
 
 
136
void tetris_free ()
 
137
{
 
138
        num_bricks = 0;
 
139
        level = 1;
 
140
        anim_time_left = 0;
 
141
}
 
142
 
 
143
void *tetris_newstate (Pos *pos, byte *move)
 
144
        // TODO: implement points for falling
 
145
{
 
146
        int i, score = 0;
 
147
        static Tetris_state state;
 
148
        int linepts[5] = {0, 40, 100, 300, 1200};
 
149
        for (i=0; move[3*i] >= 0; i++)
 
150
                if (move[3*i+2] == 0)
 
151
                        score++;
 
152
        score /= TETRIS_REAL_WID;
 
153
        score = linepts [score];
 
154
        state.score = (pos->state ? ((Tetris_state *)pos->state)->score : 0) + score;
 
155
        return &state;
 
156
}
 
157
 
 
158
int tetris_game_over (byte *board)
 
159
{
 
160
        int i;
 
161
        for (i=0; i<TETRIS_REAL_WID; i++)
 
162
                if (board[(board_heit - 2) * board_wid + i] == TETRIS_BRICK_INACTIVE)
 
163
                        return 1;
 
164
        return 0;
 
165
}
 
166
 
 
167
 
 
168
ResultType tetris_who_won (Pos *pos, Player to_play, char **commp)
 
169
{
 
170
        static char comment[32];
 
171
        int i;
 
172
        int over = tetris_game_over (pos->board);
 
173
        snprintf (comment, 32, "%s %s %d", 
 
174
                        over ? "Game over. " : "", "Score:",
 
175
                        pos->state ? ((Tetris_state *)pos->state)->score : 0);
 
176
        *commp = comment;
 
177
        return over ? RESULT_WON : RESULT_NOTYET;
 
178
}
 
179
 
 
180
int tetris_fall (byte *pos, byte **movp, int height)
 
181
{
 
182
        static byte move[32];
 
183
        byte *mp = move;
 
184
        int moving = 0;
 
185
        int canfall = 1;
 
186
        int i, j, k;
 
187
        for (j=0; j<board_heit; j++)
 
188
        for (i=0; i<TETRIS_REAL_WID; i++)
 
189
        {
 
190
                if (pos [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK)
 
191
                {
 
192
                        int tmp;
 
193
                        if (height > j) height = j;
 
194
                        moving = 1;
 
195
                        if (j == 0) canfall = 0;
 
196
                        for (k=1; k<=height; k++)
 
197
                        {
 
198
                                tmp = pos [(j-k) * board_wid + i];
 
199
                                if (tmp != 0 && !(tmp & TETRIS_BRICK_MOTION_MASK))
 
200
                                        canfall = 0;
 
201
                        }
 
202
                }
 
203
        }
 
204
        if (moving && canfall)
 
205
        {
 
206
                for (i=0; i<TETRIS_REAL_WID; i++)
 
207
                for (j=0; j<board_heit; j++)
 
208
                {
 
209
                        if (j < board_heit - height)
 
210
                        if (!(pos [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK) 
 
211
                                && (pos [(j+height) * board_wid + i] & TETRIS_BRICK_MOTION_MASK))
 
212
                        {
 
213
                                *mp++ = i; *mp++ = j; *mp++ = pos [(j+height) * board_wid + i];
 
214
                        }
 
215
                        if (pos [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK 
 
216
                                && (j >= board_heit - height || 
 
217
                                        !(pos [(j+height) * board_wid + i] & TETRIS_BRICK_MOTION_MASK)))
 
218
                        {
 
219
                                *mp++ = i; *mp++ = j; *mp++ = 0;
 
220
                        }
 
221
                }
 
222
                *mp++ = -1;
 
223
                *movp = move;
 
224
                return 1;
 
225
        }
 
226
        return -1;
 
227
}
 
228
 
 
229
int tetris_animate (Pos *pos, byte **movp)
 
230
{
 
231
        static byte move[1024];
 
232
        static int count = 0;
 
233
        byte *mp = move;
 
234
        byte *board = pos->board;
 
235
        int i, j;
 
236
        int level = num_bricks / 20 + 1;
 
237
        if (level > 10) level = 10;
 
238
        anim_time_def = (12 - level) / 2;
 
239
        if (anim_time_left) 
 
240
        {
 
241
                anim_time_left--;
 
242
                return 0;
 
243
        }
 
244
 
 
245
        anim_time_left = 12 - level;
 
246
        if (tetris_fall(board, movp, 1) > 0)
 
247
                return 1;
 
248
 
 
249
        for (i=0; i<TETRIS_REAL_WID; i++)
 
250
        for (j=0; j<board_heit; j++)
 
251
                if (board [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK)
 
252
                {
 
253
                        *mp++ = i; *mp++ = j; 
 
254
                        *mp++ = TETRIS_BRICK_INACTIVE;
 
255
                }
 
256
        for (j=0; j<board_heit; j++)
 
257
        {
 
258
                int nfull = 0;
 
259
                while (nfull + j < board_heit)
 
260
                {
 
261
                        int full = 1;
 
262
                        for (i=0; i<TETRIS_REAL_WID; i++) 
 
263
                                if (board [(j+nfull) * board_wid + i] == 0) { full = 0; break; }
 
264
                        if (!full) break;
 
265
                        nfull++;
 
266
                }
 
267
                if (nfull > 0)
 
268
                {
 
269
                        for (; j+nfull<board_heit; j++)
 
270
                        {
 
271
                                for (i=0; i<TETRIS_REAL_WID; i++) 
 
272
                                {
 
273
                                        if (board [j * board_wid + i] != 
 
274
                                                        board [(j+nfull) * board_wid + i])
 
275
                                        { *
 
276
                                                mp++ = i; *mp++ = j; 
 
277
                                                //*mp++ = board [(j+nfull) * board_wid + i]; 
 
278
                                                if ( board [(j+nfull) * board_wid + i] == 0)
 
279
                                                        *mp++ = 0;
 
280
                                                else *mp++ =  TETRIS_BRICK_INACTIVE;
 
281
                                        }
 
282
                                }
 
283
                        }
 
284
                        for (; j<board_heit; j++)
 
285
                        {
 
286
                                int empty = 1;
 
287
                                for (i=0; i<TETRIS_REAL_WID; i++) 
 
288
                                {
 
289
                                        if (board [j * board_wid + i] != 0)
 
290
                                        {
 
291
                                                *mp++ = i; *mp++ = j; *mp++ = 0;
 
292
                                        }
 
293
                                        if (board [j * board_wid + i] != 0) empty = 0;
 
294
                                }
 
295
                                if (empty) break;
 
296
                        }
 
297
                        *mp++ = -1;
 
298
                        *movp = move;
 
299
                        return 1;
 
300
                }
 
301
        }
 
302
        
 
303
        num_bricks ++;
 
304
 
 
305
        {
 
306
        int idx;
 
307
        byte *saved_m = mp;
 
308
        static int next_tile = -1;
 
309
        // This depends on the #defs!!
 
310
        // FIXME: change the shapes so that no brick is more than 2 rows tall
 
311
        byte shapes [][4][2] = {
 
312
                { { 3, 1} , {4, 1}, {5, 1}, {6, 1} },
 
313
                { { 4, 1} , {5, 1}, {4, 2}, {5, 2} },
 
314
                { { 4, 2} , {5, 2}, {5, 1}, {6, 1} },
 
315
                { { 4, 1} , {5, 1}, {5, 2}, {6, 2} },
 
316
                { { 4, 1} , {5, 1}, {6, 1}, {5, 2} },
 
317
                { { 6, 1} , {5, 1}, {4, 2}, {4, 1} },
 
318
                { { 3, 1} , {4, 1}, {5, 1}, {5, 2} },
 
319
        };
 
320
 
 
321
        idx = next_tile;
 
322
        next_tile = random() % 7;
 
323
        if (idx < 0)
 
324
                idx = random() % 7;     
 
325
        for (i=0; i<4; i++)
 
326
        {
 
327
                *mp++ = shapes[idx][i][0]; 
 
328
                *mp++ = board_heit - shapes[idx][i][1]; 
 
329
                if (board [mp[-1] * board_wid + mp[-2]])
 
330
                {
 
331
                        // we need to return the move up to the previous stage
 
332
                        *saved_m++ = -1;
 
333
                        *movp = move;
 
334
                        return 1;
 
335
                }
 
336
                *mp++ = (idx+1) | TETRIS_BRICK_MOTION_MASK;
 
337
        }
 
338
        for (i=0; i<4; i++)
 
339
        for (j=0; j<4; j++)
 
340
        {
 
341
                *mp++ = TETRIS_REAL_WID + 1 + i;
 
342
                *mp++ = board_heit - 1 - TETRIS_PREVIEW_HEIT - j;
 
343
                *mp++ = 0;
 
344
        }
 
345
        for (i=0; i<4; i++)
 
346
        {
 
347
                *mp++ = TETRIS_REAL_WID + shapes[next_tile][i][1] + 1; 
 
348
                *mp++ = board_heit - TETRIS_PREVIEW_HEIT + shapes[next_tile][i][0] - 7;
 
349
                *mp++ = (next_tile+1);
 
350
        }
 
351
        *mp++ = -1;
 
352
        *movp = move;
 
353
        return 1;
 
354
        }
 
355
}
 
356
 
 
357
 
 
358
int tetris_getmove_kb (Pos *pos, int key, byte **movp, int **rmovp)
 
359
{
 
360
        static byte move[32];
 
361
        byte *mp = move;
 
362
        int incx;
 
363
        int i, j;
 
364
        byte *board = pos->board;
 
365
 
 
366
        if (key == ' ')
 
367
        {
 
368
                for (i = board_heit; i>0; i--)
 
369
                        if (tetris_fall(board, movp, i) > 0)
 
370
                        {
 
371
                                anim_time_left = anim_time_def;
 
372
                                return 1;
 
373
                        }
 
374
                return -1;
 
375
        }
 
376
        
 
377
        if (key == GDK_Down)
 
378
        {
 
379
                int retval = tetris_fall(board, movp, 1);
 
380
                if (retval > 0) anim_time_left = anim_time_def;
 
381
                return retval;
 
382
        }
 
383
        
 
384
        if (key == GDK_Up)
 
385
        {
 
386
                int sumx = 0, sumy = 0, k = 0, incy;
 
387
                int thebrick = 0;
 
388
                byte newboard [4][2];
 
389
                for (i=0; i<TETRIS_REAL_WID; i++)
 
390
                for (j=0; j<board_heit; j++)
 
391
                        if (board [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK)
 
392
                        { 
 
393
                                sumx += i; sumy += j; 
 
394
                                thebrick = board [j * board_wid + i] | TETRIS_BRICK_MOTION_MASK;
 
395
                                if (j == 0 || ((board [(j-1) * board_wid + i] != 0) 
 
396
                                        && !(board [(j-1) * board_wid + i] & TETRIS_BRICK_MOTION_MASK)))
 
397
                                        return -1;
 
398
                        }
 
399
                if (sumy == 0) return -1;
 
400
                sumx += 3; incy = sumy % 4 > 0 ? 1 : 0; sumx /= 4; sumy /= 4;
 
401
                for (i=0; i<TETRIS_REAL_WID; i++)
 
402
                for (j=0; j<board_heit; j++)
 
403
                        if (board [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK)
 
404
                        {
 
405
                                newboard[k][0] = sumx + sumy - j;
 
406
                                newboard[k][1] = sumy - sumx + i + incy;
 
407
                                if (newboard[k][0] < 0 || newboard[k][1] < 0 || 
 
408
                                                newboard[k][0] >= TETRIS_REAL_WID || newboard[k][1] >= board_heit)
 
409
                                        return -1;
 
410
                                if (board [newboard [k][1] * board_wid + newboard[k][0]]
 
411
                                                == TETRIS_BRICK_INACTIVE)
 
412
                                        return -1;
 
413
                                k++;
 
414
                        }
 
415
                for (i=0; i<TETRIS_REAL_WID; i++)
 
416
                for (j=0; j<board_heit; j++)
 
417
                {
 
418
                        if (!(board [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK))
 
419
                        {
 
420
                                int found = 0;
 
421
                                for (k=0; k<4; k++) 
 
422
                                        if (newboard[k][0] == i && newboard[k][1] == j)
 
423
                                        { found = 1; break; }
 
424
                                if (found)
 
425
                                {
 
426
                                        *mp++ = i; *mp++ = j; *mp++ = thebrick;
 
427
                                }
 
428
                        }
 
429
                        if (board [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK)
 
430
                        {
 
431
                                int found = 0;
 
432
                                for (k=0; k<4; k++) 
 
433
                                        if (newboard[k][0] == i && newboard[k][1] == j)
 
434
                                        { found = 1; break; }
 
435
                                if (!found)
 
436
                                {
 
437
                                        *mp++ = i; *mp++ = j; *mp++ = 0;
 
438
                                }
 
439
                        }
 
440
                }
 
441
                *mp++ = -1;
 
442
                *movp = move;
 
443
                return 1;
 
444
        }
 
445
        switch (key)
 
446
        {
 
447
                case GDK_Left: incx = 1; break;
 
448
                case GDK_Right: incx = -1; break;
 
449
                default: return -1;
 
450
        }
 
451
        for (i=0; i<TETRIS_REAL_WID; i++)
 
452
        for (j=0; j<board_heit; j++)
 
453
                if (board [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK)
 
454
                {
 
455
                        if (i - incx < 0 || i - incx >= TETRIS_REAL_WID) return -1;
 
456
                        if (board [j * board_wid + i - incx] != 0 && 
 
457
                                        !(board [j * board_wid + i - incx] & TETRIS_BRICK_MOTION_MASK))
 
458
                                return -1;
 
459
                }
 
460
        for (i=0; i<TETRIS_REAL_WID; i++)
 
461
        for (j=0; j<board_heit; j++)
 
462
        {
 
463
                if (i+incx >= 0 && i+incx < TETRIS_REAL_WID)
 
464
                if (!(board [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK) 
 
465
                        && (board [j * board_wid + i+incx] & TETRIS_BRICK_MOTION_MASK))
 
466
                {
 
467
                        *mp++ = i; *mp++ = j; *mp++ = board [j * board_wid + i+incx];
 
468
                }
 
469
                if (board [j * board_wid + i] & TETRIS_BRICK_MOTION_MASK 
 
470
                        && (i+incx < 0 || i+incx >= TETRIS_REAL_WID || 
 
471
                                !(board [j * board_wid + i+incx] & TETRIS_BRICK_MOTION_MASK)))
 
472
                {
 
473
                        *mp++ = i; *mp++ = j; *mp++ = 0;
 
474
                }
 
475
        }
 
476
        *mp++ = -1;
 
477
        *movp = move;
 
478
        return 1;
 
479
}
 
480
 
 
481
 
 
482
char ** tetris_get_pixmap (int idx, int color)
 
483
{
 
484
        int i;
 
485
        static char *pixmap [TETRIS_CELL_SIZE + 2];
 
486
        char *line = "                    ";
 
487
        //pixmap = g_new(char *, TETRIS_CELL_SIZE + 2);
 
488
        pixmap[0] = "20 20 1 1";
 
489
        if (idx == TETRIS_UNUSED)
 
490
                pixmap[1] = "  c #969696";
 
491
        else
 
492
                switch (idx & TETRIS_BRICK_MASK)
 
493
                {
 
494
                        case TETRIS_BRICK_4: pixmap[1] = "  c blue"; break;
 
495
                        case TETRIS_BRICK_22: pixmap[1] = "  c red"; break;
 
496
                        case TETRIS_BRICK_121A: pixmap[1] = "  c yellow"; break;
 
497
                        case TETRIS_BRICK_121B: pixmap[1] = "  c magenta"; break;
 
498
                        case TETRIS_BRICK_T: pixmap[1] = "  c green"; break;
 
499
                        case TETRIS_BRICK_LA: pixmap[1] = "  c pink"; break;
 
500
                        case TETRIS_BRICK_LB: pixmap[1] = "  c orange"; break;
 
501
                        case TETRIS_BRICK_INACTIVE: pixmap[1] = "  c gray"; break;
 
502
                        default: return NULL;
 
503
                }
 
504
        for (i=0; i<TETRIS_CELL_SIZE; i++) pixmap[2+i] = line;
 
505
        return pixmap;
 
506
}
 
507