[Super-tux-commit] supertux/src gameobjs.cpp,1.47,1.48 gameobjs.h,1.33,1.34 sector.cpp,1.22,1.23 sec
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-09-13 22:48:30
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10685/src Modified Files: gameobjs.cpp gameobjs.h sector.cpp sector.h Log Message: Added simple particle system object. I called it Particles cause there is already a ParticleSystem class. Weather would be a better name for that class. This particle system is just a rip off of one that I did for a game of mine. I guess that with more customization it would be pretty good. Index: gameobjs.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.h,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- gameobjs.h 14 Aug 2004 11:33:53 -0000 1.33 +++ gameobjs.h 13 Sep 2004 22:48:14 -0000 1.34 @@ -176,6 +176,28 @@ Vector position; }; +class Particles : public GameObject +{ +public: + Particles(const Vector& epicenter, int number, Color color, int size, float velocity, int life_time); + ~Particles(); + + virtual void action(float elapsed_time); + virtual void draw(DrawingContext& context); + +private: + Color color; + float size; + float velocity; + Timer timer; + + struct Particle { + Vector pos; + float angle; + }; + std::vector <Particle*> particles; +}; + void load_object_gfx(); #endif Index: sector.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- sector.h 13 Sep 2004 18:50:46 -0000 1.11 +++ sector.h 13 Sep 2004 22:48:14 -0000 1.12 @@ -46,6 +46,7 @@ class Upgrade; class Bullet; class SmokeCloud; +class Particles; class BadGuy; class Tile; @@ -106,6 +107,7 @@ 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); /** Try to grab the coin at the given coordinates */ void trygrabdistro(const Vector& pos, int bounciness); @@ -159,6 +161,7 @@ std::vector<Upgrade*> upgrades; std::vector<Bullet*> bullets; std::vector<SmokeCloud*> smoke_clouds; + std::vector<Particles*> particles; public: // ugly typedef std::vector<InteractiveObject*> InteractiveObjects; Index: sector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- sector.cpp 13 Sep 2004 18:50:46 -0000 1.22 +++ sector.cpp 13 Sep 2004 22:48:14 -0000 1.23 @@ -466,7 +466,13 @@ std::remove(smoke_clouds.begin(), smoke_clouds.end(), smoke_cloud), smoke_clouds.end()); } - + Particles* particle = dynamic_cast<Particles*> (*i); + if(particle) { + particles.erase( + std::remove(particles.begin(), particles.end(), particle), + particles.end()); + } + delete *i; i = gameobjects.erase(i); } else { @@ -500,7 +506,9 @@ SmokeCloud* smoke_cloud = dynamic_cast<SmokeCloud*> (*i); if(smoke_cloud) smoke_clouds.push_back(smoke_cloud); - + Particles* particle = dynamic_cast<Particles*> (*i); + if(particle) + particles.push_back(particle); gameobjects.push_back(*i); } @@ -728,6 +736,13 @@ return true; } +bool +Sector::add_particles(const Vector& epicenter, int number, Color color, int size, float velocity, int life_time) +{ + add_object(new Particles(epicenter, number, color, size, velocity, life_time)); + return true; +} + /* Break a brick: */ bool Sector::trybreakbrick(const Vector& pos, bool small) Index: gameobjs.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.cpp,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- gameobjs.cpp 14 Aug 2004 12:00:58 -0000 1.47 +++ gameobjs.cpp 13 Sep 2004 22:48:14 -0000 1.48 @@ -32,6 +32,7 @@ #include "resources.h" #include "sector.h" #include "tilemap.h" +#include "video/drawing_context.h" BouncyDistro::BouncyDistro(const Vector& pos) : position(pos) @@ -437,6 +438,53 @@ 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_) +{ + timer.start(life_time); + + // create particles + for(int p = 0; p < number; p++) + { + Particle* particle = new Particle; + particle->pos = epicenter; + particle->angle = (rand() % 360) * (M_PI / 180); // in radius + + particles.push_back(particle); + } +} + +Particles::~Particles() +{ + // free particles + for(std::vector<Particle*>::iterator i = particles.begin(); i < particles.end(); i++) + delete (*i); +} + +void +Particles::action(float 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; + } + + if(!timer.check()) + remove_me(); +} + +void +Particles::draw(DrawingContext& context) +{ + // draw particles + for(int p = 0; p < particles.size(); p++) + { + context.draw_filled_rect(particles[p]->pos, Vector(size,size), color, LAYER_OBJECTS+10); + } +} + void load_object_gfx() { img_trampoline = sprite_manager->load("trampoline"); |