desktop file ended up in the wrong place.
[crack-attack.git] / src / DrawSwapper.cxx
blob084f1f905fd076487bf15c89ec1a9acd5d1c3b4a
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 #ifndef _WIN32
31 #else
32 # include <glext.h>
33 #endif
35 using namespace std;
37 #include "Game.h"
38 #include "Displayer.h"
39 #include "Swapper.h"
40 #include "LightManager.h"
41 #include "X.h"
43 const GLfloat swapper_colors[4][3]
44 = { { 1.0f, 1.0f, 1.0f }, // normal
45 { 0.85f, 0.85f, 0.0f }, // reverse control
46 { 0.0f, 0.6f, 0.05f }, // invisible swapper
47 { 0.425f, 0.725f, 0.025f } }; // both
49 void Displayer::drawSwapper ( )
51 // blocks have already been drawn, so we use their material calls
53 if (!X::invisibleSwapper())
54 glColor3fv(swapper_colors[Swapper::color]);
56 else {
57 if (!X::needDrawSwapper()) return;
59 glEnable(GL_BLEND);
60 glColor4f(swapper_colors[Swapper::color][0],
61 swapper_colors[Swapper::color][1], swapper_colors[Swapper::color][2],
62 X::swapperAlpha());
65 glPushMatrix();
67 GLfloat x = Swapper::x * DC_GRID_ELEMENT_LENGTH
68 + (DC_PLAY_OFFSET_X + 0.5f * DC_GRID_ELEMENT_LENGTH);
69 GLfloat y = Swapper::y * DC_GRID_ELEMENT_LENGTH + play_offset_y;
71 LightManager::setupGarbageLights(x - (0.5f * DC_GRID_ELEMENT_LENGTH), y,
72 1, 2);
74 if (Swapper::state & SS_SWAPPING) {
76 glTranslatef(x, y, DC_PLAY_OFFSET_Z);
77 glRotatef(180.0f * Swapper::swap_factor, 0.0f, 1.0f, 0.0f);
79 glPushMatrix();
81 glTranslatef(-DC_SWAPPER_GRAB_LENGTH, DC_SWAPPER_GRAB_LENGTH, 0.0f);
82 glCallList(swapper_list);
84 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH,
85 -2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f);
86 glScalef(-1.0f, -1.0f, 1.0f);
87 glCallList(swapper_list);
89 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f, 0.0f);
90 glScalef(-1.0f, 1.0f, 1.0f);
91 glCallList(swapper_list);
93 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH,
94 -2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f);
95 glScalef(-1.0f, -1.0f, 1.0f);
96 glCallList(swapper_list);
98 glPopMatrix();
100 glScalef(1.0f, 1.0f, -1.0f);
102 glTranslatef(-DC_SWAPPER_GRAB_LENGTH, DC_SWAPPER_GRAB_LENGTH, 0.0f);
103 glCallList(swapper_list);
105 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH,
106 -2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f);
107 glScalef(-1.0f, -1.0f, 1.0f);
108 glCallList(swapper_list);
110 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f, 0.0f);
111 glScalef(-1.0f, 1.0f, 1.0f);
112 glCallList(swapper_list);
114 glTranslatef(2.0f * DC_SWAPPER_GRAB_LENGTH,
115 -2.0f * DC_SWAPPER_GRAB_LENGTH, 0.0f);
116 glScalef(-1.0f, -1.0f, 1.0f);
117 glCallList(swapper_list);
119 glPopMatrix();
121 return;
124 if (Swapper::state & SS_MOVE_PAUSE) {
125 GLfloat shift = (Game::time_step - Swapper::move_pause_alarm)
126 * (1.0f / (GLfloat) GC_MOVE_DELAY);
127 shift *= shift;
129 if ((Swapper::state & SS_MOVE_MASK) & SS_MOVE_LEFT)
130 x += shift;
131 else if ((Swapper::state & SS_MOVE_MASK) & SS_MOVE_RIGHT)
132 x -= shift;
133 else if ((Swapper::state & SS_MOVE_MASK) & SS_MOVE_UP)
134 y -= shift;
135 else
136 y += shift;
139 glTranslatef(x, y, DC_PLAY_OFFSET_Z);
141 glCallList(swapper_list);
143 glScalef(-1.0f, -1.0f, 1.0f);
144 glCallList(swapper_list);
146 glScalef(-1.0f, 1.0f, 1.0f);
147 glCallList(swapper_list);
149 glScalef(-1.0f, -1.0f, 1.0f);
150 glCallList(swapper_list);
152 glPopMatrix();
154 if (X::invisibleSwapper())
155 glDisable(GL_BLEND);