src/weapon/dynamite.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  * Weapon dynamite : When fired, explode after a short laps of time. Then make a
00020  * big hole, eject character and made them lost energy.
00021  * Like a dynamite after all :)
00022  *****************************************************************************/
00023 
00024 #include "dynamite.h"
00025 #include "explosion.h"
00026 #include "../game/config.h"
00027 #include "../include/app.h"
00028 #include "../object/objects_list.h"
00029 #include "../team/teams_list.h"
00030 #include "../tool/i18n.h"
00031 #include "../tool/resource_manager.h"
00032 #include "../tool/debug.h"
00033 
00034 #ifdef __MINGW32__
00035 #undef LoadImage
00036 #endif
00037 
00038 DynamiteStick::DynamiteStick(ExplosiveWeaponConfig& cfg,
00039                              WeaponLauncher * p_launcher) :
00040   WeaponProjectile("dynamite_bullet", cfg, p_launcher)
00041 {
00042   channel = -1;
00043   explode_with_collision = false;
00044 
00045   image->animation.SetLoopMode(false);
00046   SetSize(image->GetSize());
00047   SetTestRect (0, 0, 2, 3);
00048 }
00049 
00050 void DynamiteStick::Shoot(double strength)
00051 {
00052   unsigned int delay = (1000 * WeaponProjectile::GetTotalTimeout())/image->GetFrameCount();
00053   image->SetFrameSpeed(delay);
00054 
00055   image->Scale(ActiveCharacter().GetDirection(), 1);
00056   image->SetCurrentFrame(0);
00057   image->Start();
00058   WeaponProjectile::Shoot(strength);
00059 }
00060 
00061 void DynamiteStick::Refresh()
00062 {
00063   image->Update();
00064   if (image->IsFinished()) Explosion();
00065 }
00066 
00067 void DynamiteStick::ShootSound()
00068 {
00069   channel = jukebox.Play("share","weapon/dynamite_fuze", -1);
00070 }
00071 
00072 void DynamiteStick::SignalExplosion()
00073 {
00074   jukebox.Stop(channel);
00075 }
00076 
00077 void DynamiteStick::SignalOutOfMap()
00078 {
00079   jukebox.Stop(channel);
00080 }
00081 
00082 void DynamiteStick::SignalDrowning()
00083 {
00084   jukebox.Stop(channel);
00085 }
00086 //-----------------------------------------------------------------------------
00087 
00088 Dynamite::Dynamite() :
00089     WeaponLauncher(WEAPON_DYNAMITE, "dynamite", new ExplosiveWeaponConfig(), VISIBLE_ONLY_WHEN_INACTIVE)
00090 {
00091   m_name = _("Dynamite");
00092   ReloadLauncher();
00093 }
00094 
00095 WeaponProjectile * Dynamite::GetProjectileInstance()
00096 {
00097   return dynamic_cast<WeaponProjectile *>
00098       (new DynamiteStick(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00099 }
00100 
00101 // drop a dynamite
00102 bool Dynamite::p_Shoot ()
00103 {
00104   projectile->Shoot(0);
00105 
00106   // add the character speed
00107   if(ActiveCharacter().GetDirection() == 1)
00108     projectile->SetSpeed(3.0, -M_PI_4);
00109   else
00110     projectile->SetSpeed(3.0, -3.0 * M_PI_4);
00111 
00112   return true;
00113 }

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