src/weapon/teleportation.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  * Teleportation : move a charecter anywhere on the map
00020  *****************************************************************************/
00021 
00022 #include "teleportation.h"
00023 #include "../character/body.h"
00024 #include "../game/game_loop.h"
00025 #include "../game/game_mode.h"
00026 #include "../game/time.h"
00027 #include "../graphic/effects.h"
00028 #include "../include/action_handler.h"
00029 #include "../map/camera.h"
00030 #include "../map/map.h"
00031 #include "../particles/teleport_member.h"
00032 #include "../team/teams_list.h"
00033 #include "../tool/i18n.h"
00034 
00035 Teleportation::Teleportation() : Weapon(WEAPON_TELEPORTATION, "teleportation",
00036                                         new WeaponConfig(),
00037                                         VISIBLE_ONLY_WHEN_INACTIVE)
00038 {
00039   m_name = _("Teleportation");
00040   target_chosen = false;
00041 }
00042 
00043 bool Teleportation::p_Shoot ()
00044 {
00045   if(!target_chosen)
00046     return false;
00047 
00048   // Check we are not going outside of the world !
00049   if( ActiveCharacter().IsOutsideWorldXY(dst) )
00050     return false;
00051 
00052   Rectanglei rect = ActiveCharacter().GetTestRect();
00053   rect.SetPosition(dst); 
00054 
00055   GameLoop::GetInstance()->interaction_enabled = false;
00056 
00057   jukebox.Play("share", "weapon/teleport_start");
00058 
00059   time = Time::GetInstance()->Read();
00060   ActiveCharacter().Hide();
00061   ActiveCharacter().body->MakeTeleportParticles(ActiveCharacter().GetPosition(), dst);
00062 
00063   target_chosen = false; // ensure next teleportation cannot be done pressing key space
00064   return true;
00065 }
00066 
00067 void Teleportation::Refresh()
00068 {
00069   if (!m_is_active) return;
00070 
00071   double dt = Time::GetInstance()->Read() - time;
00072 
00073   if(dt > teleportation_anim_duration)
00074   {
00075     camera.SetXYabs(dst - camera.GetSize()/2);
00076     ActiveCharacter().SetXY(dst);
00077     m_is_active = false;
00078     ActiveCharacter().SetSpeed(0.0,0.0);
00079     ActiveCharacter().Show();
00080     jukebox.Play("share","weapon/teleport_end");
00081     GameLoop::GetInstance()->interaction_enabled = true;
00082     return;
00083   }
00084 }
00085 
00086 void Teleportation::Draw()
00087 {
00088   if (!m_is_active)
00089     Weapon::Draw();
00090 }
00091 
00092 void Teleportation::ChooseTarget(Point2i mouse_pos)
00093 {
00094   dst = mouse_pos - ActiveCharacter().GetSize()/2;
00095   if(!world.ParanoiacRectIsInVacuum(Rectanglei(dst,ActiveCharacter().GetSize())) ||
00096      !ActiveCharacter().IsInVacuumXY(dst))
00097     return;
00098   target_chosen = true;
00099   Shoot();
00100 }
00101 
00102 WeaponConfig& Teleportation::cfg()
00103 { return static_cast<WeaponConfig&>(*extra_params); }
00104 

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