src/weapon/supertux.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  * Arme Supertux : Look ! it's the famous flying magic pinguin !
00020  *****************************************************************************/
00021 
00022 #include "supertux.h"
00023 #include "explosion.h"
00024 #include "../game/config.h"
00025 #include "../game/time.h"
00026 #include "../graphic/video.h"
00027 #include "../include/action_handler.h"
00028 #include "../interface/game_msg.h"
00029 #include "../map/camera.h"
00030 #include "../network/network.h"
00031 #include "../object/objects_list.h"
00032 #include "../team/teams_list.h"
00033 #include "../tool/math_tools.h"
00034 #include "../tool/i18n.h"
00035 const uint time_delta = 40;
00036 const uint animation_deltat = 50;
00037 
00038 SuperTux::SuperTux(SuperTuxWeaponConfig& cfg,
00039                    WeaponLauncher * p_launcher) :
00040   WeaponProjectile ("supertux", cfg, p_launcher),
00041   particle_engine(40)
00042 {
00043   explode_colliding_character = true;
00044   SetSize(image->GetSize());
00045   SetTestRect(1, 1, 2, 2);
00046 }
00047 
00048 void SuperTux::Shoot(double strength)
00049 {
00050   WeaponProjectile::Shoot(strength);
00051   angle_rad = ActiveCharacter().GetFiringAngle();
00052 
00053   Time * global_time = Time::GetInstance();
00054   time_next_action = global_time->Read();
00055   last_move = global_time->Read();
00056   begin_time = global_time->Read();
00057 }
00058 
00059 void SuperTux::Refresh()
00060 {
00061   WeaponProjectile::Refresh();
00062 
00063   image->SetRotation_rad(angle_rad + M_PI_2);
00064   if ((last_move+animation_deltat)<Time::GetInstance()->Read())
00065   {
00066     SetExternForce(static_cast<SuperTuxWeaponConfig&>(cfg).speed, angle_rad);
00067     image->Update();
00068     last_move = Time::GetInstance()->Read();
00069   }
00070 
00071   if(ActiveTeam().IsLocal() || ActiveTeam().IsLocalAI())
00072   {
00073     Action a(Action::ACTION_SUPERTUX_STATE);
00074     a.Push(angle_rad);
00075     a.Push(GetPhysX());
00076     a.Push(GetPhysY());
00077     Point2d speed;
00078     network.SendAction(&a);
00079   }
00080   particle_engine.AddPeriodic(GetPosition(), particle_STAR, false, angle_rad, 0);
00081 }
00082 
00083 void SuperTux::turn_left()
00084 {
00085   time_now = Time::GetInstance()->Read();
00086   if (time_next_action<time_now)
00087     {
00088       time_next_action=time_now + time_delta;
00089       angle_rad = angle_rad - M_PI / 12;
00090     }
00091 }
00092 
00093 void SuperTux::turn_right()
00094 {
00095   time_now = Time::GetInstance()->Read();
00096   if (time_next_action<time_now)
00097     {
00098       time_next_action=time_now + time_delta;
00099       angle_rad = angle_rad + M_PI / 12;
00100     }
00101 }
00102 
00103 void SuperTux::SignalOutOfMap()
00104 {
00105   GameMessages::GetInstance()->Add (_("Bye bye tux..."));
00106   WeaponProjectile::SignalOutOfMap();
00107 }
00108 
00109 //-----------------------------------------------------------------------------
00110 
00111 SuperTuxWeaponConfig::SuperTuxWeaponConfig()
00112 {
00113   speed = 2;
00114 }
00115 
00116 void SuperTuxWeaponConfig::LoadXml(xmlpp::Element *elem)
00117 {
00118   ExplosiveWeaponConfig::LoadXml (elem);
00119   XmlReader::ReadUint(elem, "speed", speed);
00120 }
00121 
00122 //-----------------------------------------------------------------------------
00123 
00124 TuxLauncher::TuxLauncher() :
00125   WeaponLauncher(WEAPON_SUPERTUX, "tux", new SuperTuxWeaponConfig(), VISIBLE_ONLY_WHEN_INACTIVE)
00126 {
00127   m_name = _("SuperTux");
00128   override_keys = true ;
00129   ReloadLauncher();
00130 }
00131 
00132 WeaponProjectile * TuxLauncher::GetProjectileInstance()
00133 {
00134   return dynamic_cast<WeaponProjectile *>
00135       (new SuperTux(cfg(),dynamic_cast<WeaponLauncher *>(this)));
00136 }
00137 
00138 bool TuxLauncher::p_Shoot ()
00139 {
00140   current_tux = static_cast<SuperTux *>(projectile);
00141   return WeaponLauncher::p_Shoot();
00142 }
00143 
00144 void TuxLauncher::HandleKeyEvent(Action::Action_t action, Keyboard::Key_Event_t event_type)
00145 {
00146   switch (action)
00147   {
00148     case Action::ACTION_MOVE_LEFT:
00149     if (event_type !=  Keyboard:: Keyboard::KEY_RELEASED)
00150       current_tux->turn_left();
00151     break ;
00152 
00153     case Action::ACTION_MOVE_RIGHT:
00154     if (event_type !=  Keyboard:: Keyboard::KEY_RELEASED)
00155       current_tux->turn_right();
00156     break ;
00157 
00158   default:
00159     break ;
00160   } ;
00161 }
00162 
00163 SuperTuxWeaponConfig& TuxLauncher::cfg()
00164 {
00165   return static_cast<SuperTuxWeaponConfig&>(*extra_params);
00166 }

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