3 * Daniel Nelson - 8/31/0
5 * Copyright (C) 2000 Daniel Nelson
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
25 * Handle's the displaying of the blocks.
36 #include "Displayer.h"
39 #include "BlockManager.h"
40 #include "LightManager.h"
44 const GLfloat
Displayer::block_colors
[BF_NUMBER
][3]
45 = { { 0.73f
, 0.0f
, 0.73f
}, // purple
46 { 0.2f
, 0.2f
, 0.8f
}, // blue
47 { 0.0f
, 0.6f
, 0.05f
}, // green
48 { 0.85f
, 0.85f
, 0.0f
}, // yellow
49 { 1.0f
, 0.4f
, 0.0f
}, // orange
50 { 1.0f
, 0.0f
, 0.0f
}, // wild
51 { 0.4f
, 0.4f
, 0.4f
}, // gray
52 { 0.05f
, 0.05f
, 0.05f
}, // black
53 { 0.95f
, 0.95f
, 0.95f
}, // white
54 { 2.0f
* 0.73f
, 2.0f
* 0.0f
, 2.0f
* 0.73f
}, // special purple
55 { 2.0f
* 0.2f
, 2.0f
* 0.2f
, 2.0f
* 0.8f
}, // special blue
56 { 2.0f
* 0.0f
, 2.0f
* 0.6f
, 2.0f
* 0.05f
}, // special green
57 { 2.0f
* 0.85f
, 2.0f
* 0.85f
, 2.0f
* 0.0f
}, // special yellow
58 { 2.0f
* 1.0f
, 2.0f
* 0.4f
, 2.0f
* 0.0f
} }; // special orange
60 const GLfloat creep_colors
[BF_NUMBER
][3]
61 = { { 0.25f
* 0.73f
, 0.25f
* 0.0f
, 0.25f
* 0.73f
}, // purple
62 { 0.25f
* 0.2f
, 0.25f
* 0.2f
, 0.25f
* 0.8f
}, // blue
63 { 0.25f
* 0.0f
, 0.25f
* 0.6f
, 0.25f
* 0.05f
}, // green
64 { 0.25f
* 0.85f
, 0.25f
* 0.85f
, 0.25f
* 0.0f
}, // yellow
65 { 0.25f
* 1.0f
, 0.25f
* 0.4f
, 0.25f
* 0.0f
}, // orange
66 { 0.25f
* 1.0f
, 0.25f
* 0.0f
, 0.25f
* 0.0f
}, // wild
67 { 0.25f
* 0.4f
, 0.25f
* 0.4f
, 0.25f
* 0.4f
}, // gray
68 { 0.25f
* 0.05f
, 0.25f
* 0.05f
, 0.25f
* 0.05f
}, // black
69 { 0.25f
* 0.95f
, 0.25f
* 0.95f
, 0.25f
* 0.95f
}, // white
70 { 0.5f
* 0.73f
, 0.5f
* 0.0f
, 0.5f
* 0.73f
}, // special purple
71 { 0.5f
* 0.2f
, 0.5f
* 0.2f
, 0.5f
* 0.8f
}, // special blue
72 { 0.5f
* 0.0f
, 0.5f
* 0.6f
, 0.5f
* 0.05f
}, // special green
73 { 0.5f
* 0.85f
, 0.5f
* 0.85f
, 0.5f
* 0.0f
}, // special yellow
74 { 0.5f
* 1.0f
, 0.5f
* 0.4f
, 0.5f
* 0.0f
} }; // special orange
76 void Displayer::setWildBlockColor ( Block
&block
, float flash
)
78 Wild
&wild
= X::wild(block
);
80 if (wild
.alarm
< GC_WILD_POLYMORPH_PERIOD
) {
81 GLfloat fade
= wild
.alarm
* (1.0f
/ (GLfloat
) GC_WILD_POLYMORPH_PERIOD
);
84 if (wild
.flavor
!= BF_NORMAL_1
)
85 next_color
= wild
.flavor
- 1;
91 color
[0] = fade
* block_colors
[wild
.flavor
][0]
92 + (1.0f
- fade
) * block_colors
[next_color
][0];
93 color
[1] = fade
* block_colors
[wild
.flavor
][1]
94 + (1.0f
- fade
) * block_colors
[next_color
][1];
95 color
[2] = fade
* block_colors
[wild
.flavor
][2]
96 + (1.0f
- fade
) * block_colors
[next_color
][2];
98 color
[0] = fade
* creep_colors
[wild
.flavor
][0]
99 + (1.0f
- fade
) * creep_colors
[next_color
][0];
100 color
[1] = fade
* creep_colors
[wild
.flavor
][1]
101 + (1.0f
- fade
) * creep_colors
[next_color
][1];
102 color
[2] = fade
* creep_colors
[wild
.flavor
][2]
103 + (1.0f
- fade
) * creep_colors
[next_color
][2];
106 glColor3f(color
[0] + flash
* (DC_FLASH_COLOR_RED
- color
[0]),
107 color
[1] + flash
* (DC_FLASH_COLOR_GREEN
- color
[1]),
108 color
[2] + flash
* (DC_FLASH_COLOR_BLUE
- color
[2]));
112 glColor3f(block_colors
[wild
.flavor
][0]
113 + flash
* (DC_FLASH_COLOR_RED
- block_colors
[wild
.flavor
][0]),
114 block_colors
[wild
.flavor
][1]
115 + flash
* (DC_FLASH_COLOR_GREEN
- block_colors
[wild
.flavor
][1]),
116 block_colors
[wild
.flavor
][2]
117 + flash
* (DC_FLASH_COLOR_BLUE
- block_colors
[wild
.flavor
][2]));
119 glColor3f(creep_colors
[wild
.flavor
][0]
120 + flash
* (DC_FLASH_COLOR_RED
- creep_colors
[wild
.flavor
][0]),
121 creep_colors
[wild
.flavor
][1]
122 + flash
* (DC_FLASH_COLOR_GREEN
- creep_colors
[wild
.flavor
][1]),
123 creep_colors
[wild
.flavor
][2]
124 + flash
* (DC_FLASH_COLOR_BLUE
- creep_colors
[wild
.flavor
][2]));
127 void Displayer::drawBlocks ( )
129 glColorMaterial(GL_FRONT
, GL_DIFFUSE
);
131 // GL_FRONT_AND_BACK because the garbage uses these material properties
132 // also and I don't think it hurts with cull face on.
134 color
[0] = 0.0f
; color
[1] = 0.0f
; color
[2] = 0.0f
; color
[3] = 1.0f
;
135 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT
, color
);
136 color
[0] = 0.5f
; color
[1] = 0.5f
; color
[2] = 0.5f
; color
[3] = 1.0f
;
137 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, color
);
138 color
[0] = 0.0f
; color
[1] = 0.0f
; color
[2] = 0.0f
; color
[3] = 1.0f
;
139 glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, color
);
140 glMaterialf(GL_FRONT_AND_BACK
, GL_SHININESS
, 10.0f
);
142 // First we'll draw the non-special color blocks.
144 int c
= BlockManager::block_count
;
145 for (int n
= 0; c
; n
++)
146 if (BlockManager::storeMap
[n
]) {
147 Block
&block
= BlockManager::blockStore
[n
];
150 if (BlockManager::isSpecialColorFlavor(block
.flavor
)) continue;
152 if (block
.y
> GC_SAFE_HEIGHT
) continue;
154 drawBlock(block
, false);
157 if (!X::specialColorActive()) return;
159 // Then we set things up for special color blocks and draw them.
161 if (opengl_version_1_2
)
162 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL
, GL_SEPARATE_SPECULAR_COLOR
);
164 glEnable(GL_TEXTURE_1D
);
166 glBindTexture(GL_TEXTURE_1D
, special_block_lightmap
);
168 c
= X::special_color_count
;
169 for (int n
= 0; c
; n
++)
170 if (BlockManager::storeMap
[n
]) {
171 Block
&block
= BlockManager::blockStore
[n
];
173 if (!BlockManager::isSpecialColorFlavor(block
.flavor
)) continue;
176 glMatrixMode(GL_TEXTURE
);
179 glTranslatef(((Game::time_step
+ block
.X
) & (DC_GLEAM_PERIOD
- 1))
180 * (1.0f
/ (GLfloat
) DC_GLEAM_PERIOD
), 0.0f
, 0.0f
);
181 glRotatef(DC_GLEAM_ROTATION_RATE
* (Game::time_step
+ block
.X
),
182 DC_GLEAM_ROTATION_AXIS_X
, DC_GLEAM_ROTATION_AXIS_Y
,
183 DC_GLEAM_ROTATION_AXIS_Z
);
184 glMatrixMode(GL_MODELVIEW
);
186 drawBlock(block
, true);
188 glMatrixMode(GL_TEXTURE
);
190 glMatrixMode(GL_MODELVIEW
);
193 glDisable(GL_TEXTURE_1D
);
195 if (opengl_version_1_2
)
196 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL
, GL_SINGLE_COLOR
);
199 inline void Displayer::drawBlock ( Block
&block
, bool special
)
206 y
= block
.y
* DC_GRID_ELEMENT_LENGTH
207 + block
.f_y
* (DC_GRID_ELEMENT_LENGTH
/ (GLfloat
) GC_STEPS_PER_GRID
)
211 if (block
.state
& (BS_STATIC
| BS_FALLING
)) {
212 x
= block
.x
* DC_GRID_ELEMENT_LENGTH
+ DC_PLAY_OFFSET_X
;
214 if (block
.flavor
!= BF_WILD
)
216 glColor3fv(block_colors
[block
.flavor
]);
218 glColor3fv(creep_colors
[block
.flavor
]);
220 setWildBlockColor(block
, 0.0f
);
222 LightManager::setupBlockLights(x
, y
);
223 glTranslatef(x
, y
, DC_PLAY_OFFSET_Z
);
226 glCallList(block_list
);
228 glCallList(special_block_list
);
230 // awaking and popping
231 } else if (block
.state
& BS_AWAKING
) {
232 x
= block
.x
* DC_GRID_ELEMENT_LENGTH
+ DC_PLAY_OFFSET_X
;
234 LightManager::setupBlockLights(x
, y
);
235 glTranslatef(x
, y
, DC_PLAY_OFFSET_Z
);
237 // if we haven't popped yet
238 if (block
.pop_alarm
!= 0) {
240 // if we're just about to pop
241 if (block
.pop_alarm
- Game::time_step
< DC_POP_ROTATE_TIME
) {
242 GLfloat p
= (block
.pop_alarm
- Game::time_step
)
243 * (1.0f
/ (GLfloat
) DC_POP_ROTATE_TIME
);
245 // each block rotates a different direction
246 if (block
.pop_direction
& BR_DIRECTION_1
) {
247 glRotatef(45.0f
* p
, 1.0f
, 0.0f
, 0.0f
);
248 glRotatef(45.0f
* p
, 0.0f
, 1.0f
, 0.0f
);
249 } else if (block
.pop_direction
& BR_DIRECTION_2
) {
250 glRotatef(90.0f
- 45.0f
* p
, 1.0f
, 0.0f
, 0.0f
);
251 glRotatef(45.0f
* p
, 0.0f
, 1.0f
, 0.0f
);
252 } else if (block
.pop_direction
& BR_DIRECTION_3
) {
253 glRotatef(90.0f
- 45.0f
* p
, 1.0f
, 0.0f
, 0.0f
);
254 glRotatef(-45.0f
* p
, 0.0f
, 1.0f
, 0.0f
);
256 glRotatef(45.0f
* p
, 1.0f
, 0.0f
, 0.0f
);
257 glRotatef(-45.0f
* p
, 0.0f
, 1.0f
, 0.0f
);
260 GLfloat scale
= 1.0f
- 0.5f
* p
;
261 glScalef(scale
, scale
, scale
);
263 glColor3f( (1.0f
- p
) * block_colors
[block
.flavor
][0]
264 + p
* garbage_colors
[block
.pop_color
][0],
265 (1.0f
- p
) * block_colors
[block
.flavor
][1]
266 + p
* garbage_colors
[block
.pop_color
][1],
267 (1.0f
- p
) * block_colors
[block
.flavor
][2]
268 + p
* garbage_colors
[block
.pop_color
][2]);
270 glEnable(rescale_method
);
271 glCallList(block_list
);
272 glDisable(rescale_method
);
274 // if we're not popping
277 glColor3fv(garbage_colors
[block
.pop_color
]);
279 // the small block is pre-rotated
280 glCallList(small_block_list
);
283 // if we've already popped
285 glColor3fv(block_colors
[block
.flavor
]);
287 glCallList(block_list
);
291 } else if (block
.state
& BS_SWAPPING
) {
292 x
= block
.x
* DC_GRID_ELEMENT_LENGTH
+ DC_PLAY_OFFSET_X
;
294 if (block
.state
& BS_SWAP_DIRECTION_MASK
) {
295 LightManager::setupBlockLights(x
+ Swapper::swap_factor
296 * DC_GRID_ELEMENT_LENGTH
, y
);
297 d_x
= -DC_GRID_ELEMENT_LENGTH
/ 2.0f
;
300 LightManager::setupBlockLights(x
- Swapper::swap_factor
301 * DC_GRID_ELEMENT_LENGTH
, y
);
302 d_x
= DC_GRID_ELEMENT_LENGTH
/ 2.0f
;
305 if (block
.flavor
!= BF_WILD
)
306 glColor3fv(block_colors
[block
.flavor
]);
308 setWildBlockColor(block
, 0.0f
);
310 glTranslatef(x
- d_x
, y
, DC_PLAY_OFFSET_Z
);
311 glRotatef(-180.0f
* (1.0f
- Swapper::swap_factor
), 0.0f
, 1.0f
, 0.0f
);
312 glTranslatef(d_x
, 0.0f
, 0.0f
);
315 glCallList(block_list
);
317 glCallList(special_block_list
);
320 } else if (block
.state
& BS_DYING
) {
321 x
= block
.x
* DC_GRID_ELEMENT_LENGTH
+ DC_PLAY_OFFSET_X
;
323 // when dying, first we flash
324 if (GC_DYING_DELAY
- block
.alarm
< DC_DYING_FLASH_TIME
) {
326 GLfloat flash
= ((GLfloat
) GC_DYING_DELAY
- block
.alarm
)
327 * (4.0f
/ (GLfloat
) DC_DYING_FLASH_TIME
);
328 if (flash
> 2.0f
) flash
= 4.0f
- flash
;
329 if (flash
> 1.0f
) flash
= 2.0f
- flash
;
331 if (block
.flavor
!= BF_WILD
)
332 glColor3f(block_colors
[block
.flavor
][0]
333 + flash
* (DC_FLASH_COLOR_RED
- block_colors
[block
.flavor
][0]),
334 block_colors
[block
.flavor
][1]
335 + flash
* (DC_FLASH_COLOR_GREEN
- block_colors
[block
.flavor
][1]),
336 block_colors
[block
.flavor
][2]
337 + flash
* (DC_FLASH_COLOR_BLUE
- block_colors
[block
.flavor
][2]));
339 setWildBlockColor(block
, flash
);
341 LightManager::setupBlockLights(x
, y
);
342 glTranslatef(x
, y
, DC_PLAY_OFFSET_Z
);
344 glCallList(block_list
);
346 glCallList(special_block_list
);
348 // then we shrink and spin
350 if (block
.flavor
!= BF_WILD
)
351 glColor3fv(block_colors
[block
.flavor
]);
353 setWildBlockColor(block
, 0.0f
);
355 LightManager::setupBlockLights(x
, y
);
356 glTranslatef(x
, y
, DC_PLAY_OFFSET_Z
);
357 glRotatef((GC_DYING_DELAY
- DC_DYING_FLASH_TIME
- block
.alarm
)
358 * (GC_DYING_DELAY
- DC_DYING_FLASH_TIME
- block
.alarm
)
359 * DC_DYING_ROTATE_SPEED
, block
.axis_x
, block
.axis_y
, 0.0f
);
361 GLfloat scale
= block
.alarm
* DC_DYING_SHRINK_SPEED
362 + DC_DYING_SHRINK_MIN_SIZE
;
363 glScalef(scale
, scale
, scale
);
365 glEnable(rescale_method
);
367 glCallList(block_list
);
369 glCallList(special_block_list
);
370 glDisable(rescale_method
);