src/particles/teleport_member.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  * Particle Engine
00020  *****************************************************************************/
00021 
00022 #include "teleport_member.h"
00023 #include "particle.h"
00024 #include "tool/random.h"
00025 #include "game/time.h"
00026 #include "map/camera.h"
00027 
00028 TeleportMemberParticle::TeleportMemberParticle(Sprite* spr, const Point2i& position, const Point2i& dest, int direction) :
00029   Particle("teleport_member_particle")
00030 {
00031   SetCollisionModel(true, false, false);
00032   image = new Sprite(spr->GetSurface());
00033 
00034   float scale_x, scale_y;
00035   image->GetScaleFactors(scale_x, scale_y);
00036   image->Scale(scale_x * (float)direction, scale_y);
00037 
00038   assert(image->GetWidth() != 0 && image->GetHeight()!=0);
00039   SetXY(position);
00040   m_left_time_to_live = 1;
00041 
00042   SetSize(image->GetSize());
00043   SetOnTop(true);
00044   destination = dest;
00045   start = position;
00046   time = Time::GetInstance()->Read();
00047 
00048   sin_x_max = randomObj.GetDouble(M_PI_4, 3.0 * M_PI_4);
00049   sin_y_max = randomObj.GetDouble(M_PI_4, 3.0 * M_PI_4);
00050   camera.FollowObject(this, true, true);
00051 }
00052 
00053 TeleportMemberParticle::~TeleportMemberParticle()
00054 {
00055   camera.StopFollowingObj(this);
00056 }
00057 
00058 void TeleportMemberParticle::Refresh()
00059 {
00060   uint now = Time::GetInstance()->Read();
00061   if(now > time + teleportation_anim_duration)
00062     m_left_time_to_live = 0;
00063 
00064   uint dt = now - time;
00065   Point2i dpos;
00066   dpos.x = (int)((destination.x - start.x) * sin((float)dt * sin_x_max / (float)teleportation_anim_duration) / sin(sin_x_max))/* * dt / teleportation_anim_duration*/;
00067   dpos.y = (int)((destination.y - start.y) * sin((float)dt * sin_y_max / (float)teleportation_anim_duration) / sin(sin_y_max))/* * dt / teleportation_anim_duration*/;
00068 
00069   SetXY( start + dpos );
00070   image->Update();
00071 }

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7