aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/entities.hpp1
-rw-r--r--src/entities.cpp11
-rw-r--r--src/inventory.cpp12
-rw-r--r--src/ui.cpp8
-rw-r--r--src/world.cpp78
5 files changed, 67 insertions, 43 deletions
diff --git a/include/entities.hpp b/include/entities.hpp
index 93c1caa..82f80c7 100644
--- a/include/entities.hpp
+++ b/include/entities.hpp
@@ -109,6 +109,7 @@ class Particles{
public:
// the location of the particle
vec2 loc;
+ float zOffset;
// the width of the particle, in pixels
float width;
diff --git a/src/entities.cpp b/src/entities.cpp
index b9acc20..8299e2c 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -915,15 +915,18 @@ Particles::Particles(float x, float y, float w, float h, float vx, float vy, Col
behind = false;
bounce = false;
index = Texture::getIndex(c);
+ zOffset = ((rand()%20)-10)/1000.0f;
}
void Particles::draw(GLfloat*& p) const
{
- vec2 tc = vec2 {0.25f * index.x, 0.125f * (8-index.y)};
+ vec2 tc = vec2(0.25f * this->index.x, 0.125f * (8.0f - this->index.y));
- float z = 0.0;
- if (behind)
- z = 2.0;
+ float z = 0.9;
+ if (behind)
+ z = 2.0;
+
+ z += zOffset;
// lower left
*(p++) = loc.x;
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 9727dc0..a7c19da 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -665,13 +665,13 @@ void itemDraw(Player *p, Item *d) {
itemTex[10] = 1.0;
}
- GLfloat itemCoords[] = {itemLoc.x, itemLoc.y, 1.0,
- itemLoc.x+d->dim.x, itemLoc.y, 1.0,
- itemLoc.x+d->dim.x, itemLoc.y+d->dim.y, 1.0,
+ GLfloat itemCoords[] = {itemLoc.x, itemLoc.y, p->z,
+ itemLoc.x+d->dim.x, itemLoc.y, p->z,
+ itemLoc.x+d->dim.x, itemLoc.y+d->dim.y, p->z,
- itemLoc.x+d->dim.x, itemLoc.y+d->dim.y, 1.0,
- itemLoc.x, itemLoc.y+d->dim.y, 1.0,
- itemLoc.x, itemLoc.y, 1.0};
+ itemLoc.x+d->dim.x, itemLoc.y+d->dim.y, p->z,
+ itemLoc.x, itemLoc.y+d->dim.y, p->z,
+ itemLoc.x, itemLoc.y, p->z};
glBindTexture(GL_TEXTURE_2D,d->tex->image[0]);
diff --git a/src/ui.cpp b/src/ui.cpp
index a687a35..6eca97d 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -1468,10 +1468,10 @@ EXIT:
0.0, 1.0,
1.0, 1.0};
- GLfloat backdrop[] = {offset.x - SCREEN_WIDTH / 2 - 1, offset.y - SCREEN_HEIGHT / 2, -8.1,
- offset.x + SCREEN_WIDTH / 2, offset.y - SCREEN_HEIGHT / 2, -8.1,
- offset.x - SCREEN_WIDTH / 2 - 1, offset.y + SCREEN_HEIGHT / 2, -8.1,
- offset.x + SCREEN_WIDTH / 2, offset.y + SCREEN_HEIGHT / 2, -8.1};
+ GLfloat backdrop[] = {offset.x - SCREEN_WIDTH / 2 - 1, offset.y - SCREEN_HEIGHT / 2, -7.9,
+ offset.x + SCREEN_WIDTH / 2, offset.y - SCREEN_HEIGHT / 2, -7.9,
+ offset.x - SCREEN_WIDTH / 2 - 1, offset.y + SCREEN_HEIGHT / 2, -7.9,
+ offset.x + SCREEN_WIDTH / 2, offset.y + SCREEN_HEIGHT / 2, -7.9};
setFontZ(-8.2);
glUniform1i(textShader_uniform_texture, 0);
diff --git a/src/world.cpp b/src/world.cpp
index f6df7d6..efafa55 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -283,7 +283,15 @@ void World::drawBackgrounds(void)
offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.9f,
offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.9f};
- glUseProgram(worldShader);
+ 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,
+ offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 9.8f,
+
+ offset.x + backgroundOffset.x + 5, offset.y - backgroundOffset.y, 9.8f,
+ offset.x - backgroundOffset.x - 5, offset.y - backgroundOffset.y, 9.8f,
+ offset.x - backgroundOffset.x - 5, offset.y + backgroundOffset.y, 9.8f};
+
+ glUseProgram(worldShader);
glEnableVertexAttribArray(worldShader_attribute_coord);
glEnableVertexAttribArray(worldShader_attribute_tex);
@@ -296,7 +304,7 @@ void World::drawBackgrounds(void)
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, back_tex_coord);
+ 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);
@@ -467,32 +475,6 @@ void World::draw(Player *p)
drawBackgrounds();
- // draw particles and buildings
- glBindTexture(GL_TEXTURE_2D, colorIndex);
- glUniform1i(worldShader_uniform_texture, 0);
- glUseProgram(worldShader);
-
- glEnableVertexAttribArray(worldShader_attribute_coord);
- glEnableVertexAttribArray(worldShader_attribute_tex);
-
- uint ps = particles.size();
-
- GLfloat partVec[ps * 6 * 5 + 1];
- GLfloat *pIndex = &partVec[0];
-
- for (auto &p : particles) {
- if (!p.behind)
- p.draw(pIndex);
- }
-
- glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[0]);
- glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[3]);
- glDrawArrays(GL_TRIANGLES, 0, ps * 6);
-
- glDisableVertexAttribArray(worldShader_attribute_tex);
- glDisableVertexAttribArray(worldShader_attribute_coord);
-
- glUseProgram(0);
for (auto &l : light) {
if (l.belongsTo) {
@@ -716,6 +698,44 @@ void World::draw(Player *p)
// draw the player
p->draw();
+
+ // draw particles like a MASTAH
+ glBindTexture(GL_TEXTURE_2D, colorIndex);
+ glUniform1i(worldShader_uniform_texture, 0);
+ glUseProgram(worldShader);
+
+ glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, .8);
+
+ glEnableVertexAttribArray(worldShader_attribute_coord);
+ glEnableVertexAttribArray(worldShader_attribute_tex);
+
+ uint ps = particles.size();
+ uint pss = ps * 6 * 5;
+ uint pc = 0;
+
+ std::vector<GLfloat> partVec(pss);
+ GLfloat *pIndex = &partVec[0];
+
+ for (uint p = 0; p < ps; p++) {
+ pc += 30;
+ if (pc > pss) {
+ // TODO resize the vector or something better than breaking
+ std::cout << "Whoops:" << pc << "," << partVec.size() << std::endl;
+ break;
+ }
+ particles[p].draw(pIndex);
+ }
+
+ glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[0]);
+ glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[3]);
+ glDrawArrays(GL_TRIANGLES, 0, ps * 6);
+
+ glDisableVertexAttribArray(worldShader_attribute_tex);
+ glDisableVertexAttribArray(worldShader_attribute_coord);
+
+ glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
+
+ glUseProgram(0);
}
/**
@@ -863,7 +883,7 @@ detect(Player *p)
HLINES(1.25), // width
HLINES(1.25), // height
randGet() % 7 * .01 * (randGet() % 2 == 0 ? -1 : 1), // vel.x
- (4 + randGet() % 6) * .05, // vel.y
+ randGet() % 1 ? (8 + randGet() % 6) * .05 : (4 + randGet() % 6) * .05, // vel.y
{ 0, 0, 255 }, // RGB color
2500 // duration (ms)
);