From 6e9cbfdb4a1cec1ab1a400bc5f6c30ecb61c84b3 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 27 May 2011 22:05:41 +0800 Subject: Fix STKM always going through walls Now behaves as normal, i.e. only occasionally goes through walls. Walls which completely block all particles are in the pmap with type 0xFF. ptypes[] doesn't go up to 0xFF, so ptypes[0xFF].state will not necessarily result in an answer that gives correct behaviour for walls. diff --git a/src/elements/stkm.c b/src/elements/stkm.c index fc6dc55..9a8a1ff 100644 --- a/src/elements/stkm.c +++ b/src/elements/stkm.c @@ -85,10 +85,11 @@ int update_STKM(UPDATE_FUNC_ARGS) { player[26] = 0; //Go left - if (((int)(player[0])&0x01) == 0x01 && ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) + r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]; + if (((int)(player[0])&0x01) == 0x01 && ((r&0xFF>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS)) { - if (ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID - && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) + if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID + && (r&0xFF) != PT_LNTG)) { if (pmap[(int)(player[8]-1)][(int)(player[7])]) { @@ -123,10 +124,11 @@ int update_STKM(UPDATE_FUNC_ARGS) { } //Go right - if (((int)(player[0])&0x02) == 0x02 && ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) + r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]; + if (((int)(player[0])&0x02) == 0x02 && ((r&0xFF>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS)) { - if (ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID - && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) + if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID + && (r&0xFF) != PT_LNTG)) { if (pmap[(int)(player[8]-1)][(int)(player[7])]) { @@ -162,7 +164,11 @@ int update_STKM(UPDATE_FUNC_ARGS) { } //Jump - if (((int)(player[0])&0x04) == 0x04 && (ptypes[pmap[(int)(player[8]-0.5)][(int)(player[7])]&0xFF].state != ST_GAS || ptypes[pmap[(int)(player[16]-0.5)][(int)(player[15])]&0xFF].state != ST_GAS)) + if (((int)(player[0])&0x04) == 0x04 && ( + (pmap[(int)(player[8]-0.5)][(int)(player[7])]&0xFF)>=PT_NUM || + ptypes[pmap[(int)(player[8]-0.5)][(int)(player[7])]&0xFF].state != ST_GAS || + (pmap[(int)(player[16]-0.5)][(int)(player[15])]&0xFF)>=PT_NUM || + ptypes[pmap[(int)(player[16]-0.5)][(int)(player[15])]&0xFF].state != ST_GAS)) { if (pmap[(int)(player[8]-0.5)][(int)(player[7])] || pmap[(int)(player[16]-0.5)][(int)(player[15])]) { @@ -284,11 +290,11 @@ int update_STKM(UPDATE_FUNC_ARGS) { for (rx = -3; rx <= 3; rx++) { r = pmap[(int)(player[16]-2)][(int)(player[15]+rx)]; - if (r && ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID) + if (r && ((r&0xFF)>=PT_NUM || (ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID))) player[15] -= rx; r = pmap[(int)(player[8]-2)][(int)(player[7]+rx)]; - if (r && ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID) + if (r && ((r&0xFF)>=PT_NUM || (ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID))) player[7] -= rx; } @@ -300,7 +306,7 @@ int update_STKM(UPDATE_FUNC_ARGS) { //For left leg if (r && (r&0xFF)!=PT_STKM) { - if (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks + if ((r&0xFF)=PT_NUM || ptypes[r&0xFF].state != ST_GAS) { player[8] += ry-1; parts[i].vy -= 0.5*parts[i].vy*dt; @@ -325,7 +331,7 @@ int update_STKM(UPDATE_FUNC_ARGS) { //For right leg if (r && (r&0xFF)!=PT_STKM) { - if (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) + if ((r&0xFF)=PT_NUM || ptypes[r&0xFF].state != ST_GAS) { player[16] += ry-1; parts[i].vy -= 0.5*parts[i].vy*dt; diff --git a/src/elements/stkm2.c b/src/elements/stkm2.c index 79dbbdf..4498060 100644 --- a/src/elements/stkm2.c +++ b/src/elements/stkm2.c @@ -85,10 +85,11 @@ int update_STKM2(UPDATE_FUNC_ARGS) { player2[26] = 0; //Go left - if (((int)(player2[0])&0x01) == 0x01 && ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) + r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]; + if (((int)(player2[0])&0x01) == 0x01 && ((r&0xFF>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS)) { - if (ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID - && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) + if (r>=PT_NUM || ptypes[r&0xFF].state != ST_LIQUID + && (r&0xFF) != PT_LNTG) { if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) { @@ -123,10 +124,11 @@ int update_STKM2(UPDATE_FUNC_ARGS) { } //Go right - if (((int)(player2[0])&0x02) == 0x02 && ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS) + r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]; + if (((int)(player2[0])&0x02) == 0x02 && ((r&0xFF>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS)) { - if (ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID - && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG) + if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID + && (r&0xFF) != PT_LNTG)) { if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) { @@ -162,7 +164,11 @@ int update_STKM2(UPDATE_FUNC_ARGS) { } //Jump - if (((int)(player2[0])&0x04) == 0x04 && (ptypes[pmap[(int)(player2[8]-0.5)][(int)(player2[7])]&0xFF].state != ST_GAS || ptypes[pmap[(int)(player2[16]-0.5)][(int)(player2[15])]&0xFF].state != ST_GAS)) + if (((int)(player2[0])&0x04) == 0x04 && ( + (pmap[(int)(player2[8]-0.5)][(int)(player2[7])]&0xFF)>=PT_NUM || + ptypes[pmap[(int)(player2[8]-0.5)][(int)(player2[7])]&0xFF].state != ST_GAS || + (pmap[(int)(player2[16]-0.5)][(int)(player2[15])]&0xFF)>=PT_NUM || + ptypes[pmap[(int)(player2[16]-0.5)][(int)(player2[15])]&0xFF].state != ST_GAS)) { if (pmap[(int)(player2[8]-0.5)][(int)(player2[7])] || pmap[(int)(player2[16]-0.5)][(int)(player2[15])]) { @@ -284,11 +290,11 @@ int update_STKM2(UPDATE_FUNC_ARGS) { for (rx = -3; rx <= 3; rx++) { r = pmap[(int)(player2[16]-2)][(int)(player2[15]+rx)]; - if (r && ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID) + if (r && ((r&0xFF)>=PT_NUM || (ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID))) player2[15] -= rx; r = pmap[(int)(player2[8]-2)][(int)(player2[7]+rx)]; - if (r && ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID) + if (r && ((r&0xFF)>=PT_NUM || (ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID))) player2[7] -= rx; } @@ -300,7 +306,7 @@ int update_STKM2(UPDATE_FUNC_ARGS) { //For left leg if (r && (r&0xFF)!=PT_STKM) { - if (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks + if ((r&0xFF)=PT_NUM || ptypes[r&0xFF].state != ST_GAS) { player2[8] += ry-1; parts[i].vy -= 0.5*parts[i].vy*dt; @@ -325,7 +331,7 @@ int update_STKM2(UPDATE_FUNC_ARGS) { //For right leg if (r && (r&0xFF)!=PT_STKM) { - if (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) + if ((r&0xFF)=PT_NUM || ptypes[r&0xFF].state != ST_GAS) { player2[16] += ry-1; parts[i].vy -= 0.5*parts[i].vy*dt; -- cgit v0.9.2-21-gd62e