Game Development Reference
In-Depth Information
void FireworksDemo::create(unsigned type, const Firework *parent)
{
// Get the rule needed to create this firework.
FireworkRule *rule = rules + (type - 1);
// Create the firework.
rule->create(fireworks+nextFirework, parent);
// Increment the index for the next firework.
nextFirework = (nextFirework + 1) % maxFireworks;
}
As fireworks are spawned, they have their particle properties set, with velocities de-
termined with a random component.
Notice that I've used high damping values for several of the firework types. This
allows them to drift back down to the ground slowly, which is especially important
for fireworks that need to hang in the air before exploding.
At each frame, all of the currently active fireworks are updated. This is performed
by a simple loop that first checks to see whether the firework should be processed
(fireworks with a type of 0 are defined to be inactive).
Excerpt from src/demos/fireworks/fireworks.cpp
for (Firework *firework = fireworks;
firework < fireworks+maxFireworks;
firework++)
{
// Check if we need to process this firework.
if (firework->type > 0)
{
// Does it need removing?
if (firework->update(duration))
{
// Find the appropriate rule.
FireworkRule *rule = rules + (firework->type-1);
// Delete the current firework (this doesn't affect its
// position and velocity for passing to the create function,
// just whether or not it is processed for rendering or
// physics.
firework->type = 0;
// Add the payload.
for (unsigned i = 0; i < rule->payloadCount; i++)
{
Search Nedrilad ::




Custom Search