src/object/ghost_particle_system.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "object/ghost_particle_system.hpp"
00018 
00019 #include <math.h>
00020 
00021 #include "math/random_generator.hpp"
00022 #include "supertux/globals.hpp"
00023 #include "video/drawing_context.hpp"
00024 
00025 //FIXME: Sometimes both ghosts have the same image
00026 //       Ghosts don't change their movement pattern - not random
00027 GhostParticleSystem::GhostParticleSystem()
00028 {
00029   ghosts[0] = Surface::create("images/objects/particles/ghost0.png");
00030   ghosts[1] = Surface::create("images/objects/particles/ghost1.png");
00031 
00032   virtual_width = SCREEN_WIDTH * 2;
00033 
00034   // create two ghosts
00035   size_t ghostcount = 2;
00036   for(size_t i=0; i<ghostcount; ++i) {
00037     GhostParticle* particle = new GhostParticle;
00038     particle->pos.x = graphicsRandom.randf(virtual_width);
00039     particle->pos.y = graphicsRandom.randf(SCREEN_HEIGHT);
00040     int size = graphicsRandom.rand(2);
00041     particle->texture = ghosts[size];
00042     particle->speed = graphicsRandom.randf(std::max(50, (size * 10)), 180 + (size * 10));
00043     particles.push_back(particle);
00044   }
00045 }
00046 
00047 void
00048 GhostParticleSystem::parse(const Reader& reader)
00049 {
00050   z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1);
00051 }
00052 
00053 GhostParticleSystem::~GhostParticleSystem()
00054 {
00055 }
00056 
00057 void GhostParticleSystem::update(float elapsed_time)
00058 {
00059   std::vector<Particle*>::iterator i;
00060   for(i = particles.begin(); i != particles.end(); ++i) {
00061     GhostParticle* particle = (GhostParticle*) *i;
00062     particle->pos.y -= particle->speed * elapsed_time;
00063     particle->pos.x -= particle->speed * elapsed_time;
00064     if(particle->pos.y > SCREEN_HEIGHT) {
00065       particle->pos.y = fmodf(particle->pos.y , virtual_height);
00066       particle->pos.x = graphicsRandom.rand(static_cast<int>(virtual_width));
00067     }
00068   }
00069 }
00070 
00071 /* EOF */

Generated on Mon Apr 21 03:38:15 2014 for SuperTux by  doxygen 1.5.1