New stick mans collisions code.
This commit is contained in:
parent
11843a8ee0
commit
c37f3b1eba
@ -86,97 +86,58 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) {
|
||||
playerp[26] = 0;
|
||||
|
||||
//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 (playerp[7]>playerp[15])
|
||||
{
|
||||
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[19] = -1;
|
||||
playerp[22] = -3;
|
||||
}
|
||||
}
|
||||
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[25] = -3;
|
||||
playerp[19] = -1;
|
||||
}
|
||||
|
||||
if (pmap[(int)(playerp[16]-1)][(int)(playerp[15])])
|
||||
{
|
||||
playerp[25] = -1;
|
||||
playerp[26] = -1;
|
||||
playerp[23] = -1;
|
||||
playerp[26] = -3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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 (playerp[7]<playerp[15])
|
||||
{
|
||||
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[19] = 1;
|
||||
playerp[22] = -3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pmap[(int)(playerp[8]-1)][(int)(playerp[7])])
|
||||
if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL))
|
||||
{
|
||||
playerp[21] = 1;
|
||||
playerp[22] = -1;
|
||||
playerp[25] = 3;
|
||||
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
|
||||
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 = -5;
|
||||
playerp[22] -= 1;
|
||||
playerp[26] -= 1;
|
||||
}
|
||||
|
||||
//Charge detector wall if foot inside
|
||||
@ -290,78 +251,31 @@ 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;
|
||||
|
||||
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;
|
||||
playerp[7] = playerp[9];
|
||||
playerp[8] = playerp[10];
|
||||
}
|
||||
|
||||
//Collision checks
|
||||
for (ry = -2-(int)parts[i].vy; ry<=0; ry++)
|
||||
if (!eval_move(PT_DUST, playerp[15], playerp[16], NULL))
|
||||
{
|
||||
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)];
|
||||
|
||||
//For right leg
|
||||
if (r && (r&0xFF)!=PT_STKM)
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
//If it falls too fast
|
||||
if (parts[i].vy>=30)
|
||||
{
|
||||
parts[i].y -= (10+ry)*dt;
|
||||
parts[i].vy = -10*dt;
|
||||
}
|
||||
//This makes stick man "pop" from obstacles
|
||||
if (!eval_move(PT_DUST, playerp[7], playerp[8], NULL))
|
||||
{
|
||||
float t;
|
||||
t = playerp[7]; playerp[7] = playerp[9]; playerp[9] = t;
|
||||
t = playerp[8]; playerp[8] = playerp[10]; playerp[10] = t;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//Keeping legs distance
|
||||
|
Loading…
Reference in New Issue
Block a user