diff options
| author | jacksonmj <jacksonmj@jacksonmj.none> | 2011-01-10 14:41:03 (GMT) |
|---|---|---|
| committer | jacksonmj <jacksonmj@jacksonmj.none> | 2011-01-10 14:41:03 (GMT) |
| commit | 54f9f872b9e4d5a0086d6de104e84d43b125c349 (patch) | |
| tree | b567fb9d3710acbce22f8193bfe2585bb2988bed /src/elements/stkm.c | |
| parent | 855281295fbc23366e8b84d7c8e55816d6f47a87 (diff) | |
| download | powder-54f9f872b9e4d5a0086d6de104e84d43b125c349.zip powder-54f9f872b9e4d5a0086d6de104e84d43b125c349.tar.gz | |
Finish update function cleanup
Diffstat (limited to 'src/elements/stkm.c')
| -rw-r--r-- | src/elements/stkm.c | 94 |
1 files changed, 48 insertions, 46 deletions
diff --git a/src/elements/stkm.c b/src/elements/stkm.c index 8b581b8..2403bc2 100644 --- a/src/elements/stkm.c +++ b/src/elements/stkm.c @@ -11,7 +11,7 @@ int update_SPAWN(UPDATE_FUNC_ARGS) { } int update_STKM(UPDATE_FUNC_ARGS) { - int r; + int r, rx, ry; float pp, d; float dt = 0.9;///(FPSB*FPSB); //Delta time in square //Tempirature handling @@ -173,56 +173,58 @@ int update_STKM(UPDATE_FUNC_ARGS) { set_emap((int)(player[15]+0.5)/CELL, (int)(player[16]+0.5)/CELL); //Searching for particles near head - for (nx = -2; nx <= 2; nx++) - for (ny = 0; ny>=-2; ny--) - { - if (!pmap[ny+y][nx+x] || (pmap[ny+y][nx+x]>>8)>=NPART) - continue; - if (ptypes[pmap[ny+y][nx+x]&0xFF].falldown!=0 || (pmap[ny+y][nx+x]&0xFF) == PT_NEUT || (pmap[ny+y][nx+x]&0xFF) == PT_PHOT) - { - player[2] = pmap[ny+y][nx+x]&0xFF; //Current element - } - if ((pmap[ny+y][nx+x]&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP + 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)) { - if (parts[i].life<=95) - parts[i].life += 5; - else - parts[i].life = 100; - kill_part(pmap[ny+y][nx+x]>>8); - } + r = pmap[y+ry][x+rx]; + if (!r || (r>>8)>=NPART) + continue; + if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) // TODO: photons are not in the pmap. This line may not work as intended. + { + player[2] = r&0xFF; //Current element + } + if ((r&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP + { + if (parts[i].life<=95) + parts[i].life += 5; + else + parts[i].life = 100; + kill_part(r>>8); + } - if ((pmap[ny+y][nx+x]&0xFF) == PT_NEUT) - { - parts[i].life -= (102-parts[i].life)/2; - kill_part(pmap[ny+y][nx+x]>>8); + if ((r&0xFF) == PT_NEUT) + { + parts[i].life -= (102-parts[i].life)/2; + kill_part(r>>8); + } + if (bmap[(ry+y)/CELL][(rx+x)/CELL]==WL_FAN) + player[2] = SPC_AIR; } - if (bmap[(ny+y)/CELL][(nx+x)/CELL]==WL_FAN) - player[2] = SPC_AIR; - } //Head position - nx = x + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01); - ny = y - 3*(player[1] == 0); + rx = x + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01); + ry = y - 3*(player[1] == 0); //Spawn if (((int)(player[0])&0x08) == 0x08) { - ny -= 2*(rand()%2)+1; - r = pmap[ny][nx]; + ry -= 2*(rand()%2)+1; + r = pmap[ry][rx]; if (!((r>>8)>=NPART)) { if (pstates[r&0xFF].state == ST_SOLID) { - create_part(-1, nx, ny, PT_SPRK); + create_part(-1, rx, ry, PT_SPRK); } else { if (player[2] == SPC_AIR) - create_parts(nx + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01), ny, 4, 4, SPC_AIR); + create_parts(rx + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR); else - create_part(-1, nx, ny, player[2]); + create_part(-1, rx, ry, player[2]); - r = pmap[ny][nx]; + r = pmap[ry][rx]; if ( ((r>>8) < NPART) && (r>>8)>=0 && player[2] != PT_PHOT && player[2] != SPC_AIR) parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player[1])&0x02) == 0x02) - 5*(((int)(player[1])&0x01) == 0x01); if (((r>>8) < NPART) && (r>>8)>=0 && player[2] == PT_PHOT) @@ -270,26 +272,26 @@ int update_STKM(UPDATE_FUNC_ARGS) { player[12] += (player[12]-parts[i].y)*d; //Side collisions checking - for (nx = -3; nx <= 3; nx++) + for (rx = -3; rx <= 3; rx++) { - r = pmap[(int)(player[16]-2)][(int)(player[15]+nx)]; + r = pmap[(int)(player[16]-2)][(int)(player[15]+rx)]; if (r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID) - player[15] -= nx; + player[15] -= rx; - r = pmap[(int)(player[8]-2)][(int)(player[7]+nx)]; + r = pmap[(int)(player[8]-2)][(int)(player[7]+rx)]; if (r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID) - player[7] -= nx; + player[7] -= rx; } //Collision checks - for (ny = -2-(int)parts[i].vy; ny<=0; ny++) + for (ry = -2-(int)parts[i].vy; ry<=0; ry++) { - r = pmap[(int)(player[8]+ny)][(int)(player[7]+0.5)]; //This is to make coding more pleasant :-) + r = pmap[(int)(player[8]+ry)][(int)(player[7]+0.5)]; //This is to make coding more pleasant :-) //For left leg if (r && (r&0xFF)!=PT_STKM) { - if (pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks //Liquid checks + if (pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks { if (parts[i].y<(player[8]-10)) parts[i].vy = 1*dt; @@ -302,14 +304,14 @@ int update_STKM(UPDATE_FUNC_ARGS) { { if (pstates[r&0xFF].state != ST_GAS) { - player[8] += ny-1; + player[8] += ry-1; parts[i].vy -= 0.5*parts[i].vy*dt; } } player[9] = player[7]; } - r = pmap[(int)(player[16]+ny)][(int)(player[15]+0.5)]; + r = pmap[(int)(player[16]+ry)][(int)(player[15]+0.5)]; //For right leg if (r && (r&0xFF)!=PT_STKM) @@ -327,7 +329,7 @@ int update_STKM(UPDATE_FUNC_ARGS) { { if (pstates[r&0xFF].state != ST_GAS) { - player[16] += ny-1; + player[16] += ry-1; parts[i].vy -= 0.5*parts[i].vy*dt; } } @@ -337,7 +339,7 @@ int update_STKM(UPDATE_FUNC_ARGS) { //If it falls too fast if (parts[i].vy>=30) { - parts[i].y -= (10+ny)*dt; + parts[i].y -= (10+ry)*dt; parts[i].vy = -10*dt; } @@ -363,9 +365,9 @@ int update_STKM(UPDATE_FUNC_ARGS) { parts[i].life -= (int)(rand()/1000)+38; } - if (r>0 && (r>>8)<NPART) //If hot or cold + if (r>0 && (r>>8)<NPART) { - if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) + if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) //If hot or cold { parts[i].life -= 2; player[26] -= 1; |
