src/weapon/disco_grenade.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  * Disco Grenade
00020  *****************************************************************************/
00021 
00022 #include "disco_grenade.h"
00023 #include <sstream>
00024 #include "explosion.h"
00025 #include "../game/time.h"
00026 #include "../graphic/video.h"
00027 #include "../interface/game_msg.h"
00028 #include "../map/camera.h"
00029 #include "../object/objects_list.h"
00030 #include "../team/teams_list.h"
00031 #include "../tool/math_tools.h"
00032 #include "../tool/i18n.h"
00033 
00034 DiscoGrenade::DiscoGrenade(ExplosiveWeaponConfig& cfg,
00035                            WeaponLauncher * p_launcher) :
00036   WeaponProjectile ("disco_grenade", cfg, p_launcher),
00037   smoke_engine(40)
00038 {
00039   m_rebound_sound = "weapon/disco_grenade_bounce";
00040   have_played_music = false;
00041   explode_with_collision = false;
00042 }
00043 
00044 void DiscoGrenade::Explosion()
00045 {
00046   const uint star_nbr = 9;
00047   const float cos_angle[] = {1.000000, 0.766044, 0.173648, -0.500000, -0.939693, -0.939693, -0.500000, 0.173648, 0.766044};
00048   const float sin_angle[] = {0.000000, 0.642788, 0.984808, 0.866025, 0.342020, -0.342020, -0.866025, -0.984808, -0.642788};
00049 
00050   for(uint i=0;i < star_nbr;i++)
00051   {
00052     double angle = 2.0*(double)i*M_PI/(double)star_nbr;
00053     //  cos_angle[i] = cos(angle);
00054     //  sin_angle[i] = sin(angle);
00055     smoke_engine.AddNow(Point2i(GetX()+(int)(cos_angle[i]*(float)cfg.explosion_range),
00056                                 GetY()+(int)(sin_angle[i]*(float)cfg.explosion_range)),
00057                                 1,particle_MAGIC_STAR,false,angle,2.5);
00058   }
00059   WeaponProjectile::Explosion();
00060 }
00061 
00062 void DiscoGrenade::Refresh()
00063 {
00064   WeaponProjectile::Refresh();
00065 
00066 #ifdef HAVE_A_REALLY_BIG_CPU
00067   if(IsMoving())
00068   {
00069     double norme,angle;
00070     GetSpeed(norme,angle);
00071     for(int i = -3; i<4 ; i++)
00072       smoke_engine.AddNow(GetPosition(), 1,particle_MAGIC_STAR, false,angle+(i*M_PI_4/3.0)+M_PI_2,2.0);
00073   }
00074   else
00075   {
00076       smoke_engine.AddNow(GetPosition(), 1,particle_MAGIC_STAR, false,((float)(Time::GetInstance()->Read()%500)-250.0) * M_PI / 250.0,3.0);
00077   }
00078 #else //  :-P
00079   smoke_engine.AddPeriodic(GetPosition(), particle_MAGIC_STAR, false);
00080 #endif //HAVE_A_REALLY_BIG_CPU
00081 
00082   double tmp = Time::GetInstance()->Read() - begin_time;
00083   // Ah ! Ah ! Ah ! Staying Alive, staying alive ...
00084   if (GetTotalTimeout() >= 2 && tmp > (1000 * GetTotalTimeout() - 2000) && !have_played_music) {
00085     jukebox.Play("share","weapon/alleluia") ;
00086     have_played_music = true;
00087   }
00088   image->SetRotation_rad(GetSpeedAngle());
00089 }
00090 
00091 void DiscoGrenade::SignalOutOfMap()
00092 {
00093   GameMessages::GetInstance()->Add (_("The disco grenade has left the dance floor before exploding"));
00094   WeaponProjectile::SignalOutOfMap();
00095 }
00096 
00097 //-----------------------------------------------------------------------------
00098 
00099 DiscoGrenadeLauncher::DiscoGrenadeLauncher() :
00100   WeaponLauncher(WEAPON_DISCO_GRENADE, "disco_grenade", new ExplosiveWeaponConfig(), VISIBLE_ONLY_WHEN_INACTIVE)
00101 {
00102   m_name = _("Disco Grenade");
00103   m_allow_change_timeout = true;
00104   ignore_collision_signal = true;
00105   ReloadLauncher();
00106 }
00107 
00108 WeaponProjectile * DiscoGrenadeLauncher::GetProjectileInstance()
00109 {
00110   return dynamic_cast<WeaponProjectile *>
00111       (new DiscoGrenade(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00112 }

Generated on Mon Jan 1 13:11:00 2007 for Wormux by  doxygen 1.4.7