Debian Codegraph @

engine/particle/graphicanimation.cpp

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name graphicanimation.cpp - The Graphic Animation class. */
11 //
12 // (c) Copyright 2007-2008 by Francois Beerten
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27 //
28
29 //@{
30
31 #include "stratagus.h"
32 #include "particle.h"
33 #include "video.h"
34
35 GraphicAnimation::GraphicAnimation(CGraphic *g, int ticksPerFrame) :
36 g(g), ticksPerFrame(ticksPerFrame), currentFrame(0), currTicks(0)
37 {
38 Assert(g);
39 }
40
41
42 void GraphicAnimation::draw(int x, int y)
43 {
44 if (!isFinished()) {
45 g->DrawFrameClip(currentFrame, x - g->Width / 2, y - g->Height / 2);
46 }
47 }
48
49 void GraphicAnimation::update(int ticks)
50 {
51 currTicks += ticks;
52 while (currTicks > ticksPerFrame) {
53 currTicks -= ticksPerFrame;
54 ++currentFrame;
55 }
56 }
57
58 bool GraphicAnimation::isFinished()
59 {
60 return currentFrame >= g->NumFrames;
61 }
62
63 Animation * GraphicAnimation::clone()
64 {
65 return new GraphicAnimation(g, ticksPerFrame);
66 }
67
68 //@}