MCPcopy Create free account
hub / github.com/Code-Bullet/Jump-King / GetPriorityCollision

Method GetPriorityCollision

Player.js:926–1116  ·  view source on GitHub ↗
(collidedLines)

Source from the content-addressed store, hash-verified

924 }
925
926 GetPriorityCollision(collidedLines) {
927
928
929 // FIRST EDGE CASES BECAUse I SUCK AT CODING
930 //ok so this is gonna need some explaining, i know there is probably a better fix but i think this will work
931 //ok so if we are going up and then we hit a verticle and a horizontal and if the midpoint of the vert is lower then
932 // we need to do the verticle one first because that should be blocking the horizontal one
933
934
935 if (collidedLines.length === 2) {
936 let vert = null
937 let horiz = null;
938 let diag = null;
939 if (collidedLines[0].isVertical) vert = collidedLines[0]
940 if (collidedLines[0].isHorizontal) horiz = collidedLines[0]
941 if (collidedLines[0].isDiagonal) diag = collidedLines[0]
942 if (collidedLines[1].isVertical) vert = collidedLines[1]
943 if (collidedLines[1].isHorizontal) horiz = collidedLines[1]
944 if (collidedLines[1].isDiagonal) diag = collidedLines[1]
945
946 if (vert != null && horiz != null) {
947 if (this.IsMovingUp()) {
948 if (vert.midPoint.y > horiz.midPoint.y) {
949 return vert;
950 } else {
951 // return horiz;
952 }
953 } else {
954 // if(vert.midPoint.y < horiz.midPoint.y ){
955 // return vert;
956 // }else{
957 // // return horiz;
958 // }
959 }
960 }
961 if (horiz != null && diag != null) {
962 // if (this.IsMovingDown()) {
963 //if the digonal one is below the horizontal then always prefer the horiz
964 if (diag.midPoint.y > horiz.midPoint.y) {
965 return horiz;
966 }
967 }
968 }
969
970
971 // check the inverse of the velocity to see if the corrections fit in the range
972 let maxAllowedXCorrection = 0 - this.currentSpeed.x;
973 let maxAllowedYCorrection = 0 - this.currentSpeed.y;
974
975
976 //if multiple collisions detected use the one that requires the least correction
977
978
979 let minCorrection = 10000;
980 let maxCorrection = 0;
981
982 let chosenLine = null;
983 if (collidedLines.length === 0) return null;

Callers 1

CheckCollisionsMethod · 0.95

Calls 3

IsMovingUpMethod · 0.95
IsMovingDownMethod · 0.95
IsMovingRightMethod · 0.95

Tested by

no test coverage detected