Gel2D - The free/open source game creation suite

gelParticle.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 2011 Mark D. Procarione
00004 
00005 Gel2D is free software: you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation, either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 Gel2D is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __GELPARTICLE_H__
00017 #define __GELPARTICLE_H__
00018 
00019 #include "gelObject.h"
00020 #include "gelColor.h"
00021 #include "gelTimer.h"
00022 #include "gelMath.h"
00023 
00024 #define GEL2D_PARSYS_HEADER "GEL2D_PARSYS_v0.1"
00025 #define GEL_MAX_PARTICLES 1000
00026 
00027 namespace gel
00028 {
00030     struct GelParticle
00031     {
00033 
00034                 GelParticle();
00035 
00037         Gel2dVec pos;
00039         Gel2dVec size;
00041         Gel2dVec sizeDelta;
00043         float    rot;
00045         float    rotDelta;
00047         Gel2dVec vel;
00049         GelColor col;
00051         GelColor colDelta;
00052 
00054         float gravity;
00056 
00057         float radialAccel;
00059 
00060         float tangetAccel;
00061 
00063         float life;
00065         float age;
00066     };
00067 
00069 
00070     struct GelParSysData
00071     {
00072         int emissionRate;
00073 
00074         int infiniteSysLife;
00075         float sysLife;
00076 
00077         Gel2dVec originDis;
00078 
00079         float direction;
00080         float spread;
00081 
00082         float minLife;
00083         float maxLife;
00084 
00085         float minSpeed;
00086         float maxSpeed;
00087 
00088         float minGravity;
00089         float maxGravity;
00090 
00091         float minRadialAccel;
00092         float maxRadialAccel;
00093 
00094         float minTangetAccel;
00095         float maxTangetAccel;
00096 
00097         float startSize;
00098         float endSize;
00099         float randSize;
00100 
00101         float parRot;
00102         float randRot;
00103 
00104         float startAlpha;
00105         float endAlpha;
00106         float randAlpha;
00107 
00108         GelColor minStartCol;
00109         GelColor maxStartCol;
00110         GelColor minEndCol;
00111         GelColor maxEndCol;
00112         GelColor randCol;
00113 
00114         Gel2dVec uv[4];
00115     };
00116 
00118     class GelParticleSys : public GelObject, public GelTextureObject
00119     {
00120         public:
00122             GelParticleSys();
00123 
00125 
00128             GelParticleSys( const char *desc_name );
00129 
00131             ~GelParticleSys();
00132 
00134 
00135             Gel2dVec getLoc() const { return location; }
00136 
00138 
00143             void setLoc( Gel2dVec loc ) { location = loc; }
00144 
00146 
00147             void fire() { sysAge = 0.0; }
00148 
00150 
00151                 void setTexture( GelTexture *tex );
00152 
00153             void mapRect( const Gel2dVec &pos, const Gel2dVec &size);
00154 
00156 
00157             int writeDesc( const char *filename );
00158 
00160 
00163             int readDesc( const char *filename );
00164 
00166 
00167             void update();
00168 
00170             void render();
00171 
00172         private:
00173                         GelParticle particles[GEL_MAX_PARTICLES];
00174 
00175                         int aliveCount;
00176 
00177             Gel2dVec location;   // emitter location
00178 
00179             GelTimer timer;
00180             double ticks;
00181 
00182                         float sysAge;
00183 
00184         public:
00185             int emissionRate;
00186 
00187                         bool infiniteSysLife;
00188                         float sysLife;
00189 
00190                         Gel2dVec originDis;
00191 
00192                         float direction;
00193                 float spread;
00194 
00195                         float minLife;
00196                         float maxLife;
00197 
00198                         float minSpeed;
00199                         float maxSpeed;
00200 
00201                         float minGravity;
00202                         float maxGravity;
00203 
00204                         float minRadialAccel;
00205                         float maxRadialAccel;
00206 
00207                         float minTangetAccel;
00208                         float maxTangetAccel;
00209 
00210                         float startSize;
00211                         float endSize;
00212                         float randSize;
00213 
00214                         float parRot;
00215                         float randRot;
00216 
00217                         float startAlpha;
00218                         float endAlpha;
00219                         float randAlpha;
00220 
00221                         GelColor minStartCol;
00222                         GelColor maxStartCol;
00223                         GelColor minEndCol;
00224                         GelColor maxEndCol;
00225                         GelColor randCol;
00226 
00227                         Gel2dVec uv[4];
00228     };
00229 }
00230 
00231 #endif // __GELPARTICLE_H__