From 4e60d3e2d3f66471dff75732626451690a5bc8b5 Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Wed, 23 Mar 2016 08:24:55 -0400 Subject: Flickering lights and light that follows player --- src/ui.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/ui.cpp') diff --git a/src/ui.cpp b/src/ui.cpp index 458e797..f0736a5 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -1445,10 +1445,18 @@ EXIT: heyOhLetsGo = 0; break; case SDLK_l: - player->light^=true; + currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); + currentWorld->light.back().belongsTo = true; + currentWorld->light.back().following = player; + currentWorld->light.back().flame = true; break; case SDLK_f: currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); + std::cout << currentWorld->light.back().belongsTo << std::endl; + currentWorld->light.back().belongsTo = false; + std::cout << currentWorld->light.back().belongsTo << std::endl; + currentWorld->light.back().following = nullptr; + currentWorld->light.back().flame = true; break; case SDLK_g: //currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, NULL); @@ -1465,13 +1473,15 @@ EXIT: case SDLK_b: currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, "", ""); currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); + currentWorld->light.back().belongsTo = false; + currentWorld->light.back().following = nullptr; + currentWorld->light.back().flame = true; break; case SDLK_F12: // Make the BYTE array, factor of 3 because it's RBG. static GLubyte* pixels; pixels = new GLubyte[ 3 * SCREEN_WIDTH * SCREEN_HEIGHT]; glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels); - //static std::thread scr; //scr = std::thread(takeScreenshot,pixels); //scr.detach(); -- cgit v1.2.3 From c9bce16570160af24ae7f1f04249aa0e8313fb06 Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Thu, 24 Mar 2016 08:25:56 -0400 Subject: Fire flickering --- include/world.h | 31 ++++++++++++++++++++++--------- src/ui.cpp | 16 ++++------------ src/world.cpp | 56 ++++++++++++++++++++++++++++++-------------------------- 3 files changed, 56 insertions(+), 47 deletions(-) (limited to 'src/ui.cpp') diff --git a/include/world.h b/include/world.h index 85b5370..51fbbfd 100644 --- a/include/world.h +++ b/include/world.h @@ -79,7 +79,8 @@ class World; * The light structure, used to store light coordinates and color. */ -typedef struct { +class Light{ +public: vec2 loc; /**< Light location */ Color color; /**< Light color */ float radius; /**< Light radius */ @@ -91,14 +92,26 @@ typedef struct { float fireFlicker; vec2 fireLoc; - // Light(vec2 l, Color c, float r){ - // loc = l; - // color = c; - // radius = r; - // belongsTo = false; - // following = nullptr; - // } -} Light; + Light(vec2 l, Color c, float r){ + loc = l; + color = c; + radius = r; + + belongsTo = false; + following = nullptr; + + flame = false; + } + + void makeFlame(void){ + flame = true; + } + + void follow(Entity *f){ + following=f; + belongsTo = true; + } +}; /** diff --git a/src/ui.cpp b/src/ui.cpp index f0736a5..e3e3e7d 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -858,7 +858,6 @@ namespace ui { void quitGame(){ dialogBoxExists = false; currentMenu = NULL; - delete[] currentMenu; gameRunning = false; updateConfig(); saveConfig(); @@ -1446,17 +1445,11 @@ EXIT: break; case SDLK_l: currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); - currentWorld->light.back().belongsTo = true; - currentWorld->light.back().following = player; - currentWorld->light.back().flame = true; + currentWorld->light.back().follow(player); + currentWorld->light.back().makeFlame(); break; case SDLK_f: currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); - std::cout << currentWorld->light.back().belongsTo << std::endl; - currentWorld->light.back().belongsTo = false; - std::cout << currentWorld->light.back().belongsTo << std::endl; - currentWorld->light.back().following = nullptr; - currentWorld->light.back().flame = true; break; case SDLK_g: //currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, NULL); @@ -1473,9 +1466,8 @@ EXIT: case SDLK_b: currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, "", ""); currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); - currentWorld->light.back().belongsTo = false; - currentWorld->light.back().following = nullptr; - currentWorld->light.back().flame = true; + currentWorld->light.back().follow(currentWorld->build.back()); + currentWorld->light.back().makeFlame(); break; case SDLK_F12: // Make the BYTE array, factor of 3 because it's RBG. diff --git a/src/world.cpp b/src/world.cpp index ca070a8..0e0b8aa 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -532,17 +532,38 @@ draw( Player *p ) for(auto &l : light){ if(l.belongsTo){ l.loc.x = l.following->loc.x + SCREEN_WIDTH/2; + l.loc.y = l.following->loc.y; + } + if(l.flame){ + l.fireFlicker = .9+((rand()%2)/10.0f); + l.fireLoc.x = l.loc.x + (rand()%2-1)*3; + l.fireLoc.y = l.loc.y + (rand()%2-1)*3; + + //std::cout << l.fireLoc.x << "," << l.fireLoc.y << std::endl; + //std::cout << l.loc.x << "," << l.loc.y << std::endl << std::endl; + }else{ + l.fireFlicker = 1.0f; } } - std::unique_ptr pointArrayBuf = std::make_unique (2 * (light.size())); + std::unique_ptr pointArrayBuf = std::make_unique (2 * (light.size())); auto pointArray = pointArrayBuf.get(); + GLfloat flameArray[64]; - for ( i = 0; i < (int)light.size(); i++ ) { - pointArray[2 * i ] = light[i].loc.x - offset.x; - pointArray[2 * i + 1] = light[i].loc.y; + for (uint i = 0; i < light.size(); i++) { + if(light[i].flame){ + pointArray[2 * i ] = light[i].fireLoc.x - offset.x; + pointArray[2 * i + 1] = light[i].fireLoc.y; + }else{ + pointArray[2 * i ] = light[i].loc.x - offset.x; + pointArray[2 * i + 1] = light[i].loc.y; + } } + for(uint i = 0; i < light.size(); i++){ + flameArray[i] = light[i].fireFlicker; + } + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); @@ -556,6 +577,7 @@ draw( Player *p ) glUniform1i ( glGetUniformLocation( shaderProgram, "numLight" ), light.size()); glUniform2fv( glGetUniformLocation( shaderProgram, "lightLocation"), light.size(), pointArray ); glUniform3f ( glGetUniformLocation( shaderProgram, "lightColor" ), 1.0f, 1.0f, 1.0f ); + glUniform1fv(glGetUniformLocation(shaderProgram,"fireFlicker"), light.size(),flameArray); } /* @@ -966,11 +988,8 @@ addParticle( float x, float y, float w, float h, float vx, float vy, Color color } void World::addLight(vec2 loc, Color color){ - Light l; - if ( light.size() < 64 ) { - l.loc = loc; - l.color = color; - light.push_back(l); + if(light.size() < 64){ + light.push_back(Light(loc,color,1)); } } @@ -1222,10 +1241,8 @@ void IndoorWorld::draw(Player *p){ //glEnable(GL_TEXTURE_2D); - std::cout << "Lights and shit" << std::endl; for(auto &l : light){ if(l.belongsTo){ - std::cout << "Is following" << std::endl; l.loc.x = l.following->loc.x + SCREEN_WIDTH/2; l.loc.y = l.following->loc.y; } @@ -1234,19 +1251,17 @@ void IndoorWorld::draw(Player *p){ l.fireLoc.x = l.loc.x + (rand()%2-1)*3; l.fireLoc.y = l.loc.y + (rand()%2-1)*3; - std::cout << l.fireLoc.x << "," << l.fireLoc.y << std::endl; - std::cout << l.loc.x << "," << l.loc.y << std::endl << std::endl; + //std::cout << l.fireLoc.x << "," << l.fireLoc.y << std::endl; + //std::cout << l.loc.x << "," << l.loc.y << std::endl << std::endl; }else{ l.fireFlicker = 1.0f; } } - std::cout << "Making light arrays" << std::endl; std::unique_ptr pointArrayBuf = std::make_unique (2 * (light.size())); auto pointArray = pointArrayBuf.get(); GLfloat flameArray[64]; - std::cout << "Setting array locations" << std::endl; for (i = 0; i < light.size(); i++) { if(light[i].flame){ pointArray[2 * i ] = light[i].fireLoc.x - offset.x; @@ -1257,7 +1272,6 @@ void IndoorWorld::draw(Player *p){ } } - std::cout << "Flame array" << std::endl; for(i = 0; i < light.size(); i++){ flameArray[i] = light[i].fireFlicker; } @@ -1268,9 +1282,7 @@ void IndoorWorld::draw(Player *p){ glUseProgram( shaderProgram ); glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); glUniform1f(glGetUniformLocation(shaderProgram, "amb" ), 0.02f + light.size()/50.0f); - glUniform1i(glGetUniformLocation(shaderProgram, "fire" ), 1); - std::cout << "Uniform sending" << std::endl; if ( light.size() == 0) glUniform1i(glGetUniformLocation(shaderProgram, "numLight"), 0); else { @@ -1282,8 +1294,6 @@ void IndoorWorld::draw(Player *p){ //delete[] flameArray; - std::cout << "Done shading" << std::endl; - bgTex->bind(0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction @@ -1299,8 +1309,6 @@ void IndoorWorld::draw(Player *p){ glUseProgram(0); //glDisable(GL_TEXTURE_2D); - std::cout << "Faggot" << std::endl; - /* * Calculate the starting and ending points to draw the ground from. */ @@ -1334,8 +1342,6 @@ void IndoorWorld::draw(Player *p){ glEnd(); glUseProgram(0); - std::cout << "Queer" << std::endl; - /* * Draw all entities. */ @@ -1347,8 +1353,6 @@ void IndoorWorld::draw(Player *p){ e->draw(); p->draw(); - - std::cout << "Cranmore Tubing park" << std::endl; } Arena::Arena(World *leave,Player *p,Mob *m){ -- cgit v1.2.3