Didn't set the version as a string
[crack-attack.git] / src / CelebrationManager.cxx
bloba07b45a9e6063ca307cba26ce14fe410c412f080
1 /*
2 * CelebrationManager.cxx
3 * Daniel Nelson - 10/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 * Handles the celebration after a game.
28 #include "Game.h"
29 #include "MetaState.h"
30 #include "Displayer.h"
31 #include "CelebrationManager.h"
32 #include "SparkleManager.h"
33 #include "MessageManager.h"
34 #include "WinRecord.h"
35 #include "Random.h"
36 #include "Score.h"
38 using namespace std;
40 bool CelebrationManager::draw_game;
41 GLfloat CelebrationManager::light_level;
42 int CelebrationManager::spark_rate[DC_CSPARK_SOURCE_NUMBER];
43 int CelebrationManager::spark_color[DC_CSPARK_SOURCE_NUMBER];
45 float CelebrationManager::win_alpha;
46 float CelebrationManager::win_scale;
47 int CelebrationManager::win_flash1;
48 int CelebrationManager::win_flash2;
50 float CelebrationManager::loss_height;
51 float CelebrationManager::loss_velocity;
52 bool CelebrationManager::loss_rescale;
53 int CelebrationManager::loss_bounce_count;
55 void CelebrationManager::gameFinish ( )
57 draw_game = true;
58 light_level = 1.0f;
60 MessageManager::mode = MM_CELEBRATION;
62 if (WinRecord::won) {
63 win_alpha = 0.0f;
64 win_scale = DC_STARTING_WIN_SCALE;
65 MessageManager::readyMessage(MS_WINNER);
67 } else {
68 loss_height = DC_STARTING_LOSS_HEIGHT;
69 loss_velocity = 0.0f;
70 loss_bounce_count = DC_STARTING_BOUNCE_COUNT;
72 if (WinRecord::isMatchFinished()) {
73 MessageManager::readyMessage(MS_GAME_OVER);
74 loss_rescale = true;
76 } else {
77 MessageManager::readyMessage(MS_LOSER);
78 loss_rescale = false;
83 void CelebrationManager::celebrationFinish ( )
85 draw_game = false;
87 MessageManager::mode = MM_NORMAL;
88 MessageManager::freeMessage();
91 void CelebrationManager::timeStep ( )
93 if (WinRecord::current_game == -1) return;
95 // fade out the game
96 if (Game::time_step < DC_CELEBRATION_FADE_TIME)
97 light_level = (DC_CELEBRATION_FADE_TIME
98 - Game::time_step) * (1.0f / (float) DC_CELEBRATION_FADE_TIME);
100 else if (Game::time_step == DC_CELEBRATION_FADE_TIME)
101 light_level = 0.0f;
103 // signal that the user is now allowed to end the celebration
104 else if (Game::time_step == DC_CELEBRATION_TIME)
105 MetaState::celebrationComplete();
107 // draw the game until the fade out is complete and no light motes exist
108 if (draw_game && !(Game::time_step < DC_CELEBRATION_FADE_TIME
109 || SparkleManager::mote_count > 0))
110 draw_game = false;
112 // handle the message behavior
114 // if we won
115 if (WinRecord::won) {
117 // fade in
118 if (Game::time_step < DC_WIN_FADE_TIME) {
119 win_alpha += 1.0f / (float) DC_WIN_FADE_TIME;
120 win_scale -= (DC_STARTING_WIN_SCALE - 1.0f) / (float) DC_WIN_FADE_TIME;
122 // reach static state
123 } else if (Game::time_step == DC_WIN_FADE_TIME) {
124 win_alpha = 1.0f;
125 win_scale = 1.0f;
126 win_flash1 = DC_WIN_FLASH_1_TIME;
127 win_flash2 = DC_WIN_FLASH_2_TIME;
129 spark_rate[DC_CSPARK_SOURCE_NUMBER - 1] = DC_CSPARK_FULL_RATE;
130 spark_color[DC_CSPARK_SOURCE_NUMBER - 1]
131 = Random::number(DC_CSPARK_COLOR_NUMBER);
132 for (int n = DC_CSPARK_SOURCE_NUMBER - 1; n--; ) {
133 spark_rate[n] = DC_CSPARK_STARTING_RATE;
134 spark_color[n] = Random::number(DC_CSPARK_COLOR_NUMBER);
137 } else {
139 // flash...
141 if (win_flash1)
142 win_flash1--;
143 if (Random::chanceIn(DC_WIN_FLASH_1_CHANCE_IN))
144 if (win_flash1) {
145 if (win_flash1 < DC_WIN_FLASH_1_TIME / 2)
146 win_flash1 = (DC_WIN_FLASH_1_TIME / 2) - win_flash1;
147 } else
148 win_flash1 = DC_WIN_FLASH_1_TIME;
150 if (win_flash2)
151 win_flash2--;
152 if (Random::chanceIn(DC_WIN_FLASH_2_CHANCE_IN))
153 if (win_flash2) {
154 if (win_flash2 < DC_WIN_FLASH_2_TIME / 2)
155 win_flash2 = (DC_WIN_FLASH_2_TIME / 2) - win_flash2;
156 } else
157 win_flash2 = DC_WIN_FLASH_2_TIME;
159 // and, if you've been really good, spark
160 if (WinRecord::isMatchFinished()
161 && (!(MetaState::mode & CM_SOLO) || Score::topRank())) {
163 // this algorithm is supposed to cause the sparks to be created in
164 // spurts, sort of like a sputtering firework
166 for (int n = DC_CSPARK_SOURCE_NUMBER; n--; ) {
167 if (spark_rate[n] > DC_CSPARK_LOW_RATE)
168 spark_rate[n] -= DC_CSPARK_QUICK_RATE_DROP;
169 else if (spark_rate[n] > 0)
170 spark_rate[n]--;
172 if (Random::chanceIn(DC_CSPARK_BOOST_CHANCE_IN)) {
173 spark_rate[n] += DC_CSPARK_RATE_BOOST;
174 if (Random::chanceIn(DC_CSPARK_COLOR_CHANGE_CHANCE_IN))
175 spark_color[n] = Random::number(DC_CSPARK_COLOR_NUMBER);
178 if (Random::number(DC_CSPARK_FULL_RATE) < spark_rate[n])
179 SparkleManager::createCelebrationSpark(n, spark_color[n]);
184 // if we lost
185 } else {
187 // drop the sign
189 if (loss_bounce_count != DC_FINAL_BOUNCE_COUNT - 1) {
191 loss_height += loss_velocity;
192 loss_velocity += -DC_LOSS_GRAVITY - DC_LOSS_DRAG * loss_velocity;
194 // if we've hit bottom
195 if (loss_height < 0.0f) {
197 // if it's the last bounce
198 if (loss_bounce_count == DC_FINAL_BOUNCE_COUNT) {
199 loss_bounce_count--;
200 loss_velocity = 0.0f;
201 loss_height = 0.0f;
203 // otherwise, bounce
204 } else {
206 // near the final bounce, reduce the elasticity
207 if (loss_velocity > -DC_LOSS_MIN_VELOCITY) {
208 loss_bounce_count--;
209 loss_velocity = -DC_LOSS_END_BOUNCE_ELASTICITY
210 * loss_bounce_count * loss_velocity;
211 loss_height = -loss_height;
213 } else {
214 loss_height = -loss_height;
215 loss_velocity = -DC_LOSS_BOUNCE_ELASTICITY * loss_velocity;