From 377b24b9da20a23487cec26c1193097d5c0c0cbc Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Sun, 31 Oct 2004 12:08:44 +0000 Subject: [PATCH] Added a parameter for Particles to set the drawing layer, instead of using a fixed one. Asked by Iknos. SVN-Revision: 2078 --- src/gameloop.cpp | 3 ++- src/gameobjs.cpp | 6 +++--- src/gameobjs.h | 8 +++++--- src/player.cpp | 3 ++- src/sector.cpp | 4 ++-- src/sector.h | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 15ebac5ad..d05379f9d 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -655,7 +655,8 @@ GameSession::action(double frame_ratio) int red = rand() % 255; // calculate firework color int green = rand() % red; currentsector->add_particles(epicenter, 0, 360, Vector(1.4,1.4), - Vector(0,0), 45, Color(red,green,0), 3, 1300); + Vector(0,0), 45, Color(red,green,0), 3, 1300, + LAYER_FOREGROUND1+1); 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 1555fc806..7500bb0da 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -465,8 +465,8 @@ SmokeCloud::draw(DrawingContext& context) img_smoke_cloud->draw(context, position, LAYER_OBJECTS+1); } -Particles::Particles(const Vector& epicenter, int min_angle, int max_angle, const Vector& initial_velocity, const Vector& acceleration, int number, Color color_, int size_, int life_time) - : color(color_), size(size_), accel(acceleration) +Particles::Particles(const Vector& epicenter, int min_angle, int max_angle, const Vector& initial_velocity, const Vector& acceleration, int number, Color color_, int size_, int life_time, int drawing_layer_) + : color(color_), size(size_), accel(acceleration), drawing_layer(drawing_layer_) { if(life_time == 0) { @@ -537,7 +537,7 @@ Particles::draw(DrawingContext& context) // draw particles for(std::vector::iterator i = particles.begin(); i < particles.end(); i++) { - context.draw_filled_rect((*i)->pos, Vector(size,size), color, LAYER_OBJECTS+10); + context.draw_filled_rect((*i)->pos, Vector(size,size), color, drawing_layer); } } diff --git a/src/gameobjs.h b/src/gameobjs.h index a3a354ac6..0831dc7bb 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -182,19 +182,21 @@ class Particles : public GameObject public: Particles(const Vector& epicenter, int min_angle, int max_angle, const Vector& initial_velocity, const Vector& acceleration, - int number, Color color, int size, int life_time); + int number, Color color, int size, int life_time, int drawing_layer); ~Particles(); virtual void action(float elapsed_time); virtual void draw(DrawingContext& context); private: - Color color; - float size; Vector accel; Timer timer; bool live_forever; + Color color; + float size; + int drawing_layer; + struct Particle { Vector pos, vel; // float angle; diff --git a/src/player.cpp b/src/player.cpp index 7dd411198..0ddfdb19a 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -505,7 +505,8 @@ Player::handle_horizontal_input() Sector::current()->add_particles( Vector(base.x + (dir == RIGHT ? base.width : 0), base.y+base.height), dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20, - Vector(2.8,-2.6), Vector(0,0.030), 3, Color(100,100,100), 3, 800); + Vector(2.8,-2.6), Vector(0,0.030), 3, Color(100,100,100), 3, 800, + LAYER_OBJECTS+1); ax *= 2.5; } diff --git a/src/sector.cpp b/src/sector.cpp index 815b321ae..4cde14196 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -769,9 +769,9 @@ Sector::add_smoke_cloud(const Vector& pos) } bool -Sector::add_particles(const Vector& epicenter, int min_angle, int max_angle, const Vector& initial_velocity, const Vector& acceleration, int number, Color color, int size, int life_time) +Sector::add_particles(const Vector& epicenter, int min_angle, int max_angle, const Vector& initial_velocity, const Vector& acceleration, int number, Color color, int size, int life_time, int drawing_layer) { - add_object(new Particles(epicenter, min_angle, max_angle, initial_velocity, acceleration, number, color, size, life_time)); + add_object(new Particles(epicenter, min_angle, max_angle, initial_velocity, acceleration, number, color, size, life_time, drawing_layer)); return true; } diff --git a/src/sector.h b/src/sector.h index 9278d6eb9..21a9c028e 100644 --- a/src/sector.h +++ b/src/sector.h @@ -114,7 +114,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 min_angle, int max_angle, const Vector& initial_velocity, const Vector& acceleration, int number, Color color, int size, int life_time); + bool add_particles(const Vector& epicenter, int min_angle, int max_angle, const Vector& initial_velocity, const Vector& acceleration, int number, Color color, int size, int life_time, int drawing_layer); void add_floating_text(const Vector& pos, const std::string& text); /** Try to grab the coin at the given coordinates */ -- 2.11.0