1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 06:28:30 +02:00

De-duplicate stuck prevention for the player/SCM

Stuck prevention (pushing the player/supercrewmate out if they are
inside a wall) has been factored out into its own function, so it's no
longer copy-pasted but slightly tweaked just for the supercrewmate.
This commit is contained in:
Misa 2020-09-05 17:38:38 -07:00 committed by Ethan Lee
parent 5e29d676e9
commit fae14f4e98
2 changed files with 29 additions and 33 deletions

View File

@ -4603,43 +4603,12 @@ void entityclass::entitycollisioncheck()
}
//can't have the player being stuck...
int j = getplayer();
skipdirblocks = true;
if (j > -1 && !testwallsx(j, entities[j].xp, entities[j].yp))
{
//Let's try to get out...
if (entities[j].rule == 0)
{
if(game.gravitycontrol==0)
{
entities[j].yp -= 3;
}
else
{
entities[j].yp += 3;
}
}
}
skipdirblocks = false;
stuckprevention(getplayer());
//Can't have the supercrewmate getting stuck either!
if (game.supercrewmate)
{
j = getscm();
skipdirblocks = true;
if (!testwallsx(j, entities[j].xp, entities[j].yp))
{
//Let's try to get out...
if(game.gravitycontrol==0)
{
entities[j].yp -= 3;
}
else
{
entities[j].yp += 3;
}
}
skipdirblocks = false;
stuckprevention(getscm());
}
//Is the player colliding with any damageblocks?
@ -4802,3 +4771,28 @@ void entityclass::collisioncheck(int i, int j, bool scm /*= false*/)
break;
}
}
void entityclass::stuckprevention(int t)
{
if (!INBOUNDS(t, entities))
{
puts("stuckprevention() out-of-bounds!");
return;
}
skipdirblocks = true;
// Can't have this entity (player or supercrewmate) being stuck...
if (!testwallsx(t, entities[t].xp, entities[t].yp))
{
// Let's try to get out...
if (game.gravitycontrol == 0)
{
entities[t].yp -= 3;
}
else
{
entities[t].yp += 3;
}
}
skipdirblocks = false;
}

View File

@ -160,6 +160,8 @@ public:
void collisioncheck(int i, int j, bool scm = false);
void stuckprevention(int t);
std::vector<entclass> entities;