/****************************************************************************** * Wormux is a convivial mass murder game. * Copyright (C) 2001-2004 Lawrence Azzoug. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA ****************************************************************************** * Arme Supertux : Look ! it's the famous flying magic pinguin ! *****************************************************************************/ #include "supertux.h" #include "explosion.h" #include "../game/config.h" #include "../game/time.h" #include "../graphic/video.h" #include "../include/action_handler.h" #include "../interface/game_msg.h" #include "../map/camera.h" #include "../network/network.h" #include "../object/objects_list.h" #include "../team/teams_list.h" #include "../tool/math_tools.h" #include "../tool/i18n.h" const uint time_delta = 40; const uint animation_deltat = 50; SuperTux::SuperTux(SuperTuxWeaponConfig& cfg, WeaponLauncher * p_launcher) : WeaponProjectile ("supertux", cfg, p_launcher), particle_engine(40) { explode_colliding_character = true; SetSize(image->GetSize()); SetTestRect(1, 1, 2, 2); } void SuperTux::Shoot(double strength) { WeaponProjectile::Shoot(strength); angle_rad = ActiveCharacter().GetFiringAngle(); Time * global_time = Time::GetInstance(); time_next_action = global_time->Read(); last_move = global_time->Read(); begin_time = global_time->Read(); } void SuperTux::Refresh() { WeaponProjectile::Refresh(); image->SetRotation_rad(angle_rad + M_PI_2); if ((last_move+animation_deltat)Read()) { SetExternForce(static_cast(cfg).speed, angle_rad); image->Update(); last_move = Time::GetInstance()->Read(); } if(ActiveTeam().IsLocal() || ActiveTeam().IsLocalAI()) { Action a(Action::ACTION_SUPERTUX_STATE); a.Push(angle_rad); a.Push(GetPhysX()); a.Push(GetPhysY()); Point2d speed; network.SendAction(&a); } particle_engine.AddPeriodic(GetPosition(), particle_STAR, false, angle_rad, 0); } void SuperTux::turn_left() { time_now = Time::GetInstance()->Read(); if (time_next_actionRead(); if (time_next_actionAdd (_("Bye bye tux...")); WeaponProjectile::SignalOutOfMap(); } //----------------------------------------------------------------------------- SuperTuxWeaponConfig::SuperTuxWeaponConfig() { speed = 2; } void SuperTuxWeaponConfig::LoadXml(xmlpp::Element *elem) { ExplosiveWeaponConfig::LoadXml (elem); XmlReader::ReadUint(elem, "speed", speed); } //----------------------------------------------------------------------------- TuxLauncher::TuxLauncher() : WeaponLauncher(WEAPON_SUPERTUX, "tux", new SuperTuxWeaponConfig(), VISIBLE_ONLY_WHEN_INACTIVE) { m_name = _("SuperTux"); override_keys = true ; ReloadLauncher(); } WeaponProjectile * TuxLauncher::GetProjectileInstance() { return dynamic_cast (new SuperTux(cfg(),dynamic_cast(this))); } bool TuxLauncher::p_Shoot () { current_tux = static_cast(projectile); return WeaponLauncher::p_Shoot(); } void TuxLauncher::HandleKeyEvent(Action::Action_t action, Keyboard::Key_Event_t event_type) { switch (action) { case Action::ACTION_MOVE_LEFT: if (event_type != Keyboard:: Keyboard::KEY_RELEASED) current_tux->turn_left(); break ; case Action::ACTION_MOVE_RIGHT: if (event_type != Keyboard:: Keyboard::KEY_RELEASED) current_tux->turn_right(); break ; default: break ; } ; } SuperTuxWeaponConfig& TuxLauncher::cfg() { return static_cast(*extra_params); }