summaryrefslogtreecommitdiff
path: root/src/elements
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2012-06-20 20:45:33 (GMT)
committer jacksonmj <mj-pt@jacksonmj.co.uk>2012-06-20 21:15:45 (GMT)
commit1d5b08194291db72c05e68eed592e8fcb6101c63 (patch)
tree39945df4b183ef2bbcaf0cc1432a3a02b547f5f6 /src/elements
parent9b2c2a78a6f4ba4fb13f04f17a649caeaf416d8d (diff)
downloadpowder-1d5b08194291db72c05e68eed592e8fcb6101c63.zip
powder-1d5b08194291db72c05e68eed592e8fcb6101c63.tar.gz
Replace all explosion sparks with new element (EMBR)
Replaces: BOMB sparks and flash, electrons + glass sparks, sparks from IGNC, sparks from TNT explosion, and sparks from FWRK and FIRW.
Diffstat (limited to 'src/elements')
-rw-r--r--src/elements/bang.c4
-rw-r--r--src/elements/bomb.c108
-rw-r--r--src/elements/elec.c18
-rw-r--r--src/elements/embr.c94
-rw-r--r--src/elements/firw.c65
-rw-r--r--src/elements/fwrk.c50
-rw-r--r--src/elements/ignt.c4
-rw-r--r--src/elements/newgraphics.c51
8 files changed, 200 insertions, 194 deletions
diff --git a/src/elements/bang.c b/src/elements/bang.c
index d827f33..1a2a1ec 100644
--- a/src/elements/bang.c
+++ b/src/elements/bang.c
@@ -73,8 +73,8 @@ int update_BANG(UPDATE_FUNC_ARGS) {
{
if(!(rand()%15))
{
- create_part(i, x, y, PT_BOMB);
- parts[i].tmp = 1;
+ create_part(i, x, y, PT_EMBR);
+ parts[i].tmp = 0;
parts[i].life = 50;
parts[i].temp = restrict_flt((MAX_TEMP/3)+otemp, MIN_TEMP, MAX_TEMP);
parts[i].vx = rand()%20-10;
diff --git a/src/elements/bomb.c b/src/elements/bomb.c
index e8544c9..f60c86b 100644
--- a/src/elements/bomb.c
+++ b/src/elements/bomb.c
@@ -17,84 +17,52 @@
int update_BOMB(UPDATE_FUNC_ARGS) {
int r, rx, ry, nb;
- //Spark is used so much now that it should be a seperate element.
- if (parts[i].tmp==1) {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ for (rx=-2; rx<3; rx++)
+ for (ry=-2; ry<3; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if (!r)
+ continue;
+ if ((r&0xFF)!=PT_BOMB && (r&0xFF)!=PT_EMBR && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_BCLN)
{
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (ptypes[r&0xFF].properties & (TYPE_SOLID | TYPE_PART | TYPE_LIQUID) && !(ptypes[r&0xFF].properties & PROP_SPARKSETTLE)) {
- kill_part(i);
- return 1;
- }
- }
- } else if (parts[i].tmp==0) {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_BOMB && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_BCLN) {
- int rad = 8;
- int nxi;
- int nxj;
- pmap[y][x] = 0;
- for (nxj=-rad; nxj<=rad; nxj++)
- for (nxi=-rad; nxi<=rad; nxi++)
- if ((pow(nxi,2))/(pow(rad,2))+(pow(nxj,2))/(pow(rad,2))<=1)
- if ((pmap[y+nxj][x+nxi]&0xFF)!=PT_DMND && (pmap[y+nxj][x+nxi]&0xFF)!=PT_CLNE && (pmap[y+nxj][x+nxi]&0xFF)!=PT_PCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_BCLN) {
- delete_part(x+nxi, y+nxj, 0);//it SHOULD kill anything but the exceptions above, doesn't seem to always work
- pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f;
- nb = create_part(-1, x+nxi, y+nxj, PT_BOMB);
- if (nb!=-1) {
- parts[nb].tmp = 2;
- parts[nb].life = 2;
- parts[nb].temp = MAX_TEMP;
- }
- }
- for (nxj=-(rad+1); nxj<=(rad+1); nxj++)
- for (nxi=-(rad+1); nxi<=(rad+1); nxi++)
- if ((pow(nxi,2))/(pow((rad+1),2))+(pow(nxj,2))/(pow((rad+1),2))<=1) {
- nb = create_part(-1, x+nxi, y+nxj, PT_BOMB);
+ int rad = 8;
+ int nxi;
+ int nxj;
+ pmap[y][x] = 0;
+ for (nxj=-rad; nxj<=rad; nxj++)
+ for (nxi=-rad; nxi<=rad; nxi++)
+ if ((pow(nxi,2))/(pow(rad,2))+(pow(nxj,2))/(pow(rad,2))<=1)
+ if ((pmap[y+nxj][x+nxi]&0xFF)!=PT_DMND && (pmap[y+nxj][x+nxi]&0xFF)!=PT_CLNE && (pmap[y+nxj][x+nxi]&0xFF)!=PT_PCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_BCLN) {
+ delete_part(x+nxi, y+nxj, 0);
+ pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f;
+ nb = create_part(-3, x+nxi, y+nxj, PT_EMBR);
if (nb!=-1) {
- parts[nb].tmp = 1;
- parts[nb].life = 50;
+ parts[nb].tmp = 2;
+ parts[nb].life = 2;
parts[nb].temp = MAX_TEMP;
- parts[nb].vx = rand()%20-10;
- parts[nb].vy = rand()%20-10;
}
}
- //create_parts(x, y, 9, 9, PT_BOMB);
- //create_parts(x, y, 8, 8, PT_NONE);
- kill_part(i);
- return 1;
- }
+ for (nxj=-(rad+1); nxj<=(rad+1); nxj++)
+ for (nxi=-(rad+1); nxi<=(rad+1); nxi++)
+ if ((pow(nxi,2))/(pow((rad+1),2))+(pow(nxj,2))/(pow((rad+1),2))<=1 && !(pmap[y+nxj][x+nxi]&0xFF)) {
+ nb = create_part(-3, x+nxi, y+nxj, PT_EMBR);
+ if (nb!=-1) {
+ parts[nb].tmp = 0;
+ parts[nb].life = 50;
+ parts[nb].temp = MAX_TEMP;
+ parts[nb].vx = rand()%40-20;
+ parts[nb].vy = rand()%40-20;
+ }
+ }
+ kill_part(i);
+ return 1;
}
- }
+ }
return 0;
}
int graphics_BOMB(GRAPHICS_FUNC_ARGS)
{
- if (cpart->tmp==0) {
- //Normal bomb
- *pixel_mode |= PMODE_FLARE;
- }
- else if(cpart->tmp==2)
- {
- //Flash
- *pixel_mode = PMODE_FLAT | FIRE_ADD;
- *colr = *colg = *colb = *firer = *fireg = *fireb = *firea = 255;
- }
- else
- {
- //Flying spark
- *pixel_mode = PMODE_SPARK | PMODE_ADD;
- *cola = 4*cpart->life;
- }
- return 0;
+ *pixel_mode |= PMODE_FLARE;
+ return 1;
}
diff --git a/src/elements/elec.c b/src/elements/elec.c
index 3d8471d..bafe939 100644
--- a/src/elements/elec.c
+++ b/src/elements/elec.c
@@ -34,25 +34,31 @@ int update_ELEC(UPDATE_FUNC_ARGS) {
continue;
if ((r&0xFF)==PT_GLAS)
{
- fire_r[y/CELL][x/CELL] += rand()%200; //D: Doesn't work with OpenGL, also shouldn't be here
- fire_g[y/CELL][x/CELL] += rand()%200;
- fire_b[y/CELL][x/CELL] += rand()%200;
for (rrx=-1; rrx<=1; rrx++)
{
for (rry=-1; rry<=1; rry++)
{
if (x+rx+rrx>=0 && y+ry+rry>=0 && x+rx+rrx<XRES && y+ry+rry<YRES) {
- nb = create_part(-1, x+rx+rrx, y+ry+rry, PT_BOMB);
+ nb = create_part(-1, x+rx+rrx, y+ry+rry, PT_EMBR);
if (nb!=-1) {
- parts[nb].tmp = 1;
+ parts[nb].tmp = 0;
parts[nb].life = 50;
- parts[nb].temp = 400.0f;
+ parts[nb].temp = parts[i].temp*0.8f;
parts[nb].vx = rand()%20-10;
parts[nb].vy = rand()%20-10;
}
}
}
}
+ fire_r[y/CELL][x/CELL] += rand()%200; //D: Doesn't work with OpenGL, also shouldn't be here
+ fire_g[y/CELL][x/CELL] += rand()%200;
+ fire_b[y/CELL][x/CELL] += rand()%200;
+ /* possible alternative, but doesn't work well at the moment because FIRE_ADD divides firea by 8, so the glow isn't strong enough
+ create_part(i, x, y, PT_EMBR);
+ parts[i].tmp = 2;
+ parts[i].life = 2;
+ parts[i].ctype = ((rand()%200)<<16) | ((rand()%200)<<8) | (rand()%200);
+ */
kill_part(i);
return 1;
}
diff --git a/src/elements/embr.c b/src/elements/embr.c
new file mode 100644
index 0000000..16c4e70
--- /dev/null
+++ b/src/elements/embr.c
@@ -0,0 +1,94 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <element.h>
+
+/* ctype - colour RRGGBB (optional)
+ * life - decremented each frame, disappears when life reaches zero
+ * tmp - mode
+ * 0 - BOMB sparks
+ * 1 - firework sparks (colour defaults to white)
+ * 2 - flash (colour defaults to white)
+ */
+int update_EMBR(UPDATE_FUNC_ARGS) {
+ int r, rx, ry, nb;
+ for (rx=-1; rx<2; rx++)
+ for (ry=-1; ry<2; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if (!r)
+ continue;
+ if ((ptypes[r&0xFF].properties & (TYPE_SOLID | TYPE_PART | TYPE_LIQUID)) && !(ptypes[r&0xFF].properties & PROP_SPARKSETTLE))
+ {
+ kill_part(i);
+ return 1;
+ }
+ }
+ return 0;
+}
+int graphics_EMBR(GRAPHICS_FUNC_ARGS)
+{
+ if (cpart->ctype&0xFFFFFF)
+ {
+ int maxComponent;
+ *colr = (cpart->ctype&0xFF0000)>>16;
+ *colg = (cpart->ctype&0x00FF00)>>8;
+ *colb = (cpart->ctype&0x0000FF);
+ maxComponent = *colr;
+ if (*colg>maxComponent) maxComponent = *colg;
+ if (*colb>maxComponent) maxComponent = *colb;
+ if (maxComponent<60)//make sure it isn't too dark to see
+ {
+ float multiplier = 60.0f/maxComponent;
+ *colr *= multiplier;
+ *colg *= multiplier;
+ *colb *= multiplier;
+ }
+ }
+ else if (cpart->tmp != 0)
+ {
+ *colr = *colg = *colb = 255;
+ }
+
+ if (decorations_enable && cpart->dcolour)
+ {
+ int a = (cpart->dcolour>>24)&0xFF;
+ *colr = (a*((cpart->dcolour>>16)&0xFF) + (255-a)**colr) >> 8;
+ *colg = (a*((cpart->dcolour>>8)&0xFF) + (255-a)**colg) >> 8;
+ *colb = (a*((cpart->dcolour)&0xFF) + (255-a)**colb) >> 8;
+ }
+ *firer = *colr;
+ *fireg = *colg;
+ *fireb = *colb;
+
+ if (cpart->tmp==1)
+ {
+ *pixel_mode = FIRE_ADD | PMODE_BLEND | PMODE_GLOW;
+ *firea = (cpart->life-15)*4;
+ *cola = (cpart->life+15)*4;
+ }
+ else if (cpart->tmp==2)
+ {
+ *pixel_mode = PMODE_FLAT | FIRE_ADD;
+ *firea = 255;
+ }
+ else
+ {
+ *pixel_mode = PMODE_SPARK | PMODE_ADD;
+ if (cpart->life<64) *cola = 4*cpart->life;
+ }
+ return 0;
+}
diff --git a/src/elements/firw.c b/src/elements/firw.c
index 5bb8f3d..3f392b6 100644
--- a/src/elements/firw.c
+++ b/src/elements/firw.c
@@ -14,10 +14,11 @@
*/
#include <element.h>
+#include "hmap.h"
int update_FIRW(UPDATE_FUNC_ARGS) {
int r, rx, ry, rt, np;
- if (parts[i].tmp==0) {
+ if (parts[i].tmp<=0) {
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
@@ -29,52 +30,42 @@ int update_FIRW(UPDATE_FUNC_ARGS) {
if (rt==PT_FIRE||rt==PT_PLSM||rt==PT_THDR)
{
parts[i].tmp = 1;
- parts[i].life = rand()%50+60;
+ parts[i].life = rand()%40+60;
}
}
}
else if (parts[i].tmp==1) {
- if (parts[i].life==0) {
+ if (parts[i].life<=0) {
parts[i].tmp=2;
} else {
- float newVel = parts[i].life/25;
- parts[i].flags &= ~FLAG_STAGNANT;
- /* TODO:
- if ((pmap[(int)(ly-newVel)][(int)lx]&0xFF)==PT_NONE && ly-newVel>0) {
- parts[i].vy = -newVel;
- ly-=newVel;
- iy-=newVel;
- }*/
- parts[i].vy = -newVel;
+ // TODO: different gravity modes + Newtonian gravity
+ parts[i].vy = -parts[i].life*0.04f - 0.1f;
}
}
- else if (parts[i].tmp==2) {
- int col = rand()%200+4;
- int tmul;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- tmul = rand()%7;
- np = create_part(-1, x+rx, y+ry, PT_FIRW);
- if (np>-1)
- {
- parts[np].vx = (rand()%3-1)*tmul;
- parts[np].vy = (rand()%3-1)*tmul;
- parts[np].tmp = col;
- parts[np].life = rand()%100+100;
- parts[np].temp = 6000.0f;
- parts[np].dcolour = parts[i].dcolour;
- }
- }
- pv[y/CELL][x/CELL] += 20;
+ else if (parts[i].tmp>=2) {
+ float angle, magnitude;
+ int caddress = (rand()%200)*3;
+ int n;
+ unsigned col = (((unsigned char)(firw_data[caddress]))<<16) | (((unsigned char)(firw_data[caddress+1]))<<8) | ((unsigned char)(firw_data[caddress+2]));
+ for (n=0; n<40; n++)
+ {
+ np = create_part(-3, x, y, PT_EMBR);
+ if (np>-1)
+ {
+ magnitude = ((rand()%60)+40)*0.05f;
+ angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi)
+ parts[np].vx = parts[i].vx + cosf(angle)*magnitude;
+ parts[np].vy = parts[i].vy + sinf(angle)*magnitude - 2.5f;
+ parts[np].ctype = col;
+ parts[np].tmp = 1;
+ parts[np].life = rand()%40+70;
+ parts[np].temp = (rand()%500)+5750.0f;
+ parts[np].dcolour = parts[i].dcolour;
+ }
+ }
+ pv[y/CELL][x/CELL] += 8.0f;
kill_part(i);
return 1;
- } else if (parts[i].tmp>=3) {
- if (parts[i].life<=0) {
- kill_part(i);
- return 1;
- }
}
return 0;
}
diff --git a/src/elements/fwrk.c b/src/elements/fwrk.c
index 173b6e7..f54877b 100644
--- a/src/elements/fwrk.c
+++ b/src/elements/fwrk.c
@@ -34,33 +34,29 @@ int update_FWRK(UPDATE_FUNC_ARGS) {
parts[i].life=0;
if ((parts[i].life<3&&parts[i].life>0)||(parts[i].vy>6&&parts[i].life>0))
{
- int q = (rand()%255+1);
- int w = (rand()%255+1);
- int e = (rand()%255+1);
- for (rx=-1; rx<2; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- if (5>=rand()%8)
- {
- if (!pmap[y+ry][x+rx])
- {
- np = create_part(-1, x+rx, y+ry , PT_DUST);
- pv[y/CELL][x/CELL] += 2.00f*CFDS;
- if (np!=-1)
- {
- parts[np].vy = -(rand()%10-1);
- parts[np].vx = ((rand()%2)*2-1)*rand()%(5+5)+(parts[i].vx)*2 ;
- parts[np].life= rand()%37+18;
- parts[np].tmp=q;
- parts[np].tmp2=w;
- parts[np].ctype=e;
- parts[np].temp= rand()%20+6000;
- parts[np].dcolour = parts[i].dcolour;
- }
- }
- }
- }
+ int r = (rand()%245+11);
+ int g = (rand()%245+11);
+ int b = (rand()%245+11);
+ int n;
+ float angle, magnitude;
+ unsigned col = (r<<16) | (g<<8) | b;
+ for (n=0; n<40; n++)
+ {
+ np = create_part(-3, x, y, PT_EMBR);
+ if (np>-1)
+ {
+ magnitude = ((rand()%60)+40)*0.05f;
+ angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi)
+ parts[np].vx = parts[i].vx + cosf(angle)*magnitude;
+ parts[np].vy = parts[i].vy + sinf(angle)*magnitude - 2.5f;
+ parts[np].ctype = col;
+ parts[np].tmp = 1;
+ parts[np].life = rand()%40+70;
+ parts[np].temp = (rand()%500)+5750.0f;
+ parts[np].dcolour = parts[i].dcolour;
+ }
+ }
+ pv[y/CELL][x/CELL] += 8.0f;
kill_part(i);
return 1;
}
diff --git a/src/elements/ignt.c b/src/elements/ignt.c
index 36f48a3..bf706bc 100644
--- a/src/elements/ignt.c
+++ b/src/elements/ignt.c
@@ -40,9 +40,9 @@ int update_IGNT(UPDATE_FUNC_ARGS) {
{
if(rand()%3)
{
- int nb = create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_BOMB);
+ int nb = create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_EMBR);
if (nb!=-1) {
- parts[nb].tmp = 1;
+ parts[nb].tmp = 0;
parts[nb].life = 30;
parts[nb].vx = rand()%20-10;
parts[nb].vy = rand()%20-10;
diff --git a/src/elements/newgraphics.c b/src/elements/newgraphics.c
index 946afc8..c8581f6 100644
--- a/src/elements/newgraphics.c
+++ b/src/elements/newgraphics.c
@@ -117,29 +117,6 @@ int graphics_LIFE(GRAPHICS_FUNC_ARGS)
*colb = PIXB(pc);
return 0;
}
-int graphics_DUST(GRAPHICS_FUNC_ARGS)
-{
- if(cpart->life >= 1)
- {
- *firea = 120;
- *firer = *colr = cpart->tmp2;
- *fireg = *colg = cpart->tmp;
- *fireb = *colb = cpart->ctype;
- if (decorations_enable && cpart->dcolour)
- {
- int a = (cpart->dcolour>>24)&0xFF;
- *firer = *colr = (a*((cpart->dcolour>>16)&0xFF) + (255-a)**colr) >> 8;
- *fireg = *colg = (a*((cpart->dcolour>>8)&0xFF) + (255-a)**colg) >> 8;
- *fireb = *colb = (a*((cpart->dcolour)&0xFF) + (255-a)**colb) >> 8;
- }
- *pixel_mode |= PMODE_GLOW | FIRE_ADD;
- /**firea = 255;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;*/
- }
- return 0;
-}
int graphics_GRAV(GRAPHICS_FUNC_ARGS)
{
*colr = 20;
@@ -497,33 +474,7 @@ int graphics_HFLM(GRAPHICS_FUNC_ARGS)
}
int graphics_FIRW(GRAPHICS_FUNC_ARGS)
{
- if(cpart->tmp>=3)
- {
- int caddress = restrict_flt(restrict_flt((float)(cpart->tmp-4), 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
- *colr = (unsigned char)firw_data[caddress];
- *colg = (unsigned char)firw_data[caddress+1];
- *colb = (unsigned char)firw_data[caddress+2];
-
- if (decorations_enable && cpart->dcolour)
- {
- int a = (cpart->dcolour>>24)&0xFF;
- *colr = (a*((cpart->dcolour>>16)&0xFF) + (255-a)**colr) >> 8;
- *colg = (a*((cpart->dcolour>>8)&0xFF) + (255-a)**colg) >> 8;
- *colb = (a*((cpart->dcolour)&0xFF) + (255-a)**colb) >> 8;
- }
-
- *firea = cpart->life*4;
- if(*firea > 240)
- *firea = 240;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
-
- *pixel_mode = PMODE_NONE; //Clear default, don't draw pixel
- *pixel_mode |= FIRE_ADD;
- //Returning 0 means dynamic, do not cache
- }
- else if(cpart->tmp > 0)
+ if(cpart->tmp > 0)
{
*pixel_mode |= PMODE_GLOW;
}