Really low graphics patch thanks to Stephan Beyer
[crack-attack.git] / src / DrawLevelLights.cxx
blob3dc8a09ef4923eb3a60887efd450bcb44fdd0ede
1 /*
2 * DrawLevelLights.cxx
3 * Daniel Nelson - 10/13/0
5 * Copyright (C) 2000 Daniel Nelson
6 *
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
22 * 174 W. 18th Ave.
23 * Columbus, OH 43210
25 * Draws the cute level lights.
28 #include <GL/glut.h>
30 #ifndef _WIN32
31 #else
32 # include <glext.h>
33 #endif
35 using namespace std;
37 #include "Game.h"
38 #include "Displayer.h"
39 #include "LevelLights.h"
40 #include "MetaState.h"
42 #define CS_UNDEFINED (0)
43 #define CS_RED (1)
44 #define CS_BLUE (2)
46 const GLfloat ambient[]
47 = { 0.0f, 0.0f, 0.0f, 1.0f };
49 const GLfloat diffuse[]
50 = { 0.0f, 0.0f, 0.0f, 1.0f };
52 const GLfloat specular[]
53 = { 0.8f, 0.8f, 0.8f, 1.0f };
55 void Displayer::drawLevelLights ( )
57 int color_state;
58 int next_color_state;
59 GLfloat death_flash = 0.0f;
60 GLfloat color[3];
62 glColorMaterial(GL_FRONT, GL_EMISSION);
64 glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
65 glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
66 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
67 glMaterialf(GL_FRONT, GL_SHININESS, 2.0f);
69 for (int set = 2; set--; ) {
71 glPushMatrix();
73 if (set == LL_LOCAL_LIGHTS)
74 glTranslatef(DC_LEVEL_LIGHT_LOCAL_OFFSET_X,
75 DC_PLAY_OFFSET_Y + (DC_GRID_ELEMENT_LENGTH / 2.0f), 0.0f);
76 else {
77 glTranslatef(DC_LEVEL_LIGHT_OPPONENT_OFFSET_X,
78 DC_PLAY_OFFSET_Y + (DC_GRID_ELEMENT_LENGTH / 2.0f), 0.0f);
79 glScalef(-1.0f, 1.0f, 1.0f);
82 static int hold_set = 0;
83 if (MetaState::mode & CM_SOLO) {
84 hold_set = set;
85 set = LL_LOCAL_LIGHTS;
88 color_state = CS_UNDEFINED;
90 if (LevelLights::death_flash_alarm[set] != -1) {
91 death_flash = LevelLights::death_flash_alarm[set]
92 * (2.0f / (GLfloat) DC_LEVEL_LIGHT_DEATH_FLASH_TIME);
94 if (death_flash > 1.0f) death_flash = 2.0f - death_flash;
97 for (int n = 0; n < LL_NUMBER_LEVEL_LIGHTS; n++) {
98 LevelLight &light = LevelLights::lights[set][n];
99 color[0] = color[1] = color[2] = 0.0f;
101 if (light.state & LS_RED) {
102 color[0] = DC_LEVEL_LIGHT_RED;
103 next_color_state = CS_RED;
105 } else if (light.state & LS_BLUE) {
106 color[2] = DC_LEVEL_LIGHT_BLUE;
107 next_color_state = CS_BLUE;
109 } else {
110 GLfloat fade = light.fade_alarm
111 * (1.0f / (GLfloat) DC_LEVEL_LIGHT_FADE_TIME);
113 if (light.state & LS_FADE_TO_RED) {
114 color[0] = DC_LEVEL_LIGHT_RED * Game::sqrt(1.0f - fade);
115 color[2] = DC_LEVEL_LIGHT_BLUE * Game::sqrt(fade);
117 } else {
118 color[0] = DC_LEVEL_LIGHT_RED * Game::sqrt(fade);
119 color[2] = DC_LEVEL_LIGHT_BLUE * Game::sqrt(1.0f - fade);
122 next_color_state = CS_UNDEFINED;
125 if (light.state & LS_IMPACT_FLASH) {
126 GLfloat flash = light.flash_alarm
127 * (1.0f / (GLfloat) DC_LEVEL_LIGHT_IMPACT_FLASH_TIME);
129 if (flash > DC_LEVEL_LIGHT_FLASH_INFLECTION)
130 flash = (1.0f - flash)
131 * (1.0f / (1.0f - DC_LEVEL_LIGHT_FLASH_INFLECTION));
132 else
133 flash *= 1.0f / DC_LEVEL_LIGHT_FLASH_INFLECTION;
134 flash *= flash;
136 color[0] += (1.0f - color[0]) * flash;
137 color[1] = flash;
138 color[2] += (1.0f - color[2]) * flash;
140 next_color_state = CS_UNDEFINED;
143 if (LevelLights::death_flash_alarm[set] != -1) {
144 color[0] += (1.0f - color[0]) * death_flash;
145 color[1] += (1.0f - color[1]) * death_flash;
146 color[2] += (1.0f - color[2]) * death_flash;
149 if (next_color_state != color_state || color_state == CS_UNDEFINED) {
150 glColor3fv(color);
151 color_state = next_color_state;
154 glTranslatef(0.0f, DC_GRID_ELEMENT_LENGTH, 0.0f);
156 glCallList(level_light_list);
159 if (MetaState::mode & CM_SOLO)
160 set = hold_set;
162 glPopMatrix();