src/particles/fire.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Particle Engine
00020  *****************************************************************************/
00021 
00022 #include "fire.h"
00023 #include "particle.h"
00024 #include "../game/time.h"
00025 #include "../tool/random.h"
00026 #include "../weapon/explosion.h"
00027 #include "../map/camera.h"
00028 
00029 const uint living_time = 5000;
00030 const uint dig_ground_time = 1000;
00031 
00032 ExplosiveWeaponConfig fire_cfg;
00033 
00034 FireParticle::FireParticle() :
00035   Particle("fire_particle")
00036 {
00037   SetCollisionModel(false, false, false);
00038   m_left_time_to_live = 100;
00039   m_check_move_on_end_turn = true;
00040   fire_cfg.damage = 1;
00041   fire_cfg.explosion_range = 5;
00042   fire_cfg.blast_range = 0;
00043   fire_cfg.blast_force = 0;
00044   fire_cfg.particle_range = 6;
00045 //  direction = randomSync.GetBool() ? -1 : 1;
00046 //  oscil_delta = randomSync.GetLong(0, dig_ground_time);
00047   direction = randomObj.GetBool() ? -1 : 1;
00048   oscil_delta = randomObj.GetLong(0, dig_ground_time);
00049   on_ground = false;
00050   image = ParticleEngine::GetSprite(FIRE_spr);
00051   image->SetRotation_HotSpot(Point2i(image->GetWidth()/2,image->GetHeight()));
00052   creation_time = Time::GetInstance()->Read();
00053   SetSize( image->GetSize() );
00054   SetTestRect((image->GetWidth() / 2)-1, (image->GetWidth() / 2) - 1,
00055       (image->GetHeight()/2)-1,1);
00056 }
00057 
00058 FireParticle::~FireParticle()
00059 {
00060   camera.StopFollowingObj(this);
00061 }
00062 
00063 void FireParticle::Refresh()
00064 {
00065   uint now = Time::GetInstance()->Read();
00066   UpdatePosition();
00067   image->Update();
00068 
00069   if (creation_time + living_time < now)
00070     m_left_time_to_live = 0;
00071 
00072   float scale = (now - creation_time)/(float)living_time;
00073   scale = 1.0 - scale;
00074   image->Scale((float)direction * scale, scale);
00075 
00076   if(image->GetSize().x != 0 && image->GetSize().y != 0)
00077   {
00078     SetSize( image->GetSize() );
00079     SetTestRect((image->GetWidth() / 2)-1, (image->GetWidth() / 2) - 1,
00080       (image->GetHeight()/2)-1,1);
00081   }
00082   else
00083     SetSize( Point2i(1,1) );
00084 
00085 
00086   if(on_ground || !FootsInVacuum())
00087   {
00088     on_ground = true;
00089     if((now + oscil_delta) / dig_ground_time != (m_last_refresh + oscil_delta) / dig_ground_time)
00090     {
00091       ApplyExplosion(Point2i(GetCenter().x,(GetY() + GetHeight() + GetCenter().y)/2), fire_cfg, "", false, ParticleEngine::LittleESmoke);
00092       fire_cfg.explosion_range = (uint)(0.5 * scale * image->GetWidth()) + 1;
00093       fire_cfg.particle_range = (uint)(0.6 * scale * image->GetWidth()) + 1;
00094     }
00095     double angle = 0.0;
00096     angle += cos((((now + oscil_delta) % 1000)/500.0) * M_PI) * 0.5; // 0.5 is arbirtary
00097     image->SetRotation_HotSpot(Point2i(image->GetWidth()/2,image->GetHeight()));
00098     image->SetRotation_rad( angle);
00099   }
00100   else
00101   {
00102     double angle = GetSpeedAngle();
00103     image->SetRotation_rad((angle - M_PI_2) * direction);
00104   }
00105 
00106   m_last_refresh = now;
00107 }
00108 
00109 void FireParticle::Draw()
00110 {
00111   image->Draw(Point2i(GetX(),GetY()));
00112 }
00113 
00114 void FireParticle::SignalDrowning()
00115 {
00116   m_left_time_to_live = 0;
00117   // jukebox.Play("share","fire/pschiit");
00118 }
00119 
00120 void FireParticle::SignalOutOfMap()
00121 {
00122   m_left_time_to_live = 0;
00123 }

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