From: Ricardo Cruz Date: Tue, 14 Sep 2004 10:27:05 +0000 (+0000) Subject: Made code using fireworks sound effect. X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=76d092bebada7aca0db7435a2810ce749816a056;p=supertux.git Made code using fireworks sound effect. Also improved Particles: it now has acceleration and knows the difference of X and Y. SVN-Revision: 1906 --- diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 4c427d12d..298b8dd44 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -515,7 +515,7 @@ GameSession::check_end_conditions() 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 @@ -556,18 +556,20 @@ GameSession::action(double frame_ratio) 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 } } diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index e2e0716ee..39d4eb699 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -438,8 +438,8 @@ SmokeCloud::draw(DrawingContext& context) 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); @@ -464,11 +464,14 @@ Particles::~Particles() 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()) diff --git a/src/gameobjs.h b/src/gameobjs.h index d5e779c96..051c0ea07 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -179,7 +179,7 @@ private: 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); @@ -188,7 +188,7 @@ public: private: Color color; float size; - float velocity; + Vector vel, accel; Timer timer; struct Particle { diff --git a/src/resources.cpp b/src/resources.cpp index 3913a05c5..be7efec2d 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -75,7 +75,8 @@ char * soundfilenames[NUM_SOUNDS] = { "/sounds/stomp.wav", "/sounds/kick.wav", "/sounds/explosion.wav", - "/sounds/warp.wav" + "/sounds/warp.wav", + "/sounds/fireworks.wav" }; diff --git a/src/resources.h b/src/resources.h index e24e24e61..1287060a9 100644 --- a/src/resources.h +++ b/src/resources.h @@ -52,6 +52,7 @@ enum { SND_KICK, SND_EXPLODE, SND_WARP, + SND_FIREWORKS, NUM_SOUNDS }; diff --git a/src/sector.cpp b/src/sector.cpp index 3d0f3e55a..300c31865 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -737,9 +737,9 @@ Sector::add_smoke_cloud(const Vector& pos) } 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; } diff --git a/src/sector.h b/src/sector.h index 5fd13ffc4..ffd409eaa 100644 --- a/src/sector.h +++ b/src/sector.h @@ -107,7 +107,7 @@ public: 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);