New stick mans collisions code.

This commit is contained in:
savask 2011-07-27 16:38:42 +07:00
parent 11843a8ee0
commit c37f3b1eba

View File

@ -86,98 +86,59 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) {
playerp[26] = 0; playerp[26] = 0;
//Go left //Go left
r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]; if (((int)(playerp[0])&0x01) == 0x01)
if (((int)(playerp[0])&0x01) == 0x01 && (((r&0xFF)>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS))
{ {
if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID if (playerp[7]>playerp[15])
&& (r&0xFF) != PT_LNTG))
{ {
if (pmap[(int)(playerp[8]-1)][(int)(playerp[7])]) if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL))
{ {
playerp[21] = -3; playerp[21] = -3;
playerp[22] = -2; playerp[19] = -1;
playerp[19] = -2; playerp[22] = -3;
}
if (pmap[(int)(playerp[16]-1)][(int)(playerp[15])])
{
playerp[25] = -3;
playerp[26] = -2;
playerp[23] = -2;
} }
} }
else 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[25] = -3;
playerp[22] = -1;
playerp[19] = -1; playerp[19] = -1;
} playerp[26] = -3;
if (pmap[(int)(playerp[16]-1)][(int)(playerp[15])])
{
playerp[25] = -1;
playerp[26] = -1;
playerp[23] = -1;
} }
} }
} }
//Go right //Go right
r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]; if (((int)(playerp[0])&0x02) == 0x02)
if (((int)(playerp[0])&0x02) == 0x02 && (((r&0xFF)>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS))
{ {
if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID if (playerp[7]<playerp[15])
&& (r&0xFF) != PT_LNTG))
{ {
if (pmap[(int)(playerp[8]-1)][(int)(playerp[7])]) if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL))
{ {
playerp[21] = 3; playerp[21] = 3;
playerp[22] = -2; playerp[19] = 1;
playerp[19] = 2; playerp[22] = -3;
}
if (pmap[(int)(playerp[16]-1)][(int)(playerp[15])])
{
playerp[25] = 3;
playerp[26] = -2;
playerp[23] = 2;
} }
} }
else else
{ {
if (pmap[(int)(playerp[8]-1)][(int)(playerp[7])]) if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL))
{ {
playerp[21] = 1; playerp[25] = 3;
playerp[22] = -1;
playerp[19] = 1; playerp[19] = 1;
playerp[26] = -3;
} }
if (pmap[(int)(playerp[16]-1)][(int)(playerp[15])])
{
playerp[25] = 1;
playerp[26] = -1;
playerp[23] = 1;
}
} }
} }
//Jump //Jump
if (((int)(playerp[0])&0x04) == 0x04 && ( if (((int)(playerp[0])&0x04) == 0x04 &&
(pmap[(int)(playerp[8]-0.5)][(int)(playerp[7])]&0xFF)>=PT_NUM || (!eval_move(PT_DUST, playerp[7], playerp[8], NULL) || !eval_move(PT_DUST, playerp[15], playerp[16], NULL)))
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 (pmap[(int)(playerp[8]-0.5)][(int)(playerp[7])] || pmap[(int)(playerp[16]-0.5)][(int)(playerp[15])])
{ {
parts[i].vy = -5; parts[i].vy = -5;
playerp[22] -= 1; playerp[22] -= 1;
playerp[26] -= 1; playerp[26] -= 1;
} }
}
//Charge detector wall if foot inside //Charge detector wall if foot inside
if (bmap[(int)(playerp[8]+0.5)/CELL][(int)(playerp[7]+0.5)/CELL]==WL_DETECT) if (bmap[(int)(playerp[8]+0.5)/CELL][(int)(playerp[7]+0.5)/CELL]==WL_DETECT)
@ -290,78 +251,31 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) {
playerp[11] += (playerp[11]-parts[i].x)*d; playerp[11] += (playerp[11]-parts[i].x)*d;
playerp[12] += (playerp[12]-parts[i].y)*d; playerp[12] += (playerp[12]-parts[i].y)*d;
//Side collisions checking if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL))
for (rx = -3; rx <= 3; rx++)
{ {
r = pmap[(int)(playerp[16]-2)][(int)(playerp[15]+rx)]; playerp[7] = playerp[9];
if (r && ((r&0xFF)>=PT_NUM || (ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID))) playerp[8] = playerp[10];
playerp[15] -= rx;
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;
} }
//Collision checks if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL))
for (ry = -2-(int)parts[i].vy; ry<=0; ry++)
{ {
r = pmap[(int)(playerp[8]+ry)][(int)(playerp[7]+0.5)]; //This is to make coding more pleasant :-) playerp[15] = playerp[17];
playerp[16] = playerp[18];
//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];
} }
r = pmap[(int)(playerp[16]+ry)][(int)(playerp[15]+0.5)]; //This makes stick man "pop" from obstacles
if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL))
//For right leg
if (r && (r&0xFF)!=PT_STKM)
{ {
if ((r&0xFF)<PT_NUM && (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG)) float t;
{ t = playerp[7]; playerp[7] = playerp[9]; playerp[9] = t;
if (parts[i].y<(playerp[16]-10)) t = playerp[8]; playerp[8] = playerp[10]; playerp[10] = t;
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];
} }
//If it falls too fast if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL))
if (parts[i].vy>=30)
{ {
parts[i].y -= (10+ry)*dt; float t;
parts[i].vy = -10*dt; t = playerp[15]; playerp[15] = playerp[17]; playerp[17] = t;
} t = playerp[16]; playerp[16] = playerp[18]; playerp[18] = t;
} }
//Keeping legs distance //Keeping legs distance