| 1 |
// ____ _ __ |
| 2 |
// / __ )____ _____ | | / /___ ___________ |
| 3 |
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
// /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
// |
| 7 |
// A futuristic real-time strategy game. |
| 8 |
// This file is part of Bos Wars. |
| 9 |
// |
| 10 |
/**@name particle.h - The base particle headerfile. */ |
| 11 |
// |
| 12 |
// (c) Copyright 2007-2008 by Jimmy Salmon and 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 |
#ifndef __PARTICLE_H__ |
| 29 |
#define __PARTICLE_H__ |
| 30 |
|
| 31 |
//@{ |
| 32 |
|
| 33 |
#include <vector> |
| 34 |
|
| 35 |
class CGraphic; |
| 36 |
class CViewport; |
| 37 |
|
| 38 |
|
| 39 |
struct CPosition |
| 40 |
{ |
| 41 |
CPosition(float x, float y) : x(x), y(y) {} |
| 42 |
float x; |
| 43 |
float y; |
| 44 |
}; |
| 45 |
|
| 46 |
class Animation |
| 47 |
{ |
| 48 |
public: |
| 49 |
virtual ~Animation() {} |
| 50 |
virtual void draw(int x, int y) = 0; |
| 51 |
virtual void update(int ticks) = 0; |
| 52 |
virtual bool isFinished() = 0; |
| 53 |
virtual Animation * clone() = 0; |
| 54 |
}; |
| 55 |
|
| 56 |
class GraphicAnimation : public Animation |
| 57 |
{ |
| 58 |
CGraphic *g; |
| 59 |
int ticksPerFrame; |
| 60 |
int currentFrame; |
| 61 |
int currTicks; |
| 62 |
public: |
| 63 |
GraphicAnimation(CGraphic *g, int ticksPerFrame); |
| 64 |
virtual ~GraphicAnimation() {} |
| 65 |
|
| 66 |
/** |
| 67 |
** Draw the current frame of the animation. |
| 68 |
** @param x x screen coordinate where to draw the animation. |
| 69 |
** @param y y screen coordinate where to draw the animation. |
| 70 |
*/ |
| 71 |
virtual void draw(int x, int y); |
| 72 |
|
| 73 |
/** |
| 74 |
** Update the animation. |
| 75 |
** @param ticks the number of ticks elapsed since the last call. |
| 76 |
*/ |
| 77 |
virtual void update(int ticks); |
| 78 |
|
| 79 |
virtual bool isFinished(); |
| 80 |
|
| 81 |
virtual Animation * clone(); |
| 82 |
}; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
// Base particle class |
| 87 |
class CParticle |
| 88 |
{ |
| 89 |
public: |
| 90 |
CParticle(CPosition position) : |
| 91 |
pos(position), destroyed(false) |
| 92 |
{} |
| 93 |
virtual ~CParticle() {} |
| 94 |
|
| 95 |
virtual void draw() {} |
| 96 |
virtual void update(int ticks) {} |
| 97 |
|
| 98 |
inline void destroy() { destroyed = true; } |
| 99 |
inline bool isDestroyed() { return destroyed; } |
| 100 |
|
| 101 |
virtual CParticle * clone() = 0; |
| 102 |
|
| 103 |
protected: |
| 104 |
CPosition pos; |
| 105 |
bool destroyed; |
| 106 |
}; |
| 107 |
|
| 108 |
|
| 109 |
class StaticParticle : public CParticle |
| 110 |
{ |
| 111 |
public: |
| 112 |
StaticParticle(CPosition position, Animation *flame); |
| 113 |
virtual ~StaticParticle(); |
| 114 |
|
| 115 |
virtual void draw(); |
| 116 |
virtual void update(int ticks); |
| 117 |
virtual CParticle * clone(); |
| 118 |
|
| 119 |
protected: |
| 120 |
Animation *animation; |
| 121 |
}; |
| 122 |
|
| 123 |
|
| 124 |
// Chunk particle |
| 125 |
class CChunkParticle : public CParticle |
| 126 |
{ |
| 127 |
public: |
| 128 |
CChunkParticle(CPosition position, Animation *smokeAnimation); |
| 129 |
virtual ~CChunkParticle(); |
| 130 |
|
| 131 |
virtual void draw(); |
| 132 |
virtual void update(int ticks); |
| 133 |
virtual CParticle * clone(); |
| 134 |
|
| 135 |
protected: |
| 136 |
CPosition initialPos; |
| 137 |
int initialVelocity; |
| 138 |
float trajectoryAngle; |
| 139 |
int nextSmokeTicks; |
| 140 |
int lifetime; |
| 141 |
int age; |
| 142 |
float height; |
| 143 |
Animation *smokeAnimation; |
| 144 |
|
| 145 |
struct { |
| 146 |
float x; |
| 147 |
float y; |
| 148 |
} direction; |
| 149 |
}; |
| 150 |
|
| 151 |
|
| 152 |
// Smoke particle |
| 153 |
class CSmokeParticle : public CParticle |
| 154 |
{ |
| 155 |
public: |
| 156 |
CSmokeParticle(CPosition position, Animation *animation); |
| 157 |
virtual ~CSmokeParticle(); |
| 158 |
|
| 159 |
virtual void draw(); |
| 160 |
virtual void update(int ticks); |
| 161 |
virtual CParticle * clone(); |
| 162 |
|
| 163 |
protected: |
| 164 |
Animation *puff; |
| 165 |
}; |
| 166 |
|
| 167 |
|
| 168 |
class CParticleManager |
| 169 |
{ |
| 170 |
public: |
| 171 |
CParticleManager(); |
| 172 |
~CParticleManager(); |
| 173 |
|
| 174 |
static void init(); |
| 175 |
static void exit(); |
| 176 |
|
| 177 |
void draw(const CViewport *vp); |
| 178 |
void update(); |
| 179 |
|
| 180 |
void add(CParticle *particle); |
| 181 |
void clear(); |
| 182 |
|
| 183 |
CPosition getScreenPos(const CPosition &pos); |
| 184 |
|
| 185 |
inline void setLowDetail(bool detail) { lowDetail = detail; } |
| 186 |
inline bool getLowDetail() const { return lowDetail; } |
| 187 |
|
| 188 |
private: |
| 189 |
std::vector<CParticle *> particles; |
| 190 |
std::vector<CParticle *> new_particles; |
| 191 |
const CViewport *vp; |
| 192 |
unsigned long lastTicks; |
| 193 |
bool lowDetail; |
| 194 |
}; |
| 195 |
|
| 196 |
extern CParticleManager ParticleManager; |
| 197 |
|
| 198 |
//@} |
| 199 |
|
| 200 |
#endif // !__PARTICLE_H__ |