src/particles/explosion_smoke.cpp

Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003  *  Wormux is a convivial mass murder game.
00004  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00019  ******************************************************************************
00020  * Particle Engine
00021  *****************************************************************************/
00022 
00023 #include "explosion_smoke.h"
00024 #include "particle.h"
00025 #include "../game/time.h"
00026 #include "../tool/random.h"
00027 
00028 ExplosionSmoke::ExplosionSmoke(const uint size_init) :
00029   Particle("explosion_smoke_particle")
00030 {
00031   m_initial_size = size_init;
00032   m_initial_time_to_live = 30;
00033   m_left_time_to_live = m_initial_time_to_live;
00034   m_time_between_scale = 25;
00035   dx = 0;
00036 
00037   image = ParticleEngine::GetSprite(EXPLOSION_SMOKE_spr);
00038   mvt_freq = randomObj.GetDouble(-2.0, 2.0);
00039   SetGravityFactor(randomObj.GetDouble(-1.0,-2.0));
00040 
00041   image->ScaleSize(m_initial_size, m_initial_size);
00042   SetSize( Point2i(1, 1) );
00043   StartMoving();
00044 }
00045 
00046 void ExplosionSmoke::Refresh()
00047 {
00048   uint time = Time::GetInstance()->Read() - m_last_refresh;
00049 
00050   UpdatePosition();
00051 
00052   image->Update();
00053 
00054   if (time >= m_time_between_scale) {
00055     //assert(m_left_time_to_live > 0);
00056     if (m_left_time_to_live <= 0) return ;
00057 
00058     m_left_time_to_live--;
00059 
00060     float lived_time = m_initial_time_to_live - m_left_time_to_live;
00061 
00062     float coeff = cos((M_PI/2.0)*((float)lived_time/((float)m_initial_time_to_live)));
00063     image->ScaleSize(int(coeff * m_initial_size),int(coeff * m_initial_size));
00064 
00065     dx = int((int)m_initial_size * sin(5.0 * ((float)lived_time/((float)m_initial_time_to_live)) * M_PI * mvt_freq / 2.0) / 2);
00066     m_last_refresh = Time::GetInstance()->Read() ;
00067   }
00068 }
00069 
00070 void ExplosionSmoke::Draw()
00071 {
00072   if (m_left_time_to_live > 0)
00073     image->Draw(GetPosition()+Point2i(dx,0));
00074 }

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7