2 * CelebrationManager.cxx
3 * Daniel Nelson - 10/30/0
5 * Copyright (C) 2000 Daniel Nelson
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
25 * Handles the celebration after a game.
29 #include "MetaState.h"
30 #include "Displayer.h"
31 #include "CelebrationManager.h"
32 #include "SparkleManager.h"
33 #include "MessageManager.h"
34 #include "WinRecord.h"
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 ( )
60 MessageManager::mode
= MM_CELEBRATION
;
64 win_scale
= DC_STARTING_WIN_SCALE
;
65 MessageManager::readyMessage(MS_WINNER
);
68 loss_height
= DC_STARTING_LOSS_HEIGHT
;
70 loss_bounce_count
= DC_STARTING_BOUNCE_COUNT
;
72 if (WinRecord::isMatchFinished()) {
73 MessageManager::readyMessage(MS_GAME_OVER
);
77 MessageManager::readyMessage(MS_LOSER
);
83 void CelebrationManager::celebrationFinish ( )
87 MessageManager::mode
= MM_NORMAL
;
88 MessageManager::freeMessage();
91 void CelebrationManager::timeStep ( )
93 if (WinRecord::current_game
== -1) return;
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
)
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))
112 // handle the message behavior
115 if (WinRecord::won
) {
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
) {
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
);
143 if (Random::chanceIn(DC_WIN_FLASH_1_CHANCE_IN
))
145 if (win_flash1
< DC_WIN_FLASH_1_TIME
/ 2)
146 win_flash1
= (DC_WIN_FLASH_1_TIME
/ 2) - win_flash1
;
148 win_flash1
= DC_WIN_FLASH_1_TIME
;
152 if (Random::chanceIn(DC_WIN_FLASH_2_CHANCE_IN
))
154 if (win_flash2
< DC_WIN_FLASH_2_TIME
/ 2)
155 win_flash2
= (DC_WIN_FLASH_2_TIME
/ 2) - win_flash2
;
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)
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
]);
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
) {
200 loss_velocity
= 0.0f
;
206 // near the final bounce, reduce the elasticity
207 if (loss_velocity
> -DC_LOSS_MIN_VELOCITY
) {
209 loss_velocity
= -DC_LOSS_END_BOUNCE_ELASTICITY
210 * loss_bounce_count
* loss_velocity
;
211 loss_height
= -loss_height
;
214 loss_height
= -loss_height
;
215 loss_velocity
= -DC_LOSS_BOUNCE_ELASTICITY
* loss_velocity
;