1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
11 /**@name smokeparticle.cpp - The smoke particle. */
12 //
13 // (c) Copyright 2007-2008 by Jimmy Salmon and Francois Beerten
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 //
29
30 //@{
31 #include "stratagus.h"
32 #include "particle.h"
33 #include "video.h"
34
35
36
37
CSmokeParticle(CPosition position,GraphicAnimation * smoke,float speedx,float speedy,int drawlevel)38 CSmokeParticle::CSmokeParticle(CPosition position, GraphicAnimation *smoke,
39 float speedx, float speedy, int drawlevel) :
40 CParticle(position, drawlevel)
41 {
42 Assert(smoke);
43 this->puff = smoke->clone();
44
45 speedVector.x = speedx;
46 speedVector.y = speedy;
47 }
48
~CSmokeParticle()49 CSmokeParticle::~CSmokeParticle()
50 {
51 delete puff;
52 }
53
isVisible(const CViewport & vp) const54 bool CSmokeParticle::isVisible(const CViewport &vp) const
55 {
56 return puff && puff->isVisible(vp, pos);
57 }
58
draw()59 void CSmokeParticle::draw()
60 {
61 CPosition screenPos = ParticleManager.getScreenPos(pos);
62 puff->draw(static_cast<int>(screenPos.x), static_cast<int>(screenPos.y));
63 }
64
update(int ticks)65 void CSmokeParticle::update(int ticks)
66 {
67 puff->update(ticks);
68 if (puff->isFinished()) {
69 destroy();
70 return;
71 }
72
73 // smoke rises
74 pos.x += ticks / 1000.f * speedVector.x;
75 pos.y += ticks / 1000.f * speedVector.y;
76 }
77
clone()78 CParticle *CSmokeParticle::clone()
79 {
80 return new CSmokeParticle(pos, puff, speedVector.x, speedVector.y, drawLevel);
81 }
82
83 //@}
84