diff options
| author | jacksonmj <mj-pt@jacksonmj.co.uk> | 2012-06-21 12:31:35 (GMT) |
|---|---|---|
| committer | jacksonmj <mj-pt@jacksonmj.co.uk> | 2012-06-21 12:58:35 (GMT) |
| commit | 31ce22f122111267f7e2989a6eaf0e627ea7d2a7 (patch) | |
| tree | 9f14e764026452dd85024f7ee85b21c9981d2bcb /src/elements | |
| parent | ded23cfa948ef224075e59340a4ab70f3b1b9f28 (diff) | |
| download | powder-31ce22f122111267f7e2989a6eaf0e627ea7d2a7.zip powder-31ce22f122111267f7e2989a6eaf0e627ea7d2a7.tar.gz | |
Gravity modes and Newtonian gravity for fireworks
Resolves issue #59
Diffstat (limited to 'src/elements')
| -rw-r--r-- | src/elements/firw.c | 20 | ||||
| -rw-r--r-- | src/elements/fwrk.c | 44 |
2 files changed, 47 insertions, 17 deletions
diff --git a/src/elements/firw.c b/src/elements/firw.c index 3f392b6..d0e863e 100644 --- a/src/elements/firw.c +++ b/src/elements/firw.c @@ -29,8 +29,19 @@ int update_FIRW(UPDATE_FUNC_ARGS) { rt = parts[r>>8].type; if (rt==PT_FIRE||rt==PT_PLSM||rt==PT_THDR) { + float gx, gy, multiplier; + get_gravity_field(x, y, ptypes[PT_FIRW].gravity, 1.0f, &gx, &gy); + if (gx*gx+gy*gy < 0.001f) + { + float angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi) + gx += sinf(angle)*ptypes[PT_FIRW].gravity*0.5f; + gy += cosf(angle)*ptypes[PT_FIRW].gravity*0.5f; + } parts[i].tmp = 1; - parts[i].life = rand()%40+60; + parts[i].life = rand()%10+20; + multiplier = (parts[i].life+20)*0.2f/sqrtf(gx*gx+gy*gy); + parts[i].vx -= gx*multiplier; + parts[i].vy -= gy*multiplier; } } } @@ -38,8 +49,7 @@ int update_FIRW(UPDATE_FUNC_ARGS) { if (parts[i].life<=0) { parts[i].tmp=2; } else { - // TODO: different gravity modes + Newtonian gravity - parts[i].vy = -parts[i].life*0.04f - 0.1f; + parts[i].flags &= ~FLAG_STAGNANT; } } else if (parts[i].tmp>=2) { @@ -54,8 +64,8 @@ int update_FIRW(UPDATE_FUNC_ARGS) { { 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].vx = parts[i].vx*0.5f + cosf(angle)*magnitude; + parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude; parts[np].ctype = col; parts[np].tmp = 1; parts[np].life = rand()%40+70; diff --git a/src/elements/fwrk.c b/src/elements/fwrk.c index f54877b..d6dc59c 100644 --- a/src/elements/fwrk.c +++ b/src/elements/fwrk.c @@ -17,22 +17,42 @@ int update_FWRK(UPDATE_FUNC_ARGS) { int r, rx, ry, np; - if ((parts[i].temp>400&&(9+parts[i].temp/40)>rand()%100000&&parts[i].life==0&&!pmap[y-1][x])||parts[i].ctype==PT_DUST) + if (parts[i].life==0 && ((parts[i].temp>400&&(9+parts[i].temp/40)>rand()%100000&&surround_space)||parts[i].ctype==PT_DUST)) { - np = create_part(-1, x , y-1 , PT_FWRK); - if (np!=-1) + float gx, gy, multiplier, gmax; + int randTmp; + get_gravity_field(x, y, ptypes[PT_FWRK].gravity, 1.0f, &gx, &gy); + if (gx*gx+gy*gy < 0.001f) { - parts[np].vy = rand()%8-22; - parts[np].vx = rand()%20-rand()%20; - parts[np].life=rand()%15+25; - parts[np].dcolour = parts[i].dcolour; - kill_part(i); - return 1; + float angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi) + gx += sinf(angle)*ptypes[PT_FWRK].gravity*0.5f; + gy += cosf(angle)*ptypes[PT_FWRK].gravity*0.5f; + } + gmax = fmaxf(fabsf(gx), fabsf(gy)); + if (eval_move(PT_FWRK, (int)(x-(gx/gmax)+0.5f), (int)(y-(gy/gmax)+0.5f), NULL)) + { + multiplier = 15.0f/sqrtf(gx*gx+gy*gy); + + //Some variation in speed parallel to gravity direction + randTmp = (rand()%200)-100; + gx += gx*randTmp*0.002f; + gy += gy*randTmp*0.002f; + //and a bit more variation in speed perpendicular to gravity direction + randTmp = (rand()%200)-100; + gx += -gy*randTmp*0.005f; + gy += gx*randTmp*0.005f; + + parts[i].life=rand()%10+18; + parts[i].ctype=0; + parts[i].vx -= gx*multiplier; + parts[i].vy -= gy*multiplier; + parts[i].dcolour = parts[i].dcolour; + return 0; } } if (parts[i].life>=45) parts[i].life=0; - if ((parts[i].life<3&&parts[i].life>0)||(parts[i].vy>6&&parts[i].life>0)) + if (parts[i].life<3&&parts[i].life>0) { int r = (rand()%245+11); int g = (rand()%245+11); @@ -47,8 +67,8 @@ int update_FWRK(UPDATE_FUNC_ARGS) { { 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].vx = parts[i].vx*0.5f + cosf(angle)*magnitude; + parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude; parts[np].ctype = col; parts[np].tmp = 1; parts[np].life = rand()%40+70; |
