00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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));
00067 dpos.y = (int)((destination.y - start.y) * sin((float)dt * sin_y_max / (float)teleportation_anim_duration) / sin(sin_y_max));
00068
00069 SetXY( start + dpos );
00070 image->Update();
00071 }