Make autopackage work
[crack-attack.git] / src / WinRecord.cxx
blob43053d481abdfdf15c11ae41c7e1cf78e72af8fd
1 /*
2 * WinRecord.cxx
3 * Daniel Nelson - 10/22/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 * Handles the win/loss record.
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 "WinRecord.h"
39 #include "Displayer.h"
40 #include "Random.h"
42 int WinRecord::current_game;
43 bool WinRecord::won;
44 bool WinRecord::concession;
45 int WinRecord::games_won;
46 int WinRecord::games_lost;
47 int WinRecord::record[GC_GAMES_PER_MATCH];
49 Star WinRecord::stars[GC_GAMES_PER_MATCH];
50 int WinRecord::dynamic_star;
51 int WinRecord::displaced_star;
52 GLfloat WinRecord::win_star_x;
53 GLfloat WinRecord::win_star_y;
54 GLfloat WinRecord::win_star_v_x;
55 GLfloat WinRecord::win_star_v_y;
56 GLfloat WinRecord::old_star_a;
57 GLfloat WinRecord::old_star_size;
58 bool WinRecord::draw_old_star;
60 void WinRecord::initialize ( )
62 for (int n = GC_GAMES_PER_MATCH; n--; )
63 record[n] = GR_NOT_PLAYED;
64 current_game = -1;
65 concession = false;
66 games_won = 0;
67 games_lost = 0;
69 dynamic_star = -1;
70 displaced_star = -1;
71 for (int n = GC_GAMES_PER_MATCH; n--; )
72 stars[n].a = 0.0f;
75 void WinRecord::gameStart ( )
77 if (MetaState::mode & CM_SOLO)
78 current_game = 1;
79 else
80 current_game++;
82 record[current_game] = GR_BEING_PLAYED;
85 void WinRecord::gameWon ( )
87 won = true;
88 games_won++;
89 record[current_game] = GR_WON;
91 if (MetaState::mode & CM_REALLY_LOW_GRAPHICS) {
92 // The star will disappear and pop into existance in the play area. After a
93 // few moments, it will fly to it's original location.
95 // record star's old location; for a time, two stars will be drawn, as one
96 // pops in and the other pops away
97 draw_old_star = true;
98 old_star_a = stars[current_game].a;
99 old_star_size = 5.0f;
101 // displace the star into the play area and set it's starting parameters
102 displaced_star = current_game;
103 stars[current_game].a = DC_STAR_WIN_MIN_ANGULAR_DEVIATION
104 + DC_STAR_WIN_SPREAD_ANGULAR_DEVIATION * Random::number();
105 if (Random::chanceIn2(2))
106 stars[current_game].a = -stars[current_game].a;
107 stars[current_game].v_a = 0.0f;
108 stars[current_game].size = 0.0f;
109 stars[current_game].v_size = 0.0f;
110 win_star_x = (-DC_LEFT_EXTERNAL_CENTER + DC_STAR_DISPLACEMENT
111 * (GC_GAMES_PER_MATCH - 1) / 2.0f + DC_STAR_WIN_OFFSET_X)
112 - DC_STAR_DISPLACEMENT * current_game;
114 if (MetaState::mode & CM_SOLO)
115 win_star_y = -DC_STAR_OFFSET_Y + DC_STAR_WIN_SOLO_OFFSET_Y;
116 else
117 win_star_y = -DC_STAR_OFFSET_Y + DC_STAR_WIN_OFFSET_Y;
119 // set the kick velocity; choice of two aesthetically pleasing preset values
120 // or, for variety, a random 270 degree arc
121 switch (Random::number(3)) {
122 case 0:
123 win_star_v_x = DC_STAR_WIN_PRESET_1_VELOCITY_X;
124 win_star_v_y = DC_STAR_WIN_PRESET_1_VELOCITY_Y;
125 break;
126 case 1:
127 win_star_v_x = DC_STAR_WIN_PRESET_2_VELOCITY_X;
128 win_star_v_y = DC_STAR_WIN_PRESET_2_VELOCITY_Y;
129 break;
130 default:
131 // too infrequent to warrent a random direction table
132 float v = DC_STAR_WIN_MIN_VELOCITY
133 + DC_STAR_WIN_SPREAD_VELOCITY * Random::number();
134 float angle = Random::number() * (3.0f * PI / 2.0f) - (PI / 2.0f);
135 win_star_v_x = v * cos(angle);
136 win_star_v_y = v * sin(angle);
137 break;
142 void WinRecord::gameLoss ( )
144 won = false;
145 games_lost++;
146 record[current_game] = GR_LOST;
149 void WinRecord::timeStep ( )
151 for (int n = GC_GAMES_PER_MATCH; n--; ) {
152 Star &star = stars[n];
154 switch (record[n]) {
156 // game being played
157 case GR_BEING_PLAYED:
158 if (Game::time_step >= GC_START_PAUSE_DELAY)
159 star.a += DC_STAR_PLAY_ANGULAR_VELOCITY;
160 else
161 star.a += Game::time_step
162 * (DC_STAR_PLAY_ANGULAR_VELOCITY / (float) GC_START_PAUSE_DELAY);
163 break;
165 // game has been lost
166 case GR_LOST:
167 if (current_game == n && Game::time_step < DC_CELEBRATION_TIME)
168 star.a += (DC_CELEBRATION_TIME - Game::time_step)
169 * (DC_STAR_PLAY_ANGULAR_VELOCITY / (float) DC_CELEBRATION_TIME);
170 break;
172 // game has been won
173 case GR_WON:
174 // wait for win message to hit before dynamics
175 if (current_game != n || Game::time_step > DC_WIN_FADE_TIME) {
177 star.size += star.v_size;
178 if (star.size < 0.0f) star.size = 0.0f;
179 star.v_size += -DC_STAR_WIN_SIZE_DRAG * star.v_size
180 - DC_STAR_WIN_SIZE_SPRING * (star.size - DC_STAR_SIZE_EQUILIBRIUM);
182 if (fabs(star.v_size) < DC_STAR_WIN_SIZE_EPSILON
183 && Random::chanceIn(DC_STAR_WIN_SIZE_PULSE_CHANCE_IN))
184 star.v_size += DC_STAR_WIN_SIZE_PULSE_VELOCITY * Random::number();
186 star.v_a += -DC_STAR_WIN_ANGULAR_SPRING * star.a;
188 star.a += star.v_a;
190 // begin motion
191 if (Game::time_step == DC_WIN_FADE_TIME + DC_STAR_WIN_KICK_DELAY
192 && current_game == n) {
193 displaced_star = -1;
194 dynamic_star = n;
197 // if we're dynamic;
198 if (dynamic_star == n) {
199 win_star_x += win_star_v_x;
200 win_star_y += win_star_v_y;
202 win_star_v_x += -DC_STAR_WIN_SPRING * win_star_x
203 - DC_STAR_WIN_DRAG * win_star_v_x;
204 win_star_v_y += -DC_STAR_WIN_SPRING * win_star_y
205 - DC_STAR_WIN_DRAG * win_star_v_y;
207 // if we're there, stop being dynamic
208 if (fabs(win_star_v_x) < DC_STAR_WIN_VELOCITY_EPSILON
209 && fabs(win_star_v_y) < DC_STAR_WIN_VELOCITY_EPSILON
210 && fabs(win_star_x) < DC_STAR_WIN_EPSILON
211 && fabs(win_star_y) < DC_STAR_WIN_EPSILON)
212 dynamic_star = -1;
216 // shrink the old star as the new one apears
217 if (draw_old_star && current_game == n) {
218 if (star.size < DC_STAR_SIZE_EQUILIBRIUM) {
219 old_star_size = DC_STAR_SIZE_EQUILIBRIUM - star.size;
220 old_star_a += DC_STAR_PLAY_ANGULAR_VELOCITY;
221 } else
222 draw_old_star = false;
225 break;