src/particles/body_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 "body_member.h"
00023 #include "particle.h"
00024 #include "tool/random.h"
00025 
00026 BodyMemberParticle::BodyMemberParticle(Sprite* spr, const Point2i& position) :
00027   Particle("body_member_particle")
00028 {
00029   SetCollisionModel(false, false, false);
00030   m_left_time_to_live = 100;
00031   image = new Sprite(spr->GetSurface());
00032   image->EnableRotationCache(32);
00033   assert(image->GetWidth() != 0 && image->GetHeight()!=0);
00034   SetXY(position);
00035 
00036   SetSize(image->GetSize());
00037   SetOnTop(true);
00038   SetSpeed( (double)randomObj.GetLong(10, 15),
00039         - (double)randomObj.GetLong(0, 3000)/1000.0);
00040 }
00041 
00042 void BodyMemberParticle::Refresh()
00043 {
00044   m_left_time_to_live--;
00045   UpdatePosition();
00046   Point2d speed;
00047   GetSpeedXY(speed);
00048 
00049   angle_rad += speed.Norm() * 20;
00050   angle_rad = fmod(angle_rad, 2 *M_PI);
00051   //FIXME what about negatives values ? what would happen ?
00052   if(m_left_time_to_live < 50)
00053     image->SetAlpha(m_left_time_to_live / 50.0);
00054   image->SetRotation_rad(angle_rad);
00055   image->Update();
00056 }

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