diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2011-08-14 17:32:10 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-08-14 17:32:10 (GMT) |
| commit | dcd3af94404b1d1bb296566a84177cc37e0b83d5 (patch) | |
| tree | 77385a265e760cd8bd86ac9077e2c0f58c6204e8 /src/elements | |
| parent | d3153aae85f2e3cd1ba8ff0520e5ebe51e08d7d5 (diff) | |
| parent | ca66525bea67de164603163752aee0212d59df34 (diff) | |
| download | powder-dcd3af94404b1d1bb296566a84177cc37e0b83d5.zip powder-dcd3af94404b1d1bb296566a84177cc37e0b83d5.tar.gz | |
Merge branch 'master' of github.com:FacialTurd/The-Powder-Toy
Diffstat (limited to 'src/elements')
| -rw-r--r-- | src/elements/O2.c | 2 | ||||
| -rw-r--r-- | src/elements/h2.c | 4 | ||||
| -rw-r--r-- | src/elements/pyro.c | 1 | ||||
| -rw-r--r-- | src/elements/stkm.c | 262 | ||||
| -rw-r--r-- | src/elements/wtrv.c | 2 |
5 files changed, 126 insertions, 145 deletions
diff --git a/src/elements/O2.c b/src/elements/O2.c index 2584d3a..a008766 100644 --- a/src/elements/O2.c +++ b/src/elements/O2.c @@ -14,6 +14,8 @@ int update_O2(UPDATE_FUNC_ARGS) if ((r&0xFF)==PT_FIRE) { parts[r>>8].temp+=(rand()/(RAND_MAX/100)); + if(parts[r>>8].tmp&0x01) + parts[r>>8].temp=3473; parts[r>>8].tmp |= 2; } if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) diff --git a/src/elements/h2.c b/src/elements/h2.c index 336f496..04f3d01 100644 --- a/src/elements/h2.c +++ b/src/elements/h2.c @@ -18,7 +18,9 @@ int update_H2(UPDATE_FUNC_ARGS) } if ((r&0xFF)==PT_FIRE) { - parts[r>>8].temp+=(rand()/(RAND_MAX/100)); + parts[r>>8].temp=2473.15; + if(parts[r>>8].tmp&0x02) + parts[r>>8].temp=3473; parts[r>>8].tmp |= 1; } if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM || (r&0xFF)==PT_LAVA) diff --git a/src/elements/pyro.c b/src/elements/pyro.c index 985151a..bd6ab26 100644 --- a/src/elements/pyro.c +++ b/src/elements/pyro.c @@ -14,6 +14,7 @@ int update_PYRO(UPDATE_FUNC_ARGS) { t = PT_DSTW; part_change_type(i,x,y,t); parts[i].life = 0; + parts[i].ctype = PT_FIRE; } else if (parts[i].temp<625) { diff --git a/src/elements/stkm.c b/src/elements/stkm.c index f3b1c3c..89bcd0e 100644 --- a/src/elements/stkm.c +++ b/src/elements/stkm.c @@ -41,34 +41,59 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { return 1; } - parts[i].vy += -0.7*dt; //Head up! + //Follow gravity + float gvx, gvy; + gvx = gvy = 0.0f; + switch (gravityMode) + { + default: + case 0: + gvy = 1; + break; + case 1: + gvy = gvx = 0.0f; + break; + case 2: + { + float gravd; + gravd = 0.01f - hypotf((parts[i].x - XCNTR), (parts[i].y - YCNTR)); + gvx = ((float)(parts[i].x - XCNTR) / gravd); + gvy = ((float)(parts[i].y - YCNTR) / gravd); + } + } + + gvx += gravx[(int)parts[i].y/CELL][(int)parts[i].x/CELL]; + gvy += gravy[(int)parts[i].y/CELL][(int)parts[i].x/CELL]; + + parts[i].vx -= gvx*dt; //Head up! + parts[i].vy -= gvy*dt; //Verlet integration - pp = 2*playerp[3]-playerp[5]+playerp[19]*dt*dt;; + pp = 2*playerp[3]-playerp[5]+playerp[19]*dt*dt; playerp[5] = playerp[3]; playerp[3] = pp; - pp = 2*playerp[4]-playerp[6]+playerp[20]*dt*dt;; + pp = 2*playerp[4]-playerp[6]+playerp[20]*dt*dt; playerp[6] = playerp[4]; playerp[4] = pp; - pp = 2*playerp[7]-playerp[9]+playerp[21]*dt*dt;; + pp = 2*playerp[7]-playerp[9]+(playerp[21]+gvx)*dt*dt; playerp[9] = playerp[7]; playerp[7] = pp; - pp = 2*playerp[8]-playerp[10]+(playerp[22]+1)*dt*dt;; + pp = 2*playerp[8]-playerp[10]+(playerp[22]+gvy)*dt*dt; playerp[10] = playerp[8]; playerp[8] = pp; - pp = 2*playerp[11]-playerp[13]+playerp[23]*dt*dt;; + pp = 2*playerp[11]-playerp[13]+playerp[23]*dt*dt; playerp[13] = playerp[11]; playerp[11] = pp; - pp = 2*playerp[12]-playerp[14]+playerp[24]*dt*dt;; + pp = 2*playerp[12]-playerp[14]+playerp[24]*dt*dt; playerp[14] = playerp[12]; playerp[12] = pp; - pp = 2*playerp[15]-playerp[17]+playerp[25]*dt*dt;; + pp = 2*playerp[15]-playerp[17]+(playerp[25]+gvx)*dt*dt; playerp[17] = playerp[15]; playerp[15] = pp; - pp = 2*playerp[16]-playerp[18]+(playerp[26]+1)*dt*dt;; + pp = 2*playerp[16]-playerp[18]+(playerp[26]+gvy)*dt*dt; playerp[18] = playerp[16]; playerp[16] = pp; @@ -85,98 +110,70 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { playerp[25] = 0; playerp[26] = 0; + float gx, gy, dl, dr; + + gx = (playerp[7] + playerp[15])/2 - gvy; + gy = (playerp[8] + playerp[16])/2 + gvx; + dl = pow(gx - playerp[7], 2) + pow(gy - playerp[8], 2); + dr = pow(gx - playerp[15], 2) + pow(gy - playerp[16], 2); + //Go left - r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]; - if (((int)(playerp[0])&0x01) == 0x01 && (((r&0xFF)>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS)) + if (((int)(playerp[0])&0x01) == 0x01) { - if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID - && (r&0xFF) != PT_LNTG)) + if (dl>dr) { - if (pmap[(int)(playerp[8]-1)][(int)(playerp[7])]) + if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL)) { - playerp[21] = -3; - playerp[22] = -2; - playerp[19] = -2; - } - - if (pmap[(int)(playerp[16]-1)][(int)(playerp[15])]) - { - playerp[25] = -3; - playerp[26] = -2; - playerp[23] = -2; + playerp[21] = -3*gvy-3*gvx; + playerp[22] = 3*gvx-3*gvy; + playerp[19] = -gvy; + playerp[20] = gvx; } } else { - if (pmap[(int)(playerp[8]-1)][(int)(playerp[7])]) //It should move another way in liquids + if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL)) { - playerp[21] = -1; - playerp[22] = -1; - playerp[19] = -1; - } - - if (pmap[(int)(playerp[16]-1)][(int)(playerp[15])]) - { - playerp[25] = -1; - playerp[26] = -1; - playerp[23] = -1; + playerp[25] = -3*gvy-3*gvx; + playerp[26] = 3*gvx-3*gvy; + playerp[19] = -gvy; + playerp[20] = gvx; } } } //Go right - r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]; - if (((int)(playerp[0])&0x02) == 0x02 && (((r&0xFF)>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS)) + if (((int)(playerp[0])&0x02) == 0x02) { - if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID - && (r&0xFF) != PT_LNTG)) + if (dl<dr) { - if (pmap[(int)(playerp[8]-1)][(int)(playerp[7])]) - { - playerp[21] = 3; - playerp[22] = -2; - playerp[19] = 2; - } - - if (pmap[(int)(playerp[16]-1)][(int)(playerp[15])]) + if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL)) { - playerp[25] = 3; - playerp[26] = -2; - playerp[23] = 2; + playerp[21] = 3*gvy-3*gvx; + playerp[22] = -3*gvx-3*gvy; + playerp[19] = gvy; + playerp[20] = -gvx; } } else { - if (pmap[(int)(playerp[8]-1)][(int)(playerp[7])]) - { - playerp[21] = 1; - playerp[22] = -1; - playerp[19] = 1; - } - - if (pmap[(int)(playerp[16]-1)][(int)(playerp[15])]) + if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL)) { - playerp[25] = 1; - playerp[26] = -1; - playerp[23] = 1; + playerp[25] = 3*gvy-3*gvx; + playerp[26] = -3*gvx-3*gvy; + playerp[19] = gvy; + playerp[20] = -gvx; } - } } //Jump - if (((int)(playerp[0])&0x04) == 0x04 && ( - (pmap[(int)(playerp[8]-0.5)][(int)(playerp[7])]&0xFF)>=PT_NUM || - ptypes[pmap[(int)(playerp[8]-0.5)][(int)(playerp[7])]&0xFF].state != ST_GAS || - (pmap[(int)(playerp[16]-0.5)][(int)(playerp[15])]&0xFF)>=PT_NUM || - ptypes[pmap[(int)(playerp[16]-0.5)][(int)(playerp[15])]&0xFF].state != ST_GAS)) + if (((int)(playerp[0])&0x04) == 0x04 && + (!eval_move(PT_DUST, playerp[7], playerp[8], NULL) || !eval_move(PT_DUST, playerp[15], playerp[16], NULL))) { - if (pmap[(int)(playerp[8]-0.5)][(int)(playerp[7])] || pmap[(int)(playerp[16]-0.5)][(int)(playerp[15])]) - { - parts[i].vy = -5; - playerp[22] -= 1; - playerp[26] -= 1; - } + parts[i].vy -= 4*gvy; + playerp[22] -= gvy; + playerp[26] -= gvy; } //Charge detector wall if foot inside @@ -243,7 +240,11 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { else np = create_part(-1, rx, ry, playerp[2]); if ( (np < NPART) && np>=0 && playerp[2] != PT_PHOT && playerp[2] != SPC_AIR) - parts[np].vx = parts[np].vx + 5*((((int)playerp[1])&0x02) == 0x02) - 5*(((int)(playerp[1])&0x01) == 0x01); + { + parts[np].vx -= -gvy*(5*((((int)playerp[1])&0x02) == 0x02) - 5*(((int)(playerp[1])&0x01) == 0x01)); + parts[np].vy -= gvx*(5*((((int)playerp[1])&0x02) == 0x02) - 5*(((int)(playerp[1])&0x01) == 0x01)); + parts[i].vx -= (ptypes[(int)playerp[2]].weight*parts[np].vx)/1000; + } if ((np < NPART) && np>=0 && playerp[2] == PT_PHOT) { int random = abs(rand()%3-1)*3; @@ -290,91 +291,64 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) { playerp[11] += (playerp[11]-parts[i].x)*d; playerp[12] += (playerp[12]-parts[i].y)*d; - //Side collisions checking - for (rx = -3; rx <= 3; rx++) + if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL)) { - r = pmap[(int)(playerp[16]-2)][(int)(playerp[15]+rx)]; - if (r && ((r&0xFF)>=PT_NUM || (ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID))) - playerp[15] -= rx; + playerp[7] = playerp[9]; + playerp[8] = playerp[10]; + } - r = pmap[(int)(playerp[8]-2)][(int)(playerp[7]+rx)]; - if (r && ((r&0xFF)>=PT_NUM || (ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID))) - playerp[7] -= rx; + if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL)) + { + playerp[15] = playerp[17]; + playerp[16] = playerp[18]; } - //Collision checks - for (ry = -2-(int)parts[i].vy; ry<=0; ry++) + //This makes stick man "pop" from obstacles + if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL)) { - r = pmap[(int)(playerp[8]+ry)][(int)(playerp[7]+0.5)]; //This is to make coding more pleasant :-) + float t; + t = playerp[7]; playerp[7] = playerp[9]; playerp[9] = t; + t = playerp[8]; playerp[8] = playerp[10]; playerp[10] = t; + } - //For left leg - if (r && (r&0xFF)!=PT_STKM) - { - if ((r&0xFF)<PT_NUM && (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG)) //Liquid checks - { - if (parts[i].y<(playerp[8]-10)) - parts[i].vy = 1*dt; - else - parts[i].vy = 0; - if (abs(parts[i].vx)>1) - parts[i].vx *= 0.5*dt; - } - else - { - if ((r&0xFF)>=PT_NUM || ptypes[r&0xFF].state != ST_GAS) - { - playerp[8] += ry-1; - parts[i].vy -= 0.5*parts[i].vy*dt; - } - } - playerp[9] = playerp[7]; - } + if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL)) + { + float t; + t = playerp[15]; playerp[15] = playerp[17]; playerp[17] = t; + t = playerp[16]; playerp[16] = playerp[18]; playerp[18] = t; + } - r = pmap[(int)(playerp[16]+ry)][(int)(playerp[15]+0.5)]; + //Keeping legs distance + if ((pow((playerp[7] - playerp[15]), 2) + pow((playerp[8]-playerp[16]), 2))<16) + { + float tvx, tvy; + tvx = -gvy; + tvy = gvx; - //For right leg - if (r && (r&0xFF)!=PT_STKM) + if (tvx || tvy) { - if ((r&0xFF)<PT_NUM && (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG)) - { - if (parts[i].y<(playerp[16]-10)) - parts[i].vy = 1*dt; - else - parts[i].vy = 0; - if (abs(parts[i].vx)>1) - parts[i].vx *= 0.5*dt; - } - else - { - if ((r&0xFF)>=PT_NUM || ptypes[r&0xFF].state != ST_GAS) - { - playerp[16] += ry-1; - parts[i].vy -= 0.5*parts[i].vy*dt; - } - } - playerp[17] = playerp[15]; - } + playerp[21] -= 0.2*tvx/hypot(tvx, tvy); + playerp[22] -= 0.2*tvy/hypot(tvx, tvy); - //If it falls too fast - if (parts[i].vy>=30) - { - parts[i].y -= (10+ry)*dt; - parts[i].vy = -10*dt; + playerp[25] += 0.2*tvx/hypot(tvx, tvy); + playerp[26] += 0.2*tvy/hypot(tvx, tvy); } - } - //Keeping legs distance - if (pow((playerp[7] - playerp[15]), 2)<16 && pow((playerp[8]-playerp[16]), 2)<1) + if ((pow((playerp[3] - playerp[11]), 2) + pow((playerp[4]-playerp[12]), 2))<16) { - playerp[21] -= 0.2; - playerp[25] += 0.2; - } + float tvx, tvy; + tvx = -gvy; + tvy = gvx; - if (pow((playerp[3] - playerp[11]), 2)<16 && pow((playerp[4]-playerp[12]), 2)<1) - { - playerp[19] -= 0.2; - playerp[23] += 0.2; + if (tvx || tvy) + { + playerp[19] -= 0.2*tvx/hypot(tvx, tvy); + playerp[20] -= 0.2*tvy/hypot(tvx, tvy); + + playerp[23] += 0.2*tvx/hypot(tvx, tvy); + playerp[24] += 0.2*tvy/hypot(tvx, tvy); + } } //If legs touch something diff --git a/src/elements/wtrv.c b/src/elements/wtrv.c index 7a32c94..a4facde 100644 --- a/src/elements/wtrv.c +++ b/src/elements/wtrv.c @@ -15,5 +15,7 @@ int update_WTRV(UPDATE_FUNC_ARGS) { parts[i].life = 4; } } + if(parts[i].temp>1273&&parts[i].ctype==PT_FIRE) + parts[i].temp-=parts[i].temp/1000; return 0; } |
