From: drumsetmonkey Date: Wed, 13 Jan 2016 13:31:26 +0000 (-0500) Subject: Added fire X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=01c0446eaaf8f84a35ce5d5d82c55b7e155f7e43;p=clyne%2Fgamedev.git Added fire --- 01c0446eaaf8f84a35ce5d5d82c55b7e155f7e43 diff --cc include/entities.h index 8ef7c90,1e6d316..412ec42 --- a/include/entities.h +++ b/include/entities.h @@@ -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); @@@ -97,12 -94,8 +98,13 @@@ 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 bd3d89b,dba3605..bff283d --- a/main.cpp +++ 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; } } diff --cc src/entities.cpp index 817a1b0,b4c34d9..01b379b --- a/src/entities.cpp +++ b/src/entities.cpp @@@ -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 58606e5,3d7027d..6ee7255 --- a/src/world.cpp +++ b/src/world.cpp @@@ -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;ikill(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(); } @@@ -781,7 -778,7 +782,7 @@@ /* * 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){