/*
Copyright (C) 2003, 2010 - Wolfire Games
-Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
+Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
This file is part of Lugaru.
along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "Game.h"
-#include "Graphic/Sprite.h"
-#include "Objects/Person.h"
+#include "Graphic/Sprite.hpp"
+
+#include "Game.hpp"
+#include "Objects/Person.hpp"
extern XYZ viewer;
extern float viewdistance;
extern float multiplier;
extern float gravity;
extern Terrain terrain;
-extern Objects objects;
extern int detail;
extern XYZ viewerfacing;
extern int bloodtoggle;
for (unsigned i = 0; i < sprites.size(); i++) {
if (lasttype != sprites[i]->type) {
switch (sprites[i]->type) {
- case cloudsprite:
- cloudtexture.bind();
- if (!blend) {
- blend = 1;
- glAlphaFunc(GL_GREATER, 0.0001);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- break;
- case breathsprite:
- case cloudimpactsprite:
- cloudimpacttexture.bind();
- if (!blend) {
- blend = 1;
- glAlphaFunc(GL_GREATER, 0.0001);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- break;
- case smoketype:
- smoketexture.bind();
- if (!blend) {
- blend = 1;
- glAlphaFunc(GL_GREATER, 0.0001);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- break;
- case bloodsprite:
- bloodtexture.bind();
- if (!blend) {
- blend = 1;
- glAlphaFunc(GL_GREATER, 0.0001);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- break;
- case splintersprite :
- if (lastspecial != sprites[i]->special) {
- if (sprites[i]->special == 0)
- splintertexture.bind();
- if (sprites[i]->special == 1)
- leaftexture.bind();
- if (sprites[i]->special == 2)
- snowflaketexture.bind();
- if (sprites[i]->special == 3)
- toothtexture.bind();
+ case cloudsprite:
+ cloudtexture.bind();
if (!blend) {
blend = 1;
glAlphaFunc(GL_GREATER, 0.0001);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
- }
- break;
- case snowsprite:
- snowflaketexture.bind();
- if (!blend) {
- blend = 1;
- glAlphaFunc(GL_GREATER, 0.0001);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- break;
- case weaponshinesprite:
- shinetexture.bind();
- if (blend) {
- blend = 0;
- glAlphaFunc(GL_GREATER, 0.001);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- }
- break;
- case flamesprite:
- case weaponflamesprite:
- flametexture.bind();
- if (blend || lasttype == bloodflamesprite) {
- blend = 0;
- glAlphaFunc(GL_GREATER, 0.3);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- }
- break;
- case bloodflamesprite:
- bloodflametexture.bind();
- if (blend) {
- blend = 0;
- glAlphaFunc(GL_GREATER, 0.3);
- glBlendFunc(GL_ONE, GL_ZERO);
- }
- break;
+ break;
+ case breathsprite:
+ case cloudimpactsprite:
+ cloudimpacttexture.bind();
+ if (!blend) {
+ blend = 1;
+ glAlphaFunc(GL_GREATER, 0.0001);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ break;
+ case smoketype:
+ smoketexture.bind();
+ if (!blend) {
+ blend = 1;
+ glAlphaFunc(GL_GREATER, 0.0001);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ break;
+ case bloodsprite:
+ bloodtexture.bind();
+ if (!blend) {
+ blend = 1;
+ glAlphaFunc(GL_GREATER, 0.0001);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ break;
+ case splintersprite:
+ if (lastspecial != sprites[i]->special) {
+ if (sprites[i]->special == 0) {
+ splintertexture.bind();
+ }
+ if (sprites[i]->special == 1) {
+ leaftexture.bind();
+ }
+ if (sprites[i]->special == 2) {
+ snowflaketexture.bind();
+ }
+ if (sprites[i]->special == 3) {
+ toothtexture.bind();
+ }
+ if (!blend) {
+ blend = 1;
+ glAlphaFunc(GL_GREATER, 0.0001);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ }
+ break;
+ case snowsprite:
+ snowflaketexture.bind();
+ if (!blend) {
+ blend = 1;
+ glAlphaFunc(GL_GREATER, 0.0001);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ break;
+ case weaponshinesprite:
+ shinetexture.bind();
+ if (blend) {
+ blend = 0;
+ glAlphaFunc(GL_GREATER, 0.001);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ }
+ break;
+ case flamesprite:
+ case weaponflamesprite:
+ flametexture.bind();
+ if (blend || lasttype == bloodflamesprite) {
+ blend = 0;
+ glAlphaFunc(GL_GREATER, 0.3);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ }
+ break;
+ case bloodflamesprite:
+ bloodflametexture.bind();
+ if (blend) {
+ blend = 0;
+ glAlphaFunc(GL_GREATER, 0.3);
+ glBlendFunc(GL_ONE, GL_ZERO);
+ }
+ break;
}
}
- if (sprites[i]->type == snowsprite)
+ if (sprites[i]->type == snowsprite) {
distancemult = (144 - (distsq(&tempviewer, &sprites[i]->position) - (144 * fadestart)) * (1 / (1 - fadestart))) / 144;
- else
+ } else {
distancemult = (viewdistsquared - (distsq(&viewer, &sprites[i]->position) - (viewdistsquared * fadestart)) * (1 / (1 - fadestart))) / viewdistsquared;
+ }
if (sprites[i]->type == flamesprite) {
- if (distancemult >= 1)
+ if (distancemult >= 1) {
glColor4f(sprites[i]->color[0], sprites[i]->color[1], sprites[i]->color[2], sprites[i]->opacity);
- else
+ } else {
glColor4f(sprites[i]->color[0], sprites[i]->color[1], sprites[i]->color[2], sprites[i]->opacity * distancemult);
+ }
} else {
- if (distancemult >= 1)
- glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->opacity);
- else
- glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->opacity * distancemult);
+ if (distancemult >= 1) {
+ glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity);
+ } else {
+ glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity * distancemult);
+ }
}
lasttype = sprites[i]->type;
lastspecial = sprites[i]->special;
glRotatef(sprites[i]->rotation, 0, 0, 1);
if ((sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite)) {
- if (sprites[i]->alivetime < .14)
+ if (sprites[i]->alivetime < .14) {
glScalef(sprites[i]->alivetime / .14, sprites[i]->alivetime / .14, sprites[i]->alivetime / .14);
+ }
}
if (sprites[i]->type == smoketype || sprites[i]->type == snowsprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == breathsprite) {
if (sprites[i]->alivetime < .3) {
- if (distancemult >= 1)
- glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->opacity * sprites[i]->alivetime / .3);
- if (distancemult < 1)
- glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->opacity * distancemult * sprites[i]->alivetime / .3);
+ if (distancemult >= 1) {
+ glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity * sprites[i]->alivetime / .3);
+ }
+ if (distancemult < 1) {
+ glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->opacity * distancemult * sprites[i]->alivetime / .3);
+ }
}
}
if (sprites[i]->type == splintersprite && sprites[i]->special > 0 && sprites[i]->special != 3) {
if (sprites[i]->alivetime < .2) {
- if (distancemult >= 1)
- glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], sprites[i]->alivetime / .2);
- else
- glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], distancemult * sprites[i]->alivetime / .2);
+ if (distancemult >= 1) {
+ glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], sprites[i]->alivetime / .2);
+ } else {
+ glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], distancemult * sprites[i]->alivetime / .2);
+ }
} else {
- if (distancemult >= 1)
- glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1);
- else
- glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1);
+ if (distancemult >= 1) {
+ glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], 1);
+ } else {
+ glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], distancemult);
+ }
}
}
if (sprites[i]->type == splintersprite && (sprites[i]->special == 0 || sprites[i]->special == 3)) {
- if (distancemult >= 1)
- glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1);
- else
- glColor4f(sprites[i]->color[0]*lightcolor[0], sprites[i]->color[1]*lightcolor[1], sprites[i]->color[2]*lightcolor[2], 1);
+ if (distancemult >= 1) {
+ glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], 1);
+ } else {
+ glColor4f(sprites[i]->color[0] * lightcolor[0], sprites[i]->color[1] * lightcolor[1], sprites[i]->color[2] * lightcolor[2], distancemult);
+ }
}
glBegin(GL_TRIANGLES);
glTexCoord2f(1.0f, 1.0f);
- glVertex3f( .5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f);
+ glVertex3f(.5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-.5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f);
glTexCoord2f(1.0f, 0.0f);
- glVertex3f( .5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f);
+ glVertex3f(.5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-.5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f);
glTexCoord2f(1.0f, 0.0f);
- glVertex3f( .5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f);
+ glVertex3f(.5 * sprites[i]->size, -.5 * sprites[i]->size, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-.5 * sprites[i]->size, .5 * sprites[i]->size, 0.0f);
glEnd();
sprites[i]->position += sprites[i]->velocity * multiplier;
sprites[i]->velocity += windvector * multiplier;
}
- if (sprites[i]->type == flamesprite || sprites[i]->type == smoketype)
+ if (sprites[i]->type == flamesprite || sprites[i]->type == smoketype) {
sprites[i]->position += windvector * multiplier / 2;
- if ((sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite))
+ }
+ if ((sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite)) {
multiplier *= sprites[i]->speed * .7;
+ }
sprites[i]->alivetime += multiplier;
if (sprites[i]->type == cloudsprite || sprites[i]->type == cloudimpactsprite) {
sprites[i]->rotation += multiplier * 360;
sprites[i]->position.y -= multiplier;
sprites[i]->position += windvector * multiplier;
- if (sprites[i]->position.y < tempviewer.y - 6) sprites[i]->position.y += 12;
- if (sprites[i]->position.y > tempviewer.y + 6) sprites[i]->position.y -= 12;
- if (sprites[i]->position.z < tempviewer.z - 6) sprites[i]->position.z += 12;
- if (sprites[i]->position.z > tempviewer.z + 6) sprites[i]->position.z -= 12;
- if (sprites[i]->position.x < tempviewer.x - 6) sprites[i]->position.x += 12;
- if (sprites[i]->position.x > tempviewer.x + 6) sprites[i]->position.x -= 12;
+ if (sprites[i]->position.y < tempviewer.y - 6) {
+ sprites[i]->position.y += 12;
+ }
+ if (sprites[i]->position.y > tempviewer.y + 6) {
+ sprites[i]->position.y -= 12;
+ }
+ if (sprites[i]->position.z < tempviewer.z - 6) {
+ sprites[i]->position.z += 12;
+ }
+ if (sprites[i]->position.z > tempviewer.z + 6) {
+ sprites[i]->position.z -= 12;
+ }
+ if (sprites[i]->position.x < tempviewer.x - 6) {
+ sprites[i]->position.x += 12;
+ }
+ if (sprites[i]->position.x > tempviewer.x + 6) {
+ sprites[i]->position.x -= 12;
+ }
}
if (sprites[i]->type == bloodsprite) {
bool spritehit = 0;
if (!spritehit && Person::players[j]->dead && sprites[i]->alivetime > .1) {
where = sprites[i]->oldposition;
where -= Person::players[j]->coords;
- if (!Person::players[j]->skeleton.free)
+ if (!Person::players[j]->skeleton.free) {
where = DoRotation(where, 0, -Person::players[j]->yaw, 0);
+ }
startpoint = where;
where = sprites[i]->position;
where -= Person::players[j]->coords;
- if (!Person::players[j]->skeleton.free)
+ if (!Person::players[j]->skeleton.free) {
where = DoRotation(where, 0, -Person::players[j]->yaw, 0);
+ }
endpoint = where;
movepoint = 0;
whichpatchx = sprites[i]->position.x / (terrain.size / subdivision * terrain.scale);
whichpatchz = sprites[i]->position.z / (terrain.size / subdivision * terrain.scale);
- if (whichpatchx > 0 && whichpatchz > 0 && whichpatchx < subdivision && whichpatchz < subdivision)
- if (terrain.patchobjectnum[whichpatchx][whichpatchz]) {
- if (!spritehit)
- for (int j = 0; j < terrain.patchobjectnum[whichpatchx][whichpatchz]; j++) {
- k = terrain.patchobjects[whichpatchx][whichpatchz][j];
- start = sprites[i]->oldposition;
- end = sprites[i]->position;
- if (!spritehit)
- if (objects.model[k].LineCheck(&start, &end, &colpoint, &objects.position[k], &objects.yaw[k]) != -1) {
- if (detail == 2 || (detail == 1 && abs(Random() % 4) == 0) || (detail == 0 && abs(Random() % 8) == 0))
- objects.model[k].MakeDecal(blooddecalfast, DoRotation(colpoint - objects.position[k], 0, -objects.yaw[k], 0), sprites[i]->size * 1.6, .5, Random() % 360);
- DeleteSprite(i);
- spritehit = 1;
+ if (whichpatchx > 0 && whichpatchz > 0 && whichpatchx < subdivision && whichpatchz < subdivision) {
+ if (!spritehit) {
+ for (unsigned int j = 0; j < terrain.patchobjects[whichpatchx][whichpatchz].size(); j++) {
+ k = terrain.patchobjects[whichpatchx][whichpatchz][j];
+ start = sprites[i]->oldposition;
+ end = sprites[i]->position;
+ if (!spritehit) {
+ if (Object::objects[k]->model.LineCheck(&start, &end, &colpoint, &Object::objects[k]->position, &Object::objects[k]->yaw) != -1) {
+ if (detail == 2 || (detail == 1 && abs(Random() % 4) == 0) || (detail == 0 && abs(Random() % 8) == 0)) {
+ Object::objects[k]->model.MakeDecal(blooddecalfast, DoRotation(colpoint - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), sprites[i]->size * 1.6, .5, Random() % 360);
}
+ DeleteSprite(i);
+ spritehit = 1;
+ }
}
+ }
}
- if (!spritehit)
+ }
+ if (!spritehit) {
if (sprites[i]->position.y < terrain.getHeight(sprites[i]->position.x, sprites[i]->position.z)) {
terrain.MakeDecal(blooddecalfast, sprites[i]->position, sprites[i]->size * 1.6, .6, Random() % 360);
DeleteSprite(i);
}
+ }
}
}
if (sprites[i]->type == splintersprite) {
sprites[i]->rotation += sprites[i]->rotatespeed * multiplier;
sprites[i]->opacity -= multiplier / 2;
- if (sprites[i]->special == 0 || sprites[i]->special == 2 || sprites[i]->special == 3)
+ if (sprites[i]->special == 0 || sprites[i]->special == 2 || sprites[i]->special == 3) {
sprites[i]->velocity.y += gravity * multiplier;
- if (sprites[i]->special == 1)
+ }
+ if (sprites[i]->special == 1) {
sprites[i]->velocity.y += gravity * multiplier * .5;
+ }
}
if (sprites[i]->type == flamesprite || sprites[i]->type == weaponflamesprite || sprites[i]->type == weaponshinesprite || sprites[i]->type == bloodflamesprite) {
sprites[i]->rotation += multiplier * sprites[i]->rotatespeed;
sprites[i]->opacity -= multiplier * 5 / 4;
- if (sprites[i]->type != weaponshinesprite && sprites[i]->type != bloodflamesprite)
- if (sprites[i]->opacity < .5 && sprites[i]->opacity + multiplier * 5 / 4 >= .5 && (abs(Random() % 4) == 0 || (sprites[i]->initialsize > 2 && Random() % 2 == 0)))
+ if (sprites[i]->type != weaponshinesprite && sprites[i]->type != bloodflamesprite) {
+ if (sprites[i]->opacity < .5 && sprites[i]->opacity + multiplier * 5 / 4 >= .5 && (abs(Random() % 4) == 0 || (sprites[i]->initialsize > 2 && Random() % 2 == 0))) {
MakeSprite(smoketype, sprites[i]->position, sprites[i]->velocity, .9, .9, .6, sprites[i]->size * 1.2, .4);
+ }
+ }
if (sprites[i]->alivetime > .14 && (sprites[i]->type == flamesprite)) {
sprites[i]->velocity = 0;
sprites[i]->velocity.y = 1.5;
sprites[i]->color[0] -= multiplier;
sprites[i]->color[1] -= multiplier;
sprites[i]->color[2] -= multiplier;
- if (sprites[i]->color[0] < .6)
+ if (sprites[i]->color[0] < .6) {
sprites[i]->color[0] = .6;
- if (sprites[i]->color[1] < .6)
+ }
+ if (sprites[i]->color[1] < .6) {
sprites[i]->color[1] = .6;
- if (sprites[i]->color[2] < .6)
+ }
+ if (sprites[i]->color[2] < .6) {
sprites[i]->color[2] = .6;
+ }
sprites[i]->size += multiplier;
sprites[i]->velocity = 0;
sprites[i]->velocity.y = 1.5;
sprites[i]->rotation += multiplier * sprites[i]->rotatespeed / 5;
}
- if (sprites[i]->opacity <= 0 || sprites[i]->size <= 0)
+ if (sprites[i]->opacity <= 0 || sprites[i]->size <= 0) {
DeleteSprite(i);
+ }
}
- if (check)
+ if (check) {
for (int i = sprites.size() - 1; i >= 0; i--) {
sprites[i]->oldposition = sprites[i]->position;
}
+ }
glAlphaFunc(GL_GREATER, 0.0001);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
speed = 0;
rotatespeed = 0;
}
-
-void Sprite::clearTextures()
-{
- toothtexture.destroy();
- cloudtexture.destroy();
- cloudimpacttexture.destroy();
- bloodtexture.destroy();
- flametexture.destroy();
- bloodflametexture.destroy();
- smoketexture.destroy();
- snowflaketexture.destroy();
- shinetexture.destroy();
- splintertexture.destroy();
- leaftexture.destroy();
-}
-