____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
A futuristic real-time strategy game.
This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project.
Distributed under the "GNU General Public License"00001 // ____ _ __ 00002 // / __ )____ _____ | | / /___ ___________ 00003 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ 00004 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) 00005 // /_____/\____/____/ |__/|__/\__,_/_/ /____/ 00006 // 00007 // A futuristic real-time strategy game. 00008 // This file is part of Bos Wars. 00009 // 00011 // 00012 // (c) Copyright 2007-2008 by Jimmy Salmon and Francois Beerten 00013 // 00014 // This program is free software; you can redistribute it and/or modify 00015 // it under the terms of the GNU General Public License as published by 00016 // the Free Software Foundation; only version 2 of the License. 00017 // 00018 // This program is distributed in the hope that it will be useful, 00019 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 // GNU General Public License for more details. 00022 // 00023 // You should have received a copy of the GNU General Public License 00024 // along with this program; if not, write to the Free Software 00025 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00026 // 02111-1307, USA. 00027 00028 #ifndef __PARTICLE_H__ 00029 #define __PARTICLE_H__ 00030 00032 00033 #include <vector> 00034 00035 class CGraphic; 00036 class CViewport; 00037 00038 00039 struct CPosition 00040 { 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 ticks) {} 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); 00129 virtual ~CChunkParticle(); 00130 00131 virtual void draw(); 00132 virtual void update(int ticks); 00133 virtual CParticle * clone(); 00134 00135 protected: 00136 CPosition initialPos; 00137 int initialVelocity; 00138 float trajectoryAngle; 00139 int nextSmokeTicks; 00140 int lifetime; 00141 int age; 00142 float height; 00143 Animation *smokeAnimation; 00144 00145 struct { 00146 float x; 00147 float y; 00148 } direction; 00149 }; 00150 00151 00152 // Smoke particle 00153 class CSmokeParticle : public CParticle 00154 { 00155 public: 00156 CSmokeParticle(CPosition position, Animation *animation); 00157 virtual ~CSmokeParticle(); 00158 00159 virtual void draw(); 00160 virtual void update(int ticks); 00161 virtual CParticle * clone(); 00162 00163 protected: 00164 Animation *puff; 00165 }; 00166 00167 00168 class CParticleManager 00169 { 00170 public: 00171 CParticleManager(); 00172 ~CParticleManager(); 00173 00174 static void init(); 00175 static void exit(); 00176 00177 void draw(const CViewport *vp); 00178 void update(); 00179 00180 void add(CParticle *particle); 00181 void clear(); 00182 00183 CPosition getScreenPos(const CPosition &pos); 00184 00185 inline void setLowDetail(bool detail) { lowDetail = detail; } 00186 inline bool getLowDetail() const { return lowDetail; } 00187 00188 private: 00189 std::vector<CParticle *> particles; 00190 std::vector<CParticle *> new_particles; 00191 const CViewport *vp; 00192 unsigned long lastTicks; 00193 bool lowDetail; 00194 }; 00195 00196 extern CParticleManager ParticleManager; 00197 00199 00200 #endif // !__PARTICLE_H__
1.5.6