~ubuntu-branches/ubuntu/wily/xmoto/wily-proposed

« back to all changes in this revision

Viewing changes to src/RendererParticles.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-09-14 21:01:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060914210120-bvr7yu9rafb3fivp
Tags: 0.2.1-1
* New upstream release.
* Removed manpages and desktop files from the Debian package as they are now
  provided upstream.
* Make the package binNMUable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
    if(pGame != NULL) {
40
40
      Particle *p = new Particle;
 
41
      p->bFront = true;
41
42
      p->Type = Type;
42
43
      p->Pos = Pos;
43
44
      p->Vel = Vel;     
76
77
          p->fKillTime += 10000;
77
78
          p->fFireSeed = randomNum(0,100);
78
79
          break;
 
80
          
 
81
        case PT_STAR:
 
82
          p->fAngVel = randomNum(-60,60);
 
83
          p->Vel = Vector2f(randomNum(-2,2),randomNum(0,2));
 
84
          p->Acc = Vector2f(0,-4);
 
85
          break;
79
86
      }
80
87
      
81
88
      return p;
84
91
    return NULL;
85
92
  }  
86
93
 
 
94
  Particle *GameRenderer::_GetNewestParticle(ParticleType PType) {
 
95
    /* Return newest particle of a given type */
 
96
    Particle *pNewest = NULL;
 
97
    for(int i=0;i<m_Particles.size();i++) {
 
98
      if(m_Particles[i]->Type == PType &&
 
99
         (pNewest==NULL || pNewest->fSpawnTime < m_Particles[i]->fSpawnTime))
 
100
        pNewest = m_Particles[i];
 
101
    }
 
102
    return pNewest;
 
103
  }
 
104
 
87
105
  void GameRenderer::_UpdateParticles(float fTimeStep) {
88
106
    MotoGame *pGame = getGameObject();
89
107
    
97
115
      {
98
116
        for(int i=0;i<pGame->getEntities().size();i++) {
99
117
          if(pGame->getEntities()[i]->Type == ET_PARTICLESOURCE && 
100
 
            pGame->getTime()>pGame->getEntities()[i]->fNextParticleTime) {
 
118
            pGame->getTime() > pGame->getEntities()[i]->fNextParticleTime) {
101
119
            
102
120
            if(pGame->getEntities()[i]->ParticleType == "Smoke") {
103
121
              /* Generate smoke */
110
128
            else if(pGame->getEntities()[i]->ParticleType == "Fire") {
111
129
              for(int k=0;k<10;k++) {
112
130
                /* Generate fire */
113
 
                spawnParticle(PT_FIRE,pGame->getEntities()[i]->Pos,Vector2f(randomNum(-1,1),randomNum(0.1,0.3)),0);
 
131
                Particle *pFireParticle = spawnParticle(PT_FIRE,pGame->getEntities()[i]->Pos,Vector2f(randomNum(-1,1),randomNum(0.1,0.3)),0);
 
132
                pFireParticle->bFront = false;
 
133
                
114
134
                pGame->getEntities()[i]->fNextParticleTime = pGame->getTime() + randomNum(0.05,0.1f);              
115
135
              }
116
136
            }
199
219
    }
200
220
  }  
201
221
  
 
222
  void GameRenderer::clearAllParticles(void) {
 
223
    for(int i=0;i<m_Particles.size();i++) { 
 
224
      delete m_Particles[i];
 
225
    }
 
226
    m_Particles.clear();
 
227
  }
 
228
  
202
229
  void GameRenderer::_RenderParticle(Vector2f P,Texture *pTexture,float fSize,float fAngle,Color c) {
203
230
    /* Render single particle */
204
231
    if(pTexture == NULL) return;
235
262
  }
236
263
  
237
264
  void GameRenderer::_RenderParticles(bool bFront) {
 
265
    EffectSprite* pType;
 
266
 
238
267
    /* Render all particles */
239
268
    for(int i=0;i<m_Particles.size();i++) {
240
269
      if(m_Particles[i]->bFront == bFront) {
241
270
        switch(m_Particles[i]->Type) {
242
271
          case PT_SMOKE1:
243
 
            _RenderParticle(m_Particles[i]->Pos,m_pSmoke1,m_Particles[i]->fSmokeSize,
244
 
                            m_Particles[i]->fAng,m_Particles[i]->SmokeColor);
 
272
                  pType = (EffectSprite*) getParent()->m_theme.getSprite(SPRITE_TYPE_EFFECT, "Smoke1");
 
273
                  if(pType != NULL) {
 
274
                    _RenderParticle(m_Particles[i]->Pos,pType->getTexture(),m_Particles[i]->fSmokeSize,
 
275
                                    m_Particles[i]->fAng,m_Particles[i]->SmokeColor);
 
276
                  }
245
277
            break;
246
278
          case PT_SMOKE2:
247
 
            _RenderParticle(m_Particles[i]->Pos,m_pSmoke2,m_Particles[i]->fSmokeSize,
248
 
                            m_Particles[i]->fAng,m_Particles[i]->SmokeColor);
 
279
                    pType = (EffectSprite*) getParent()->m_theme.getSprite(SPRITE_TYPE_EFFECT, "Smoke2");
 
280
                    if(pType != NULL) {
 
281
                      _RenderParticle(m_Particles[i]->Pos,pType->getTexture(),m_Particles[i]->fSmokeSize,
 
282
                                      m_Particles[i]->fAng,m_Particles[i]->SmokeColor);
 
283
                    }
249
284
            break;
250
285
          case PT_FIRE:
251
 
            _RenderParticle(m_Particles[i]->Pos,m_pFire1,m_Particles[i]->fFireSize,
252
 
                            m_Particles[i]->fAng,m_Particles[i]->FireColor);
 
286
                    pType = (EffectSprite*) getParent()->m_theme.getSprite(SPRITE_TYPE_EFFECT, "Fire1");
 
287
                    if(pType != NULL) {
 
288
                      _RenderParticle(m_Particles[i]->Pos,pType->getTexture(),m_Particles[i]->fFireSize,
 
289
                                      m_Particles[i]->fAng,m_Particles[i]->FireColor);
 
290
                    }
253
291
            break;
254
292
          case PT_DEBRIS:
255
 
            _RenderParticle(m_Particles[i]->Pos,m_pDirt1,m_Particles[i]->fDebrisSize,
256
 
                            m_Particles[i]->fAng,m_Particles[i]->DebrisTint);
257
 
            break;
 
293
                  pType = (EffectSprite*) getParent()->m_theme.getSprite(SPRITE_TYPE_EFFECT, "Debris1");
 
294
                  if(pType != NULL) {
 
295
                    _RenderParticle(m_Particles[i]->Pos,pType->getTexture(),m_Particles[i]->fDebrisSize,
 
296
                                    m_Particles[i]->fAng,m_Particles[i]->DebrisTint);
 
297
                  }
 
298
                  break;
 
299
                case PT_STAR:
 
300
                  {
 
301
                    AnimationSprite *pStarAnim = (AnimationSprite *)getParent()->m_theme.getSprite(SPRITE_TYPE_ANIMATION,"Star");
 
302
                    if(pStarAnim != NULL) {
 
303
                      _RenderParticle(m_Particles[i]->Pos,pStarAnim->getTexture(),pStarAnim->getWidth(),
 
304
                                      m_Particles[i]->fAng,MAKE_COLOR(255,255,255,255));
 
305
                                }
 
306
                  }
 
307
                  break;                
258
308
        }
259
309
      }
260
310
    }
261
311
  }
262
312
 
263
 
};
 
313
}
264
314