From ceaee392e547283b722bd3365b3d3f5a00388580 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 5 Sep 2020 17:25:49 -0700 Subject: [PATCH] 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. --- desktop_version/src/Entity.cpp | 51 ++++------------------------------ desktop_version/src/Entity.h | 4 +-- desktop_version/src/Logic.cpp | 8 ++---- 3 files changed, 8 insertions(+), 55 deletions(-) diff --git a/desktop_version/src/Entity.cpp b/desktop_version/src/Entity.cpp index ff45c43b..b2137555 100644 --- a/desktop_version/src/Entity.cpp +++ b/desktop_version/src/Entity.cpp @@ -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(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()) diff --git a/desktop_version/src/Entity.h b/desktop_version/src/Entity.h index 5930f68e..9119ce78 100644 --- a/desktop_version/src/Entity.h +++ b/desktop_version/src/Entity.h @@ -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); diff --git a/desktop_version/src/Logic.cpp b/desktop_version/src/Logic.cpp index f6a5e6d5..19fa0256 100644 --- a/desktop_version/src/Logic.cpp +++ b/desktop_version/src/Logic.cpp @@ -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()); } } }