diff options
-rw-r--r-- | assets/cat.png | bin | 402 -> 402 bytes | |||
-rw-r--r-- | assets/style/classic/bg/bgFarMountain.png | bin | 20172 -> 33711 bytes | |||
-rw-r--r-- | assets/style/classic/bg/bgn.png | bin | 1438185 -> 10675 bytes | |||
-rw-r--r-- | assets/style/classic/bg/forestTileBack.png | bin | 9657 -> 15086 bytes | |||
-rw-r--r-- | assets/style/classic/bg/forestTileFar.png | bin | 14112 -> 28260 bytes | |||
-rw-r--r-- | assets/style/classic/bg/forestTileFront.png | bin | 26722 -> 32565 bytes | |||
-rw-r--r-- | assets/style/classic/bg/forestTileMid.png | bin | 45450 -> 37280 bytes | |||
-rw-r--r-- | brice.dat | 4 | ||||
-rw-r--r-- | config/items.xml | 8 | ||||
-rw-r--r-- | frig.frag | 2 | ||||
-rw-r--r-- | include/common.hpp | 1 | ||||
-rw-r--r-- | include/entities.hpp | 12 | ||||
-rw-r--r-- | include/inventory.hpp | 12 | ||||
-rw-r--r-- | include/texture.hpp | 3 | ||||
-rw-r--r-- | include/world.hpp | 2 | ||||
-rw-r--r-- | main.cpp | 79 | ||||
-rw-r--r-- | shaders/world.frag | 29 | ||||
-rw-r--r-- | shaders/world.vert | 6 | ||||
-rw-r--r-- | src/inventory.cpp | 9 | ||||
-rw-r--r-- | src/items.cpp | 9 | ||||
-rw-r--r-- | src/mob.cpp | 4 | ||||
-rw-r--r-- | src/ui.cpp | 8 | ||||
-rw-r--r-- | src/world.cpp | 153 | ||||
-rw-r--r-- | xml/playerSpawnHill1.xml | 1 |
24 files changed, 234 insertions, 108 deletions
diff --git a/assets/cat.png b/assets/cat.png Binary files differindex 56821dd..c5b83c7 100644 --- a/assets/cat.png +++ b/assets/cat.png diff --git a/assets/style/classic/bg/bgFarMountain.png b/assets/style/classic/bg/bgFarMountain.png Binary files differindex eb703bb..dc4d682 100644 --- a/assets/style/classic/bg/bgFarMountain.png +++ b/assets/style/classic/bg/bgFarMountain.png diff --git a/assets/style/classic/bg/bgn.png b/assets/style/classic/bg/bgn.png Binary files differindex 2aa3995..1ac3127 100644 --- a/assets/style/classic/bg/bgn.png +++ b/assets/style/classic/bg/bgn.png diff --git a/assets/style/classic/bg/forestTileBack.png b/assets/style/classic/bg/forestTileBack.png Binary files differindex 0ea6022..f43346c 100644 --- a/assets/style/classic/bg/forestTileBack.png +++ b/assets/style/classic/bg/forestTileBack.png diff --git a/assets/style/classic/bg/forestTileFar.png b/assets/style/classic/bg/forestTileFar.png Binary files differindex 241e479..b7cb140 100644 --- a/assets/style/classic/bg/forestTileFar.png +++ b/assets/style/classic/bg/forestTileFar.png diff --git a/assets/style/classic/bg/forestTileFront.png b/assets/style/classic/bg/forestTileFront.png Binary files differindex e54f631..d81b2c7 100644 --- a/assets/style/classic/bg/forestTileFront.png +++ b/assets/style/classic/bg/forestTileFront.png diff --git a/assets/style/classic/bg/forestTileMid.png b/assets/style/classic/bg/forestTileMid.png Binary files differindex b23afd2..6c4c597 100644 --- a/assets/style/classic/bg/forestTileMid.png +++ b/assets/style/classic/bg/forestTileMid.png @@ -1,5 +1,5 @@ 2 -canSprint -1 canJump 1 +canSprint +1 diff --git a/config/items.xml b/config/items.xml index 1192842..0abd40d 100644 --- a/config/items.xml +++ b/config/items.xml @@ -12,7 +12,15 @@ <item name="Flashlight" type="Tool" value="1" maxStackSize="1" width="4" height="8" sprite="assets/items/flashlight_off.png" /> <item name="Fried Chicken" type="Cooked Food" value="10" maxStackSize="6" sprite="assets/items/FOOD_CHICKEN_FRIED.png" /> +<!--###########--> <!-- NEW ITEMS --> +<!--##########--> + +<!-- WEAPONS --> <item name="Wood Sword" type="Sword" damage="3" maxStackSize="1" sprite="assets/items/SWORD_WOOD.png" /> <item name="Hunters Bow" type="Bow" damage="2" maxStackSize="1" sprite="assets/items/bow.png"/> <item name="Crude Arrow" type="Arrow" damage="1" maxStackSize="99" sprite="assets/items/arrow_crude.png"/> + +<!-- UTILITIES --> +<item name="Rusty Lantern" type="Light" radius="150" color="255|255|255" sprite="assets/items/rusty_lantern.png"/> +<item name="Mossy Torch" type="Light" fire="true" radius="150" color="245|220|200" sprite="assets/items/basic_torch.png"/> @@ -31,4 +31,4 @@ void main(){ color += vec4(amb,amb,amb,1.0f+amb); gl_FragColor = tex * vec4(color)*tex.a; -}
\ No newline at end of file +} diff --git a/include/common.hpp b/include/common.hpp index 934ede5..1ef8b8a 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -238,6 +238,7 @@ extern GLint worldShader_uniform_light_color; extern GLint worldShader_uniform_light_impact; extern GLint worldShader_uniform_light_amt; +extern Color ambient; /** * Prints a formatted debug message to the console, along with the callee's file and line * number. diff --git a/include/entities.hpp b/include/entities.hpp index ca4ef2b..d2185c4 100644 --- a/include/entities.hpp +++ b/include/entities.hpp @@ -400,7 +400,8 @@ public: float fireFlicker; vec2 fireLoc; - Light(vec2 l, Color c, float r){ + Light(vec2 l, float r, Color c) + { loc = l; color = c; radius = r; @@ -411,7 +412,14 @@ public: flame = false; } - void makeFlame(void){ + void follow(Entity *f) + { + following = f; + belongsTo = true; + } + + void makeFlame(void) + { flame = true; } }; diff --git a/include/inventory.hpp b/include/inventory.hpp index 1431f42..a85e537 100644 --- a/include/inventory.hpp +++ b/include/inventory.hpp @@ -185,6 +185,18 @@ public: Food* clone(); }; +class ItemLight : public Item { +private: + // the color of the light + Color color; +public: + // turn on/off the light + // TODO + int useItem(); + + ItemLight* clone(); +}; + /** * Currency class. Well, it's used for currency */ diff --git a/include/texture.hpp b/include/texture.hpp index df2a83c..95bd73b 100644 --- a/include/texture.hpp +++ b/include/texture.hpp @@ -76,6 +76,9 @@ public: return textures[index].second; } + const dim2 getTextureDim(void) { + return Texture::imageDim((*position).second); + } }; /** diff --git a/include/world.hpp b/include/world.hpp index ce50244..ecfa14f 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -459,7 +459,7 @@ public: void addHill(ivec2 peak, unsigned int width); // functions to add entities to the world - void addLight(vec2 xy, Color color); + void addLight(vec2 xy, float radius, Color color); void addMerchant(float x, float y, bool housed); @@ -81,6 +81,9 @@ GLint worldShader_uniform_light_color; GLint worldShader_uniform_light_impact; GLint worldShader_uniform_light_amt; +// the ambient light of the current world +Color ambient; + // keeps a simple palette of colors for single-color draws GLuint colorIndex; @@ -365,6 +368,7 @@ void render() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // TODO add depth glEnable(GL_DEPTH_TEST); + //glEnable(GL_CULL_FACE); glUseProgram(textShader); glUniformMatrix4fv(textShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(ortho)); @@ -374,9 +378,15 @@ void render() { glUniformMatrix4fv(worldShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f))); glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0); - glUniform4f(worldShader_uniform_ambient, 1.0, 1.0, 1.0, 1.0); - glUniform1i(worldShader_uniform_light_amt, 0); + glUniform4f(worldShader_uniform_ambient, ambient.red, ambient.green, ambient.blue, 1.0); glUniform1f(worldShader_uniform_light_impact, 1.0); + + /*static GLfloat l[] = {460.0, 100.0, 0.0, 300.0}; + static GLfloat lc[] = {1.0, 1.0, 1.0, 1.0}; + glUniform4fv(worldShader_uniform_light, 1, l); + glUniform4fv(worldShader_uniform_light_color, 1, lc); + glUniform1i(worldShader_uniform_light_amt, 1); + */ /************************** **** RENDER STUFF HERE **** **************************/ @@ -462,44 +472,44 @@ void render() { if (currentMenu) ui::menu::draw(); - glUseProgram(textShader); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, mouseTex); - glUniform1i(textShader_uniform_texture, 0); + glUseProgram(textShader); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, mouseTex); + glUniform1i(textShader_uniform_texture, 0); - glEnableVertexAttribArray(textShader_attribute_tex); - glEnableVertexAttribArray(textShader_attribute_coord); + glEnableVertexAttribArray(textShader_attribute_tex); + glEnableVertexAttribArray(textShader_attribute_coord); - glDisable(GL_DEPTH_TEST); + glDisable(GL_DEPTH_TEST); - GLfloat mouseCoords[] = { - ui::mouse.x ,ui::mouse.y, 1.0, //bottom left - ui::mouse.x+15 ,ui::mouse.y, 1.0, //bottom right - ui::mouse.x+15 ,ui::mouse.y-15, 1.0, //top right + GLfloat mouseCoords[] = { + ui::mouse.x ,ui::mouse.y, -9.9, //bottom left + ui::mouse.x+15 ,ui::mouse.y, -9.9, //bottom right + ui::mouse.x+15 ,ui::mouse.y-15, -9.9, //top right - ui::mouse.x+15 ,ui::mouse.y-15, 1.0, //top right - ui::mouse.x ,ui::mouse.y-15, 1.0, //top left - ui::mouse.x ,ui::mouse.y, 1.0, //bottom left - }; + ui::mouse.x+15 ,ui::mouse.y-15, -9.9, //top right + ui::mouse.x ,ui::mouse.y-15, -9.9, //top left + ui::mouse.x ,ui::mouse.y, -9.9, //bottom left + }; - GLfloat mouseTex[] = { - 0.0f, 0.0f, //bottom left - 1.0f, 0.0f, //bottom right - 1.0f, 1.0f, //top right + GLfloat mouseTex[] = { + 0.0f, 0.0f, //bottom left + 1.0f, 0.0f, //bottom right + 1.0f, 1.0f, //top right - 1.0f, 1.0f, //top right - 0.0f, 1.0f, //top left - 0.0f, 0.0f, //bottom left - }; + 1.0f, 1.0f, //top right + 0.0f, 1.0f, //top left + 0.0f, 0.0f, //bottom left + }; - glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, mouseCoords); - glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, mouseTex); - glDrawArrays(GL_TRIANGLES, 0, 6); + glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, mouseCoords); + glVertexAttribPointer(textShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, mouseTex); + glDrawArrays(GL_TRIANGLES, 0, 6); - glDisableVertexAttribArray(textShader_attribute_coord); - glDisableVertexAttribArray(textShader_attribute_tex); + glDisableVertexAttribArray(textShader_attribute_coord); + glDisableVertexAttribArray(textShader_attribute_tex); - SDL_GL_SwapWindow(window); + SDL_GL_SwapWindow(window); } void logic(){ @@ -562,6 +572,13 @@ void logic(){ // calculate the world shading value worldShade = 50 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI)); + float ws = 75 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI)); + + float ambRG = std::clamp(.5f + (-ws / 100.0f), 0.01f, .9f); + float ambB = std::clamp(.5f + (-ws / 80.0f), 0.03f, .9f); + + ambient = Color(ambRG, ambRG, ambB, 1.0f); + // update fades ui::fadeUpdate(); diff --git a/shaders/world.frag b/shaders/world.frag index 3177795..bde5fa5 100644 --- a/shaders/world.frag +++ b/shaders/world.frag @@ -3,7 +3,7 @@ uniform sampler2D normalTex; varying vec2 texCoord; varying vec4 color; -varying vec3 fragCoord; +varying vec4 fragCoord; uniform vec4 ambientLight; uniform vec4 light[128]; @@ -11,26 +11,25 @@ uniform vec4 lightColor[128]; uniform float lightImpact; uniform int lightSize; -float b = .0005f; -float minLight = .05f; -float radius = sqrt(1.0f / (b * minLight)); - void main() { - vec4 pixTex = texture2D(texture, vec2(texCoord.x, 1-texCoord.y)); + vec2 texLoc = vec2(texCoord.x, 1-texCoord.y); + vec4 pixTex = texture2D(texture, texLoc); if (pixTex.a < 0.1f) discard; - + vec4 shadeColor = vec4(0.0f, 0.0f, 0.0f, 0.0f); - for (int i = 0; i < lightSize; i++) { - vec2 loc = light[i].xy; - float dist = length(loc - fragCoord.xy); - float attenuation = clamp(1.0f - dist*dist/(radius*radius), 0.0f, 1.0f); - attenuation *= attenuation; - - shadeColor += vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor[i]); + if (lightImpact > 0.0f) { + for (int i = 0; i < lightSize; i++) { + vec2 loc = light[i].xy; + float dist = length(loc - fragCoord.xy); + float attenuation = clamp(1.0f - dist*dist/(light[i].w*light[i].w), 0.0f, 1.0f); + attenuation *= attenuation; + + shadeColor += (vec4(attenuation, attenuation, attenuation, 0.0f) * vec4(lightColor[i])) * lightImpact; + } } - shadeColor += ambientLight; + shadeColor += ambientLight; gl_FragColor = pixTex * color * shadeColor; } diff --git a/shaders/world.vert b/shaders/world.vert index df814e6..0d5e65e 100644 --- a/shaders/world.vert +++ b/shaders/world.vert @@ -7,11 +7,11 @@ uniform mat4 transform; varying vec2 texCoord; varying vec4 color; -varying vec3 fragCoord; +varying vec4 fragCoord; void main(){ color = tex_color; texCoord = tex_coord; - gl_Position = ortho * transform * vec4(coord2d.xyz, 1.0); - fragCoord = vec3(gl_Position.xyz); + fragCoord = vec4(coord2d.xyz, 1.0); + gl_Position = ortho * transform * fragCoord; } diff --git a/src/inventory.cpp b/src/inventory.cpp index e235f51..ede5eeb 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -91,6 +91,11 @@ void items(void) ItemMap.push_back(new Food()); + // light + } else if (strCaseCmp(name, "light")) { + + ItemMap.push_back(new ItemLight()); + // if type was not specified make it a base item } else { @@ -98,7 +103,9 @@ void items(void) } // set how much of the item we can stack - ItemMap.back()->maxStackSize = exml->UnsignedAttribute("maxStackSize"); + if(exml->QueryUnsignedAttribute("maxStackSize", &ItemMap.back()->maxStackSize) != XML_NO_ERROR) { + ItemMap.back()->maxStackSize = 1; + } // set all of the texture frames we can use ItemMap.back()->tex = new Texturec(1, exml->Attribute("sprite")); diff --git a/src/items.cpp b/src/items.cpp index 6c65b59..eacf5a9 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -158,6 +158,11 @@ int Food::useItem() return 0; } +int ItemLight::useItem() +{ + std::cout << "fsdfsdf" << std::endl; + return 0; +} /************************************************** * CLONE * @@ -193,6 +198,10 @@ RawFood* RawFood::clone() return new RawFood(*this); } +ItemLight* ItemLight::clone() +{ + return new ItemLight(*this); +} /************************************************************************************ * ITEM SPECIFIC * ************************************************************************************/ diff --git a/src/mob.cpp b/src/mob.cpp index d6df3fd..a0e7087 100644 --- a/src/mob.cpp +++ b/src/mob.cpp @@ -143,9 +143,9 @@ void Cat::onHit(unsigned int _health) bool Cat::bindTex(void) { - glActiveTexture(GL_TEXTURE0); + glActiveTexture(GL_TEXTURE0); tex(0); - return true; + return true; } void Cat::createFromXML(const XMLElement *e) @@ -1397,19 +1397,19 @@ EXIT: heyOhLetsGo = 0; break; case SDLK_l: - currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); - //currentWorld->getLastLight()->follow(player); + currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y}, 300.0f, {1.0f,1.0f,1.0f}); + currentWorld->getLastLight()->follow(player); currentWorld->getLastLight()->makeFlame(); break; case SDLK_f: - currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); + currentWorld->addLight({player->loc.x, player->loc.y}, 300.0f, {1.0f,1.0f,1.0f}); break; case SDLK_b: if (debug) posFlag ^= true; else { 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->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y}, 400.0f, {1.0f,1.0f,1.0f}); //currentWorld->getLastLight()->follow(currentWorld->build.back()); currentWorld->getLastLight()->makeFlame(); } diff --git a/src/world.cpp b/src/world.cpp index 2ecccec..bb0487e 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -267,7 +267,25 @@ void World::drawBackgrounds(void) 0.0f, 0.0f, 0.0f, 1.0f,}; - vec2 bg_tex_coord[] = { vec2(0.0f, 0.0f), + // TODO scroll backdrop + GLfloat bgOff = game::time::getTickCount()/24000.0f; + + GLfloat topS = .125f + bgOff; + GLfloat bottomS = 0.0f + bgOff; + + if (topS < 0.0f) topS += 1.0f; + if (bottomS < 0.0f) bottomS += 1.0f; + if(bgOff < 0)std::cout << bottomS << "," << topS << std::endl; + + GLfloat scrolling_tex_coord[] = {0.0f, bottomS, + 1.0f, bottomS, + 1.0f, bottomS, + + 1.0f, bottomS, + 0.0f, bottomS, + 0.0f, bottomS}; + + vec2 bg_tex_coord[] = { vec2(0.0f, 0.0f), vec2(1.0f, 0.0f), vec2(1.0f, 1.0f), @@ -275,13 +293,13 @@ void World::drawBackgrounds(void) vec2(0.0f, 1.0f), vec2(0.0f, 0.0f)}; - GLfloat back_tex_coord[] = {offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f, - offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f, + GLfloat back_tex_coord[] = {offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f, offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 9.9f, + offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f, - offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 9.9f, - offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f, - offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f}; + offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.9f, + offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f, + offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f}; GLfloat fron_tex_coord[] = {offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.8f, offset.x + backgroundOffset.x + 5, offset.y + backgroundOffset.y, 9.8f, @@ -292,25 +310,32 @@ void World::drawBackgrounds(void) offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.8f}; glUseProgram(worldShader); + glUniform1f(worldShader_uniform_light_impact, 0.0f); + glUniform4f(worldShader_uniform_ambient, 1.0, 1.0, 1.0, 1.0); glEnableVertexAttribArray(worldShader_attribute_coord); glEnableVertexAttribArray(worldShader_attribute_tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + bgTex(0); glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0); - glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, back_tex_coord); - glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex_coord); + glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, back_tex_coord); + glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, scrolling_tex_coord); glDrawArrays(GL_TRIANGLES, 0 , 6); bgTex++; - glUniform4f(worldShader_uniform_color, .8, .8, .8, 1.3 - static_cast<float>(alpha)/255.0f); - glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, fron_tex_coord); + glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.3 - static_cast<float>(alpha)/255.0f); + + glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, fron_tex_coord); glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, tex_coord); glDrawArrays(GL_TRIANGLES, 0 , 6); - - static GLuint starTex = Texture::genColor(Color(255, 255, 255)); - const static float stardim = 2; + // TODO make stars dynamic + //static GLuint starTex = Texture::genColor(Color(255, 255, 255)); + static GLuint starTex = Texture::loadTexture("assets/style/classic/bg/star.png"); + const static float stardim = 24; GLfloat star_coord[star.size() * 5 * 6 + 1]; GLfloat *si = &star_coord[0]; @@ -321,72 +346,77 @@ void World::drawBackgrounds(void) for (auto &s : star) { *(si++) = s.x + xcoord; *(si++) = s.y, - *(si++) = 9.8; + *(si++) = 9.7f; *(si++) = 0.0; *(si++) = 0.0; *(si++) = s.x + xcoord + stardim; *(si++) = s.y, - *(si++) = 9.8; + *(si++) = 9.7f; *(si++) = 1.0; *(si++) = 0.0; *(si++) = s.x + xcoord + stardim; *(si++) = s.y + stardim, - *(si++) = 9.8; + *(si++) = 9.7f; *(si++) = 1.0; *(si++) = 1.0; *(si++) = s.x + xcoord + stardim; *(si++) = s.y + stardim, - *(si++) = 9.8; + *(si++) = 9.7f; *(si++) = 1.0; *(si++) = 1.0; *(si++) = s.x + xcoord; *(si++) = s.y + stardim, - *(si++) = 9.8; + *(si++) = 9.7f; *(si++) = 0.0; *(si++) = 1.0; *(si++) = s.x + xcoord; *(si++) = s.y, - *(si++) = 9.8; + *(si++) = 9.7f; *(si++) = 0.0; *(si++) = 0.0; } glBindTexture(GL_TEXTURE_2D, starTex); - glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, (255.0f - (randGet() % 200 - 100)) / 255.0f); - + //glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, (255.0f - (randGet() % 200 - 100)) / 255.0f); + glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.3 - static_cast<float>(alpha)/255.0f); + glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &star_coord[0]); glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &star_coord[3]); glDrawArrays(GL_TRIANGLES, 0, star.size() * 6); + } - glDisableVertexAttribArray(worldShader_attribute_coord); + + glDisableVertexAttribArray(worldShader_attribute_coord); glDisableVertexAttribArray(worldShader_attribute_tex); glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0); + glUniform4f(worldShader_uniform_ambient, ambient.red, ambient.green, ambient.blue, 1.0); glUseProgram(0); std::vector<vec3> bg_items; bgTex++; + dim2 mountainDim = bgTex.getTextureDim(); auto xcoord = width / 2 * -1 + offset.x * 0.85f; - for (unsigned int i = 0; i <= worldData.size() * HLINE / 1920; i++) { - bg_items.push_back(vec3(1920 * i + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f)); - bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f)); - bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 8.0f)); - - bg_items.push_back(vec3(1920 * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 8.0f)); - bg_items.push_back(vec3(1920 * i + xcoord, GROUND_HEIGHT_MINIMUM + 1080, 8.0f)); - bg_items.push_back(vec3(1920 * i + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f)); + for (unsigned int i = 0; i <= worldData.size() * HLINE / mountainDim.x; i++) { + bg_items.push_back(vec3(mountainDim.x * i + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f)); + bg_items.push_back(vec3(mountainDim.x * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f)); + bg_items.push_back(vec3(mountainDim.x * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + mountainDim.y, 8.0f)); + + bg_items.push_back(vec3(mountainDim.x * (i + 1) + xcoord, GROUND_HEIGHT_MINIMUM + mountainDim.y, 8.0f)); + bg_items.push_back(vec3(mountainDim.x * i + xcoord, GROUND_HEIGHT_MINIMUM + mountainDim.y, 8.0f)); + bg_items.push_back(vec3(mountainDim.x * i + xcoord, GROUND_HEIGHT_MINIMUM, 8.0f)); } std::vector<GLfloat> bg_i; @@ -406,6 +436,7 @@ void World::drawBackgrounds(void) } glUseProgram(worldShader); + glUniform1f(worldShader_uniform_light_impact, 0.01); glEnableVertexAttribArray(worldShader_attribute_coord); glEnableVertexAttribArray(worldShader_attribute_tex); @@ -423,15 +454,16 @@ void World::drawBackgrounds(void) for (unsigned int i = 0; i < 4; i++) { std::vector<vec3>c; bgTex++; - auto xcoord = offset.x * bgDraw[i][2]; - for (int j = worldStart; j <= -worldStart; j += 600) { - c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1))); - c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1))); - c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM + 400, 7-(i*.1))); - - c.push_back(vec3(j + 600 + xcoord, GROUND_HEIGHT_MINIMUM + 400, 7-(i*.1))); - c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM + 400, 7-(i*.1))); - c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1))); + dim2 dim = bgTex.getTextureDim(); + auto xcoord = offset.x * bgDraw[i][2]; + for (int j = worldStart; j <= -worldStart; j += dim.x) { + c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1))); + c.push_back(vec3(j + dim.x + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1))); + c.push_back(vec3(j + dim.x + xcoord, GROUND_HEIGHT_MINIMUM + dim.y, 7-(i*.1))); + + c.push_back(vec3(j + dim.x + xcoord, GROUND_HEIGHT_MINIMUM + dim.y, 7-(i*.1))); + c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM + dim.y, 7-(i*.1))); + c.push_back(vec3(j + xcoord, GROUND_HEIGHT_MINIMUM, 7-(i*.1))); } bg_i.clear(); @@ -451,6 +483,7 @@ void World::drawBackgrounds(void) } glUseProgram(worldShader); + glUniform1f(worldShader_uniform_light_impact, 0.075f + (0.2f*i)); glEnableVertexAttribArray(worldShader_attribute_coord); glEnableVertexAttribArray(worldShader_attribute_tex); @@ -475,10 +508,18 @@ void World::draw(Player *p) drawBackgrounds(); - - for (auto &l : light) { - if (l.belongsTo) { - l.loc.x = l.following->loc.x + SCREEN_WIDTH / 2; + uint ls = light.size(); + + GLfloat *lightCoords = new GLfloat[light.size() * 4]; + GLfloat *lightColors = new GLfloat[light.size() * 4]; + + uint lpIndex = 0; + uint lcIndex = 0; + + for (uint i = 0; i < ls; i++) { + auto &l = light[i]; + if (l.belongsTo) { + l.loc.x = l.following->loc.x; l.loc.y = l.following->loc.y; } if (l.flame) { @@ -488,7 +529,25 @@ void World::draw(Player *p) } else { l.fireFlicker = 1; } - } + + lightCoords[lpIndex++] = l.loc.x; + lightCoords[lpIndex++] = l.loc.y; + lightCoords[lpIndex++] = 0.0; + lightCoords[lpIndex++] = l.radius; + + lightColors[lcIndex++] = l.color.red; + lightColors[lcIndex++] = l.color.green; + lightColors[lcIndex++] = l.color.blue; + lightColors[lcIndex++] = 1.0; + } + + glUseProgram(worldShader); + + glUniform4fv(worldShader_uniform_light, ls, lightCoords); + glUniform4fv(worldShader_uniform_light_color, ls, lightColors); + glUniform1i(worldShader_uniform_light_amt, ls); + + glUseProgram(0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); @@ -545,6 +604,7 @@ void World::draw(Player *p) } glUseProgram(worldShader); + glUniform1f(worldShader_uniform_light_impact, 0.45f); glEnableVertexAttribArray(worldShader_attribute_coord); glEnableVertexAttribArray(worldShader_attribute_tex); @@ -629,6 +689,7 @@ void World::draw(Player *p) } glUseProgram(worldShader); + glUniform1f(worldShader_uniform_light_impact, 1.0f); glEnableVertexAttribArray(worldShader_attribute_coord); glEnableVertexAttribArray(worldShader_attribute_tex); @@ -1506,10 +1567,10 @@ addParticle(float x, float y, float w, float h, float vx, float vy, Color color, } void World:: -addLight(vec2 loc, Color color) +addLight(vec2 loc, float radius, Color color) { if (light.size() < 64) - light.emplace_back(loc, color, 1); + light.emplace_back(loc, radius, color); } void World:: diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index 7be0e08..2aec9ef 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -86,5 +86,6 @@ And it wasn't stormy. <give id="Hunters Bow" count="1"/> <give id="Crude Arrow" count="110"/> <give id="Fried Chicken" count="1"/> + <give id="Mossy Torch" count="1"/> </text> </Dialog> |