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

De-duplicate vertical moving platform fix for player/SCM

Instead of having two separate functions to move entities along vertical
moving platforms, one for the player and one for the supercrewmate, they
have been consolidated into one function.
This commit is contained in:
Misa 2020-09-05 17:25:49 -07:00 committed by Ethan Lee
parent 1c5b72410a
commit ceaee392e5
3 changed files with 8 additions and 55 deletions

View File

@ -4497,17 +4497,16 @@ void entityclass::entitymapcollision( int t )
}
}
void entityclass::movingplatformfix( int t )
void entityclass::movingplatformfix( int t, int j )
{
if (t < 0 || t >= (int) entities.size())
if (!INBOUNDS(t, entities) || !INBOUNDS(j, entities))
{
puts("movingplatformfix() out-of-bounds!");
return;
}
//If this intersects the player, then we move the player along it
int j = getplayer();
if (j > -1 && entitycollide(t, j))
//If this intersects the entity, then we move them along it
if (entitycollide(t, j))
{
//ok, bollox, let's make sure
entities[j].yp = entities[j].yp + int(entities[j].vy);
@ -4518,7 +4517,7 @@ void entityclass::movingplatformfix( int t )
entities[j].newyp = entities[j].yp + int(entities[j].vy);
if (testwallsy(j, entities[j].xp, entities[j].newyp))
{
if (entities[t].vy > 0)
if (entities[t].vy > 0)
{
entities[j].yp = entities[t].yp + entities[t].h;
entities[j].vy = 0;
@ -4539,46 +4538,6 @@ void entityclass::movingplatformfix( int t )
}
}
void entityclass::scmmovingplatformfix( int t )
{
if (t < 0 || t >= (int) entities.size())
{
puts("scmmovingplatformfix() out-of-bounds!");
return;
}
//If this intersects the SuperCrewMate, then we move them along it
int j = getscm();
if (entitycollide(t, j))
{
//ok, bollox, let's make sure
entities[j].yp = entities[j].yp + (entities[j].vy);
if (entitycollide(t, j))
{
entities[j].yp = entities[j].yp - (entities[j].vy);
entities[j].vy = entities[t].vy;
entities[j].newyp = static_cast<float>(entities[j].yp) + entities[j].vy;
if (testwallsy(j, entities[j].xp, entities[j].newyp))
{
if (entities[t].vy > 0)
{
entities[j].yp = entities[t].yp + entities[t].h;
entities[j].vy = 0;
}
else
{
entities[j].yp = entities[t].yp - entities[j].h-entities[j].cy;
entities[j].vy = 0;
}
}
else
{
entities[t].state = entities[t].onwall;
}
}
}
}
void entityclass::hormovingplatformfix( int t )
{
if (t < 0 || t >= (int) entities.size())

View File

@ -152,9 +152,7 @@ public:
void entitymapcollision(int t);
void movingplatformfix(int t);
void scmmovingplatformfix(int t);
void movingplatformfix(int t, int j);
void hormovingplatformfix(int t);

View File

@ -892,14 +892,10 @@ void gamelogic()
obj.entitymapcollision(i); // Collisions with walls
obj.createblock(0, obj.entities[i].xp, obj.entities[i].yp, obj.entities[i].w, obj.entities[i].h);
obj.movingplatformfix(i, obj.getplayer());
if (game.supercrewmate)
{
obj.movingplatformfix(i);
obj.scmmovingplatformfix(i);
}
else
{
obj.movingplatformfix(i);
obj.movingplatformfix(i, obj.getscm());
}
}
}