Also improved Particles: it now has acceleration and knows the difference of X and Y.
SVN-Revision: 1906
else if(!end_sequence && endtile && endtile->data == 0)
{
end_sequence = ENDSEQUENCE_RUNNING;
- random_timer.start(200); // start 1st fire work
+ random_timer.start(200); // start 1st firework
last_x_pos = -1;
SoundManager::get()->play_music(level_end_song, 0);
endsequence_timer.start(7000); // 5 seconds until we finish the map
newsector = newspawnpoint = "";
}
- // on end sequence make a few fire works
+ // on end sequence make a few fireworks
if(end_sequence == ENDSEQUENCE_RUNNING && !random_timer.check())
{
Vector epicenter = currentsector->camera->get_translation();
epicenter.x += screen->w * ((float)rand() / RAND_MAX);
epicenter.y += (screen->h/2) * ((float)rand() / RAND_MAX);
- int red = rand() % 255; // calculate fire work color
+ int red = rand() % 255; // calculate firework color
int green = rand() % red;
- currentsector->add_particles(epicenter, 45, Color(red,green,0), 3, 1.4, 1300);
+ currentsector->add_particles(epicenter, Vector(1.4,1.4), Vector(0,0),
+ 45, Color(red,green,0), 3, 1300);
- random_timer.start(rand() % 400 + 600); // next fire work
+ SoundManager::get()->play_sound(IDToSound(SND_FIREWORKS));
+ random_timer.start(rand() % 400 + 600); // next firework
}
}
img_smoke_cloud->draw(context, position, LAYER_OBJECTS+1);
}
-Particles::Particles(const Vector& epicenter, int number, Color color_, int size_, float velocity_, int life_time)
- : color(color_), size(size_), velocity(velocity_)
+Particles::Particles(const Vector& epicenter, const Vector& velocity, const Vector& acceleration, int number, Color color_, int size_, int life_time)
+ : color(color_), size(size_), vel(velocity), accel(acceleration)
{
timer.start(life_time);
void
Particles::action(float elapsed_time)
{
+ vel.x += accel.x * elapsed_time;
+ vel.y += accel.y * elapsed_time;
+
// update particles
for(int p = 0; p < particles.size(); p++)
{
- particles[p]->pos.x += sin(particles[p]->angle) * velocity * elapsed_time;
- particles[p]->pos.y += cos(particles[p]->angle) * velocity * elapsed_time;
+ particles[p]->pos.x += sin(particles[p]->angle) * vel.x * elapsed_time;
+ particles[p]->pos.y += cos(particles[p]->angle) * vel.y * elapsed_time;
}
if(!timer.check())
class Particles : public GameObject
{
public:
- Particles(const Vector& epicenter, int number, Color color, int size, float velocity, int life_time);
+ Particles(const Vector& epicenter, const Vector& velocity, const Vector& acceleration, int number, Color color, int size, int life_time);
~Particles();
virtual void action(float elapsed_time);
private:
Color color;
float size;
- float velocity;
+ Vector vel, accel;
Timer timer;
struct Particle {
"/sounds/stomp.wav",
"/sounds/kick.wav",
"/sounds/explosion.wav",
- "/sounds/warp.wav"
+ "/sounds/warp.wav",
+ "/sounds/fireworks.wav"
};
SND_KICK,
SND_EXPLODE,
SND_WARP,
+ SND_FIREWORKS,
NUM_SOUNDS
};
}
bool
-Sector::add_particles(const Vector& epicenter, int number, Color color, int size, float velocity, int life_time)
+Sector::add_particles(const Vector& epicenter, const Vector& velocity, const Vector& acceleration, int number, Color color, int size, int life_time)
{
- add_object(new Particles(epicenter, number, color, size, velocity, life_time));
+ add_object(new Particles(epicenter, velocity, acceleration, number, color, size, life_time));
return true;
}
void add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind);
bool add_bullet(const Vector& pos, float xm, Direction dir);
bool add_smoke_cloud(const Vector& pos);
- bool add_particles(const Vector& epicenter, int number, Color color, int size, float velocity, int life_time);
+ bool add_particles(const Vector& epicenter, const Vector& velocity, const Vector& acceleration, int number, Color color, int size, int life_time);
/** Try to grab the coin at the given coordinates */
void trygrabdistro(const Vector& pos, int bounciness);