$treeview $search $mathjax
Stratagus
2.2.7
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
00001 // _________ __ __ 00002 // / _____// |_____________ _/ |______ ____ __ __ ______ 00003 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 00004 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | 00005 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 00006 // \/ \/ \//_____/ \/ 00007 // ______________________ ______________________ 00008 // T H E W A R B E G I N S 00009 // Stratagus - A free fantasy real time strategy game engine 00010 // 00012 // 00013 // (c) Copyright 2007-2008 by Jimmy Salmon and Francois Beerten 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; only version 2 of the License. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 00029 #ifndef __PARTICLE_H__ 00030 #define __PARTICLE_H__ 00031 00033 00034 #include <vector> 00035 00036 class CGraphic; 00037 class CViewport; 00038 00039 00040 struct CPosition { 00041 CPosition(float x, float y) : x(x), y(y) {} 00042 float x; 00043 float y; 00044 }; 00045 00046 class Animation 00047 { 00048 public: 00049 virtual ~Animation() {} 00050 virtual void draw(int x, int y) = 0; 00051 virtual void update(int ticks) = 0; 00052 virtual bool isFinished() = 0; 00053 virtual Animation *clone() = 0; 00054 }; 00055 00056 class GraphicAnimation : public Animation 00057 { 00058 CGraphic *g; 00059 int ticksPerFrame; 00060 int currentFrame; 00061 int currTicks; 00062 public: 00063 GraphicAnimation(CGraphic *g, int ticksPerFrame); 00064 virtual ~GraphicAnimation() {} 00065 00071 virtual void draw(int x, int y); 00072 00077 virtual void update(int ticks); 00078 00079 virtual bool isFinished(); 00080 00081 virtual Animation *clone(); 00082 }; 00083 00084 00085 00086 // Base particle class 00087 class CParticle 00088 { 00089 public: 00090 CParticle(CPosition position) : 00091 pos(position), destroyed(false) 00092 {} 00093 virtual ~CParticle() {} 00094 00095 virtual void draw() {} 00096 virtual void update(int) {} 00097 00098 inline void destroy() { destroyed = true; } 00099 inline bool isDestroyed() { return destroyed; } 00100 00101 virtual CParticle *clone() = 0; 00102 00103 protected: 00104 CPosition pos; 00105 bool destroyed; 00106 }; 00107 00108 00109 class StaticParticle : public CParticle 00110 { 00111 public: 00112 StaticParticle(CPosition position, Animation *flame); 00113 virtual ~StaticParticle(); 00114 00115 virtual void draw(); 00116 virtual void update(int ticks); 00117 virtual CParticle *clone(); 00118 00119 protected: 00120 Animation *animation; 00121 }; 00122 00123 00124 // Chunk particle 00125 class CChunkParticle : public CParticle 00126 { 00127 public: 00128 CChunkParticle(CPosition position, Animation *smokeAnimation, Animation *debrisAnimation, 00129 int minVelocity, int maxVelocity, int minTrajectoryAngle); 00130 virtual ~CChunkParticle(); 00131 00132 virtual void draw(); 00133 virtual void update(int ticks); 00134 virtual CParticle *clone(); 00135 00136 protected: 00137 CPosition initialPos; 00138 int initialVelocity; 00139 float trajectoryAngle; 00140 int nextSmokeTicks; 00141 int lifetime; 00142 int age; 00143 int minVelocity; 00144 int maxVelocity; 00145 int minTrajectoryAngle; 00146 float height; 00147 Animation *debrisAnimation; 00148 Animation *smokeAnimation; 00149 00150 struct { 00151 float x; 00152 float y; 00153 } direction; 00154 }; 00155 00156 00157 // Smoke particle 00158 class CSmokeParticle : public CParticle 00159 { 00160 public: 00161 CSmokeParticle(CPosition position, Animation *animation); 00162 virtual ~CSmokeParticle(); 00163 00164 virtual void draw(); 00165 virtual void update(int ticks); 00166 virtual CParticle *clone(); 00167 00168 protected: 00169 Animation *puff; 00170 }; 00171 00172 class CRadialParticle : public CParticle 00173 { 00174 public: 00175 CRadialParticle(CPosition position, Animation *animation, int maxSpeed); 00176 virtual ~CRadialParticle(); 00177 00178 virtual void draw(); 00179 virtual void update(int ticks); 00180 virtual CParticle *clone(); 00181 00182 protected: 00183 Animation *animation; 00184 float direction; 00185 int speed; 00186 int maxSpeed; 00187 }; 00188 00189 00190 class CParticleManager 00191 { 00192 public: 00193 CParticleManager(); 00194 ~CParticleManager(); 00195 00196 static void init(); 00197 static void exit(); 00198 00199 void draw(const CViewport &vp); 00200 void update(); 00201 00202 void add(CParticle *particle); 00203 void clear(); 00204 00205 CPosition getScreenPos(const CPosition &pos) const; 00206 00207 inline void setLowDetail(bool detail) { lowDetail = detail; } 00208 inline bool getLowDetail() const { return lowDetail; } 00209 00210 private: 00211 std::vector<CParticle *> particles; 00212 std::vector<CParticle *> new_particles; 00213 const CViewport *vp; 00214 unsigned long lastTicks; 00215 bool lowDetail; 00216 }; 00217 00218 extern CParticleManager ParticleManager; 00219 00221 00222 #endif // !__PARTICLE_H__