1 /* -*- Mode: C++; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil -*-
2 *
3 * Quadra, an action puzzle game
4 * Copyright (C) 1998-2000 Ludus Design
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 // "Bloc" is simply "block" in french, which we used to mean a tetromino.
22 #include "bloc.h"
23
24 #include "color.h"
25 #include "quadra.h"
26
Bloc(int q,int c,int px,int py)27 Bloc::Bloc(int q, int c, int px, int py):
28 type(q),
29 rot(0),
30 bx(px),
31 by(py),
32 col(c) {
33 if (c == -1)
34 col = type;
35 calc_xy();
36 // Force the tetromino to start at the beginning of its initial position.
37 y -= 17 << 4;
38 }
39
draw(const Video_bitmap & b,int tx,int ty) const40 void Bloc::draw(const Video_bitmap& b, int tx, int ty) const {
41 int i,j;
42 Byte t, to[4];
43 if(tx == -1)
44 tx = x>>4;
45 if(ty == -1)
46 ty = y>>4;
47 for(j=0; j<4; j++)
48 for(i=0; i<4; i++) {
49 t = bloc[type][rot][j][i];
50 if(t) {
51 if(i > 0)
52 to[0] = bloc[type][rot][j][i-1];
53 else
54 to[0] = 0;
55 if(j > 0)
56 to[1] = bloc[type][rot][j-1][i];
57 else
58 to[1] = 0;
59 if(i < 3)
60 to[2] = bloc[type][rot][j][i+1];
61 else
62 to[2] = 0;
63 if(j < 3)
64 to[3] = bloc[type][rot][j+1][i];
65 else
66 to[3] = 0;
67 raw_draw_bloc_corner(b, tx+i*18, ty+j*18, t&15, color[col], to);
68 }
69 }
70 }
71
small_draw(const Video_bitmap & b,int tx,int ty) const72 void Bloc::small_draw(const Video_bitmap& b, int tx, int ty) const {
73 int i,j;
74 Byte t;
75 if(tx == -1)
76 tx = x>>4;
77 if(ty == -1)
78 ty = y>>4;
79 for(j=0; j<4; j++)
80 for(i=0; i<4; i++) {
81 t = bloc[type][rot][j][i];
82 if(t)
83 raw_small_draw_bloc(b, tx+i*6, ty+j*6, t&15, color[col]);
84 }
85 }
86
87 /*
88 * The four indexes are:
89 * - which type of tetromino
90 * - which orientation
91 * - which row of the tetromino
92 * - which block on a row of the tetromino
93 *
94 * When a number is non-zero, it means that there is a block present at that
95 * position, and the number itself indicates where the edges of the tetromino
96 * are. The numbers are the following values OR'd together:
97 * - 1: left
98 * - 2: top
99 * - 4: right
100 * - 8: bottom
101 */
102 const Byte Bloc::bloc[7][4][4][4]={
103 // O (square)
104 {{{0,0,0,0},
105 {0,3,6,0},
106 {0,9,12,0},
107 {0,0,0,0}},
108 {{0,0,0,0},
109 {0,3,6,0},
110 {0,9,12,0},
111 {0,0,0,0}},
112 {{0,0,0,0},
113 {0,3,6,0},
114 {0,9,12,0},
115 {0,0,0,0}},
116 {{0,0,0,0},
117 {0,3,6,0},
118 {0,9,12,0},
119 {0,0,0,0}}},
120 // S
121 {{{0,0,0,0},
122 {0,3,14,0},
123 {11,12,0,0},
124 {0,0,0,0}},
125 {{7,0,0,0},
126 {9,6,0,0},
127 {0,13,0,0},
128 {0,0,0,0}},
129 {{0,0,0,0},
130 {0,3,14,0},
131 {11,12,0,0},
132 {0,0,0,0}},
133 {{7,0,0,0},
134 {9,6,0,0},
135 {0,13,0,0},
136 {0,0,0,0}}},
137 // Z
138 {{{0,0,0,0},
139 {11,6,0,0},
140 {0,9,14,0},
141 {0,0,0,0}},
142 {{0,7,0,0},
143 {3,12,0,0},
144 {13,0,0,0},
145 {0,0,0,0}},
146 {{0,0,0,0},
147 {11,6,0,0},
148 {0,9,14,0},
149 {0,0,0,0}},
150 {{0,7,0,0},
151 {3,12,0,0},
152 {13,0,0,0},
153 {0,0,0,0}}},
154 // L
155 {{{0,0,0,0},
156 {3,10,14,0},
157 {13,0,0,0},
158 {0,0,0,0}},
159 {{11,6,0,0},
160 {0,5,0,0},
161 {0,13,0,0},
162 {0,0,0,0}},
163 {{0,0,7,0},
164 {11,10,12,0},
165 {0,0,0,0},
166 {0,0,0,0}},
167 {{0,7,0,0},
168 {0,5,0,0},
169 {0,9,14,0},
170 {0,0,0,0}}},
171 // J
172 {{{0,0,0,0},
173 {11,10,6,0},
174 {0,0,13,0},
175 {0,0,0,0}},
176 {{0,7,0,0},
177 {0,5,0,0},
178 {11,12,0,0},
179 {0,0,0,0}},
180 {{7,0,0,0},
181 {9,10,14,0},
182 {0,0,0,0},
183 {0,0,0,0}},
184 {{0,3,14,0},
185 {0,5,0,0},
186 {0,13,0,0},
187 {0,0,0,0}}},
188 // I
189 {{{0,0,0,0},
190 {11,10,10,14},
191 {0,0,0,0},
192 {0,0,0,0}},
193 {{0,7,0,0},
194 {0,5,0,0},
195 {0,5,0,0},
196 {0,13,0,0}},
197 {{0,0,0,0},
198 {11,10,10,14},
199 {0,0,0,0},
200 {0,0,0,0}},
201 {{0,7,0,0},
202 {0,5,0,0},
203 {0,5,0,0},
204 {0,13,0,0}}},
205 // T
206 {{{0,0,0,0},
207 {11,2,14,0},
208 {0,13,0,0},
209 {0,0,0,0}},
210 {{0,7,0,0},
211 {11,4,0,0},
212 {0,13,0,0},
213 {0,0,0,0}},
214 {{0,7,0,0},
215 {11,8,14,0},
216 {0,0,0,0},
217 {0,0,0,0}},
218 {{0,7,0,0},
219 {0,1,14,0},
220 {0,13,0,0},
221 {0,0,0,0}}}};
222