]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added fire
authordrumsetmonkey <abelleisle@roadrunner.com>
Wed, 13 Jan 2016 13:31:26 +0000 (08:31 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Wed, 13 Jan 2016 13:31:26 +0000 (08:31 -0500)
1  2 
include/entities.h
main.cpp
src/entities.cpp
src/world.cpp

index 8ef7c90c1712eec55de48f217a703ce91e1315d0,1e6d31649c6e30f813ae23c13db41e302a7da92e..412ec42537d7064d8ce58c562947dfa8bb320878
@@@ -82,11 -81,9 +82,12 @@@ public
        float velx;
        float vely;
        Color color;
 -      int duration;
 +      float duration;
        bool canMove;
 -      Particles(float x, float y, float w, float h, float vx, float vy, Color c, int d){
 +      bool fountain;
 +      bool gravity;
++      bool behind;
 +      Particles(float x, float y, float w, float h, float vx, float vy, Color c, float d){
                loc.x = (x);
                loc.y = (y);
                width = (w);
                color.green = (c.green);
                color.blue = (c.blue);
                duration = d;
 +              fountain = false;
 +              gravity = true;
++              behind = false;
 +      }
 +      ~Particles(){
 +
        }
 -      ~Particles(){}
        void draw(){
                glColor3f(color.red,color.green,color.blue);
                glRectf(loc.x,loc.y,loc.x+width,loc.y+height);
diff --cc main.cpp
index bd3d89b2e63684038b5b1ccb395da98979e6b6d3,dba36052ffa12cba4a6ab2f7ba2763042df36690..bff283d7da929d9642f4a75c57e9f6943877dbf1
+++ b/main.cpp
@@@ -941,20 -943,9 +941,21 @@@ void logic()
                }
        }
        for(auto &b : currentWorld->build){
 -              if(b->bsubtype == FOUNTAIN){
 -                      for(int r = 0; r < (rand()%20)+10;r++)
 -                              currentWorld->addParticle(rand()%HLINE*3 + b->loc.x + b->width/2,b->loc.y + b->height, HLINE,HLINE, rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01,((4+rand()%6)*.05), {0,0,1.0f}, 2500);
 +              switch(b->bsubtype){
 +                      case FOUNTAIN:
 +                              for(int r = 0; r < (rand()%20)+10;r++){
 +                                      currentWorld->addParticle(rand()%HLINE*3 + b->loc.x + b->width/2,b->loc.y + b->height, HLINE,HLINE, rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01,((4+rand()%6)*.05), {0,0,1.0f}, 2500);
 +                                      currentWorld->particles.back()->fountain = true;
 +                              }
 +                              break;
 +                      case FIRE_PIT:
 +                              for(int r = 0; r < (rand()%20)+10;r++){
-                                       currentWorld->addParticle(rand()%(int)(b->width) + b->loc.x, b->loc.y, HLINE, HLINE, rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01,((4+rand()%6)*.05), {1.0f,0.0f,0.0f}, 100);
++                                      currentWorld->addParticle(rand()%(int)(b->width/2) + b->loc.x+b->width/4, b->loc.y+3*HLINE, HLINE, HLINE, rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01,((4+rand()%6)*.05), {1.0f,0.0f,0.0f}, 100);
 +                                      currentWorld->particles.back()->gravity = false;
++                                      currentWorld->particles.back()->behind = true;
 +                              }
 +                              break;
 +                      default: break;
                }
        }
        
index 817a1b07fe7f7e1da730dd2c282abcd4a4fcbb8c,b4c34d958d9441f635aef2c55cccfb550c0b23d6..01b379b4a59d5ec390c2c162658d01dd0ff18723
@@@ -501,11 -498,6 +501,12 @@@ unsigned int Structures::spawn(BUILD_SU
                        height = 40 * HLINE;
                        oi->addLight({x+SCREEN_WIDTH/2,y+30*HLINE},{1.0f,1.0f,1.0f});
                        break;
 +              case FIRE_PIT:
 +                      tex = new Texturec(1, sTexLoc[sub].c_str());
 +                      width =  12 * HLINE;
 +                      height = 12 * HLINE;
++                      oi->addLight({x+SCREEN_WIDTH/2,y},{1.0f,1.0f,1.0f});
 +                      break;
                default:
                        break;
        }
diff --cc src/world.cpp
index 58606e5cd4560f2c9cc0a1e4f31786d7bdd02c06,3d7027dc1dfbd5515e03d23e1c9b2d06dcd37ebb..6ee725535a3ff748ad714421f7f021c7ab2316d5
@@@ -424,21 -421,21 +424,21 @@@ void World::update(Player *p,unsigned i
           else if(e->vel.x > 0)e->left = false;
                }
        }
-       for(auto &pa : particles){
-               if(pa->kill(deltaTime)){
-                       //delete pa;
-                       //particles.erase(particles.begin()+oh);
-                       std::cout << pa.duration;
-                       std::cout << particles[oh].duration;
-               }else if(pa->canMove){
-                       pa->loc.y += pa->vely * deltaTime;
-                       pa->loc.x += pa->velx * deltaTime;
 -      
++
+       for(unsigned int i=0;i<particles.size();i++){
+               if(particles[i]->kill(deltaTime)){
+                       delete particles[i];
+                       particles.erase(particles.begin()+i);
+               }else if(particles[i]->canMove){
+                       particles[i]->loc.y += particles[i]->vely * deltaTime;
+                       particles[i]->loc.x += particles[i]->velx * deltaTime;
                        for(auto &b : build){
-                               if(b->bsubtype==FOUNTAIN && pa->fountain){
-                                       if(pa->loc.x >= b->loc.x && pa->loc.x <= b->loc.x+b->width){
-                                               if(pa->loc.y <= b->loc.y + b->height*.25){
-                                                       delete pa;
-                                                       particles.erase(particles.begin()+oh);
+                               if(b->bsubtype==FOUNTAIN){
+                                       if(particles[i]->loc.x >= b->loc.x && particles[i]->loc.x <= b->loc.x + b->width){
+                                               if(particles[i]->loc.y <= b->loc.y + b->height * .25){
+                                                       delete particles[i];
+                                                       particles.erase(particles.begin()+i);
                                                }
                                        }
                                }
@@@ -657,7 -654,7 +657,8 @@@ LOOP2
         *      Draw structures. We draw structures behind the dirt/grass so that the building's
         *      corners don't stick out.
        */
--      
++
++      for(auto &part : particles){if(part->behind)part->draw();}
        for(auto &b : current->build){
                b->draw();
        }
        /*
         *      Draw non-structure entities.
        */
--      for(auto &part : particles){part->draw();}
++      for(auto &part : particles){if(!part->behind)part->draw();}
        for(auto &n : current->npc){
                n->loc.y+=(yoff-DRAW_Y_OFFSET);
                n->draw();
@@@ -1125,9 -1122,9 +1126,11 @@@ void World::addParticle(float x, float 
  }
  
  void World::addLight(vec2 loc, Color color){
--      light.push_back(Light());
--      light.back().loc = loc;
--      light.back().color = color;
++      if(light.size() < 64){
++              light.push_back(Light());
++              light.back().loc = loc;
++              light.back().color = color;
++      }
  }
  
  /*void World::removeObject(Object i){