3 * Daniel Nelson - 9/4/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 all the pretty sparkles!
28 #include "SparkleManager.h"
31 #include "Displayer.h"
32 #include "MetaState.h"
35 int SparkleManager::spark_count
;
36 Spark
SparkleManager::sparks
[DC_MAX_SPARK_NUMBER
];
38 int SparkleManager::mote_count
;
39 Mote
SparkleManager::motes
[DC_MAX_MOTE_NUMBER
];
41 const int SparkleManager::mote_colors
[DC_NUMBER_MOTE_LEVELS
]
42 = { 0, 0, 0, 4, 5, 6, 7, 8, 9, 10, 11,
43 0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 3 };
45 const int SparkleManager::mote_light_colors
[DC_NUMBER_MOTE_LEVELS
]
46 = { 0, 0, 0, 0, 1, 0, 2, 3, 4, 5, 6,
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
49 const int SparkleManager::mote_types
[DC_NUMBER_MOTE_LEVELS
]
50 = { MT_FOUR_POINTED_STAR
, MT_FIVE_POINTED_STAR
,
51 MT_SIX_POINTED_STAR
, MT_SPECIAL_STAR
, MT_SPECIAL_STAR
, MT_SPECIAL_STAR
,
52 MT_SPECIAL_STAR
, MT_SPECIAL_STAR
, MT_SPECIAL_STAR
, MT_SPECIAL_STAR
,
53 MT_SPECIAL_STAR
, MT_MULTIPLIER_ONE_STAR
, MT_MULTIPLIER_TWO_STAR
,
54 MT_MULTIPLIER_THREE_STAR
, MT_MULTIPLIER_THREE_STAR
,
55 MT_MULTIPLIER_THREE_STAR
, MT_MULTIPLIER_THREE_STAR
,
56 MT_MULTIPLIER_THREE_STAR
, MT_MULTIPLIER_THREE_STAR
,
57 MT_MULTIPLIER_THREE_STAR
, MT_MULTIPLIER_THREE_STAR
,
58 MT_MULTIPLIER_THREE_STAR
};
60 const GLfloat
SparkleManager::mote_sizes
[DC_NUMBER_MOTE_LEVELS
]
61 = { 2.0f
, 2.8f
, 2.8f
, 3.4f
, 3.4f
, 3.4f
, 3.4f
, 3.4f
, 3.4f
, 3.4f
, 3.4f
,
62 4.0f
, 2.6f
, 3.5f
, 3.7f
, 3.9f
, 4.1f
, 4.3f
, 4.5f
, 4.7f
, 4.9f
, 5.1f
};
64 const float SparkleManager::mote_inverse_masses
[DC_NUMBER_MOTE_LEVELS
]
65 = { 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
,
66 1.0f
, 1.0f
, 1.0f
, 1.0f
, 1.0f
/ 1.4f
, 1.0f
/ 1.8f
, 1.0f
/ 2.2f
,
67 1.0f
/ 2.6f
, 1.0f
/ 3.0f
, 1.0f
/ 3.4f
, 1.0f
/ 3.8f
, 1.0f
/ 4.2f
};
69 void SparkleManager::initialize ( )
72 for (int n
= DC_MAX_SPARK_NUMBER
; n
--; )
73 sparks
[n
].active
= false;
76 for (int n
= DC_MAX_MOTE_NUMBER
; n
--; )
77 motes
[n
].active
= false;
80 void SparkleManager::createBlockDeathSpark ( int x
, int y
, int color
, int n
)
83 if (spark_count
== DC_MAX_SPARK_NUMBER
) return;
86 for (n
= 0; sparks
[n
].active
; n
++);
87 Spark
&spark
= sparks
[n
];
91 spark
.x
= x
* DC_GRID_ELEMENT_LENGTH
+ DC_PLAY_OFFSET_X
;
92 spark
.y
= y
* DC_GRID_ELEMENT_LENGTH
+ Displayer::play_offset_y
;
94 float v
= DC_MIN_SPARK_VELOCITY
+ (Random::number() + Random::number())
95 * (0.5f
* (DC_MAX_SPARK_VELOCITY
- DC_MIN_SPARK_VELOCITY
));
96 Random::deathSparkAngle(spark
.v_x
, spark
.v_y
);
100 spark
.a
= Random::number(360);
101 spark
.v_a
= DC_MIN_SPARK_ANGULAR_VELOCITY
102 + (Random::number() + Random::number())
103 * (0.5f
* (DC_MAX_SPARK_ANGULAR_VELOCITY
- DC_MIN_SPARK_ANGULAR_VELOCITY
));
104 if (Random::chanceIn2(2))
105 spark
.v_a
= -spark
.v_a
;
107 switch (Random::number2(4)) {
109 spark
.size
= DC_MIN_SPARK_SIZE
;
112 spark
.size
= DC_MIN_SPARK_SIZE
+ Random::number()
113 * (1.0f
- DC_MIN_SPARK_SIZE
);
122 if (Random::chanceIn(DC_CHANCE_LONG_SPARK_LIFE_TIME
))
123 spark
.life_time
= Random::number(10 * DC_SPREAD_SPARK_LIFE_TIME
)
124 + Random::number(10 * DC_SPREAD_SPARK_LIFE_TIME
)
125 + 10 * (DC_MEDIUM_SPARK_LIFE_TIME
- DC_SPREAD_SPARK_LIFE_TIME
);
127 spark
.life_time
= Random::number(DC_SPREAD_SPARK_LIFE_TIME
)
128 + Random::number(DC_SPREAD_SPARK_LIFE_TIME
)
129 + (DC_MEDIUM_SPARK_LIFE_TIME
- DC_SPREAD_SPARK_LIFE_TIME
);
133 void SparkleManager::createCelebrationSpark ( int source
, int color
)
135 if (spark_count
== DC_MAX_SPARK_NUMBER
) return;
138 for (n
= 0; sparks
[n
].active
; n
++);
139 Spark
&spark
= sparks
[n
];
146 Random::celebrationSpark1Angle(spark
.v_x
, spark
.v_y
);
147 v
= DC_MIN_CSPARK_VELOCITY
+ DC_SPREAD_CSPARK_VELOCITY
* Random::number();
149 Random::celebrationSpark2Angle(spark
.v_x
, spark
.v_y
);
150 v
= (2.0f
* DC_MIN_CSPARK_VELOCITY
)
151 + (2.0f
* DC_SPREAD_CSPARK_VELOCITY
) * Random::number();
158 if (MetaState::mode
& CM_SOLO
) {
159 spark
.x
= DC_PLAY_OFFSET_X
+ DC_SOURCE_1_SOLO_OFFSET_X
;
160 spark
.y
= DC_PLAY_OFFSET_Y
+ DC_SOURCE_1_SOLO_OFFSET_Y
;
162 spark
.x
= DC_PLAY_OFFSET_X
+ DC_SOURCE_1_OFFSET_X
;
163 spark
.y
= DC_PLAY_OFFSET_Y
+ DC_SOURCE_1_OFFSET_Y
;
167 spark
.x
= DC_PLAY_OFFSET_X
+ DC_SOURCE_2_OFFSET_X
;
168 spark
.y
= DC_PLAY_OFFSET_Y
+ DC_SOURCE_2_OFFSET_Y
;
171 if (MetaState::mode
& CM_SOLO
) {
172 spark
.x
= DC_PLAY_OFFSET_X
+ DC_SOURCE_3_SOLO_OFFSET_X
;
173 spark
.y
= DC_PLAY_OFFSET_Y
+ DC_SOURCE_3_SOLO_OFFSET_Y
;
175 spark
.x
= DC_PLAY_OFFSET_X
+ DC_SOURCE_3_OFFSET_X
;
176 spark
.y
= DC_PLAY_OFFSET_Y
+ DC_SOURCE_3_OFFSET_Y
;
178 spark
.v_x
= -spark
.v_x
;
181 spark
.x
= DC_PLAY_OFFSET_X
+ DC_SOURCE_4_OFFSET_X
;
182 spark
.y
= DC_PLAY_OFFSET_Y
+ DC_SOURCE_4_OFFSET_Y
;
183 spark
.v_x
= -spark
.v_x
;
186 if (MetaState::mode
& CM_SOLO
) {
187 spark
.x
= DC_PLAY_OFFSET_X
+ DC_SOURCE_5_SOLO_OFFSET_X
;
188 spark
.y
= DC_PLAY_OFFSET_Y
+ DC_SOURCE_5_SOLO_OFFSET_Y
;
190 spark
.x
= DC_PLAY_OFFSET_X
+ DC_SOURCE_5_OFFSET_X
;
191 spark
.y
= DC_PLAY_OFFSET_Y
+ DC_SOURCE_5_OFFSET_Y
;
196 spark
.a
= Random::number(360);
197 spark
.v_a
= DC_MIN_SPARK_ANGULAR_VELOCITY
198 + (Random::number() + Random::number())
199 * (0.5f
* (DC_MAX_SPARK_ANGULAR_VELOCITY
- DC_MIN_SPARK_ANGULAR_VELOCITY
));
200 if (Random::chanceIn2(2))
201 spark
.v_a
= -spark
.v_a
;
203 if (Random::chanceIn(3))
204 spark
.size
= DC_MIN_SPARK_SIZE
205 + Random::number() * (1.0f
- DC_MIN_SPARK_SIZE
);
207 spark
.size
= DC_MIN_SPARK_SIZE
;
211 if (Random::chanceIn(DC_CHANCE_LONG_SPARK_LIFE_TIME
))
212 spark
.life_time
= Random::number(10 * DC_SPREAD_SPARK_LIFE_TIME
)
213 + Random::number(10 * DC_SPREAD_SPARK_LIFE_TIME
)
214 + 10 * (DC_MEDIUM_SPARK_LIFE_TIME
- DC_SPREAD_SPARK_LIFE_TIME
);
216 spark
.life_time
= Random::number(DC_SPREAD_SPARK_LIFE_TIME
)
217 + Random::number(DC_SPREAD_SPARK_LIFE_TIME
)
218 + (DC_MEDIUM_SPARK_LIFE_TIME
- DC_SPREAD_SPARK_LIFE_TIME
);
221 void SparkleManager::createRewardMote ( int x
, int y
, int level
,
224 if (mote_count
== DC_MAX_MOTE_NUMBER
) return;
227 for (n
= 0; motes
[n
].active
; n
++);
228 Mote
&mote
= motes
[n
];
236 if (level
>= DC_NUMBER_MOTE_LEVELS
)
237 level
= DC_NUMBER_MOTE_LEVELS
- 1;
238 mote
.color
= mote_colors
[level
];
239 mote
.light_color
= mote_light_colors
[level
];
240 mote
.type
= mote_types
[level
];
241 mote
.size
= mote_sizes
[level
];
242 mote
.inverse_mass
= mote_inverse_masses
[level
];
244 mote
.x
= x
* DC_GRID_ELEMENT_LENGTH
+ DC_PLAY_OFFSET_X
245 - (DC_GRID_ELEMENT_LENGTH
/ 2.0f
)
246 + (float) Random::number(20) * ((float) DC_GRID_ELEMENT_LENGTH
/ 20.0f
);
247 mote
.y
= y
* DC_GRID_ELEMENT_LENGTH
+ Displayer::play_offset_y
248 - (DC_GRID_ELEMENT_LENGTH
/ 2.0f
)
249 + (float) Random::number(20) * ((float) DC_GRID_ELEMENT_LENGTH
/ 20.0f
);
251 // slow down big ones
252 float v
= (DC_MEDIUM_MOTE_VELOCITY
- DC_SPREAD_MOTE_VELOCITY
253 + Random::number() * (2.0f
* DC_SPREAD_MOTE_VELOCITY
)) * mote
.inverse_mass
;
254 if (x
< GC_PLAY_WIDTH
/ 2)
255 mote
.v_x
= -0.707107 * v
;
257 mote
.v_x
= 0.707107 * v
;
258 mote
.v_y
= -0.707107 * v
;
260 mote
.a
= mote
.initial_a
= Random::number(360);
261 mote
.v_a
= (DC_MEDIUM_MOTE_ANGULAR_VELOCITY
262 - DC_SPREAD_MOTE_ANGULAR_VELOCITY
+ Random::number()
263 * (2.0f
* DC_SPREAD_MOTE_ANGULAR_VELOCITY
)) * mote
.inverse_mass
;
264 if (Random::chanceIn2(2))
265 mote
.v_a
= -mote
.v_a
;
268 mote
.sibling_delay
= sibling_number
* DC_MULTI_MOTE_FIRE_DELAY
;
270 mote
.associated_light
= -1;
273 void SparkleManager::timeStep ( )
276 for (int n
= 0; c
; n
++)
277 if (sparks
[n
].active
) {
278 Spark
&spark
= sparks
[n
];
281 if (--spark
.life_time
== 0) {
282 spark
.active
= false;
286 spark
.x
+= spark
.v_x
;
287 spark
.y
+= spark
.v_y
;
289 spark
.a
+= spark
.v_a
;
291 spark
.v_y
-= DC_SPARK_GRAVITY
+ DC_SPARK_DRAG
* spark
.v_y
;
292 spark
.v_x
-= DC_SPARK_DRAG
* spark
.v_x
;
297 for (int n
= 0; c
; n
++)
298 if (motes
[n
].active
) {
299 Mote
&mote
= motes
[n
];
302 if (mote
.life_time
>= 0)
303 if (++mote
.life_time
- mote
.sibling_delay
< GC_DYING_DELAY
) {
305 if (mote
.life_time
<= GC_DYING_DELAY
)
306 mote
.brightness
= DC_MAX_MOTE_LIGHT_BRIGHTNESS
307 * mote
.life_time
* (1.0f
/ (float) GC_DYING_DELAY
);
311 else if (mote
.color
> 0 && mote
.color
< DC_FIRST_SPECIAL_MOTE_COLOR
)
315 if (mote
.y
> DC_PLAY_HEIGHT
+ mote
.size
* (DC_SPARKLE_LENGTH
/ 2.0f
)) {
325 mote
.v_y
+= mote
.inverse_mass
* DC_MOTE_UPWARD_FORCE
326 - DC_MOTE_DRAG
* mote
.v_y
;
327 mote
.v_x
-= mote
.inverse_mass
* DC_MOTE_CENTER_SPRING
* mote
.x
328 + DC_MOTE_DRAG
* mote
.v_x
;
330 mote
.v_a
-= mote
.inverse_mass
331 * DC_MOTE_TWIST_SPRING
* (mote
.a
- mote
.initial_a
);