Each module now includes its own header first. Removed sstream.h and the definition...
[crack-attack.git] / src / DrawSwapper.cxx
blob3d62fc576a37d64e5b38f2c18b9a267628f2bd45
1 /*
2 * DrawSwapper.cxx
3 * Daniel Nelson - 9/30/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 swapper thing.
28 #include <GL/glut.h>
30 #include "glext.h"
32 #include "Game.h"
33 #include "Displayer.h"
34 #include "Swapper.h"
35 #include "LightManager.h"
36 #include "X.h"
38 const GLfloat swapper_colors[4][3]
39 = { { 1.0f, 1.0f, 1.0f }, // normal
40 { 0.85f, 0.85f, 0.0f }, // reverse control
41 { 0.0f, 0.6f, 0.05f }, // invisible swapper
42 { 0.425f, 0.725f, 0.025f } }; // both
44 void Displayer::drawSwapper ( )
46 // blocks have already been drawn, so we use their material calls
48 if (!X::invisibleSwapper())
49 glColor3fv(swapper_colors[Swapper::color]);
51 else {
52 if (!X::needDrawSwapper()) return;
54 glEnable(GL_BLEND);
55 glColor4f(swapper_colors[Swapper::color][0],
56 swapper_colors[Swapper::color][1], swapper_colors[Swapper::color][2],
57 X::swapperAlpha());
60 glPushMatrix();
62 GLfloat x = Swapper::x * DC_GRID_ELEMENT_LENGTH
63 + (DC_PLAY_OFFSET_X + 0.5f * DC_GRID_ELEMENT_LENGTH);
64 GLfloat y = Swapper::y * DC_GRID_ELEMENT_LENGTH + play_offset_y;
66 LightManager::setupGarbageLights(x - (0.5f * DC_GRID_ELEMENT_LENGTH), y,
67 1, 2);
69 if (Swapper::state & SS_SWAPPING) {
71 glTranslatef(x, y, DC_PLAY_OFFSET_Z);
72 glRotatef(180.0f * Swapper::swap_factor, 0.0f, 1.0f, 0.0f);
74 glPushMatrix();
76 glTranslatef(-DC_SWAPPER_GRAB_LENGTH, DC_SWAPPER_GRAB_LENGTH, 0.0f);
77 glCallList(swapper_list);
79 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH,
80 -2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f);
81 glScalef(-1.0f, -1.0f, 1.0f);
82 glCallList(swapper_list);
84 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f, 0.0f);
85 glScalef(-1.0f, 1.0f, 1.0f);
86 glCallList(swapper_list);
88 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH,
89 -2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f);
90 glScalef(-1.0f, -1.0f, 1.0f);
91 glCallList(swapper_list);
93 glPopMatrix();
95 glScalef(1.0f, 1.0f, -1.0f);
97 glTranslatef(-DC_SWAPPER_GRAB_LENGTH, DC_SWAPPER_GRAB_LENGTH, 0.0f);
98 glCallList(swapper_list);
100 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH,
101 -2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f);
102 glScalef(-1.0f, -1.0f, 1.0f);
103 glCallList(swapper_list);
105 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f, 0.0f);
106 glScalef(-1.0f, 1.0f, 1.0f);
107 glCallList(swapper_list);
109 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH,
110 -2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f);
111 glScalef(-1.0f, -1.0f, 1.0f);
112 glCallList(swapper_list);
114 glPopMatrix();
116 return;
119 if (Swapper::state & SS_MOVE_PAUSE) {
120 GLfloat shift = (Game::time_step - Swapper::move_pause_alarm)
121 * (1.0f / (GLfloat) GC_MOVE_DELAY);
122 shift *= shift;
124 if ((Swapper::state & SS_MOVE_MASK) & SS_MOVE_LEFT)
125 x += shift;
126 else if ((Swapper::state & SS_MOVE_MASK) & SS_MOVE_RIGHT)
127 x -= shift;
128 else if ((Swapper::state & SS_MOVE_MASK) & SS_MOVE_UP)
129 y -= shift;
130 else
131 y += shift;
134 glTranslatef(x, y, DC_PLAY_OFFSET_Z);
136 glCallList(swapper_list);
138 glScalef(-1.0f, -1.0f, 1.0f);
139 glCallList(swapper_list);
141 glScalef(-1.0f, 1.0f, 1.0f);
142 glCallList(swapper_list);
144 glScalef(-1.0f, -1.0f, 1.0f);
145 glCallList(swapper_list);
147 glPopMatrix();
149 if (X::invisibleSwapper())
150 glDisable(GL_BLEND);