00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00046
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;
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
00118 }
00119
00120 void FireParticle::SignalOutOfMap()
00121 {
00122 m_left_time_to_live = 0;
00123 }