(l)
| 712 | // this is done by taking the collision of the 4 lines that make up the hitbox |
| 713 | |
| 714 | IsCollidingWithLine(l) { |
| 715 | if (l.isHorizontal) { |
| 716 | var isRectWithinLineX = (l.x1 < this.currentPos.x && this.currentPos.x < l.x2) || (l.x1 < this.currentPos.x + this.width && this.currentPos.x + this.width < l.x2) || (this.currentPos.x < l.x1 && l.x1 < this.currentPos.x + this.width) || (this.currentPos.x < l.x2 && l.x2 < this.currentPos.x + this.width); |
| 717 | var isRectWithinLineY = this.currentPos.y < l.y1 && l.y1 < this.currentPos.y + this.height; |
| 718 | // if (isRectWithinLineX && isRectWithinLineY) { |
| 719 | // print(this.currentPos.x, l.x1, l.x2) |
| 720 | // print(isRectWithinLineX, isRectWithinLineY) |
| 721 | // } |
| 722 | return isRectWithinLineX && isRectWithinLineY; |
| 723 | } else if (l.isVertical) { |
| 724 | isRectWithinLineY = (l.y1 < this.currentPos.y && this.currentPos.y < l.y2) || (l.y1 < this.currentPos.y + this.height && this.currentPos.y + this.height < l.y2) || (this.currentPos.y < l.y1 && l.y1 < this.currentPos.y + this.height) || (this.currentPos.y < l.y2 && l.y2 < this.currentPos.y + this.height); |
| 725 | isRectWithinLineX = this.currentPos.x < l.x1 && l.x1 < this.currentPos.x + this.width; |
| 726 | // if (isRectWithinLineX && isRectWithinLineY) { |
| 727 | // print(this.currentPos.x, l.x1, l.x2) |
| 728 | // print(isRectWithinLineX, isRectWithinLineY) |
| 729 | // } |
| 730 | return isRectWithinLineX && isRectWithinLineY; |
| 731 | } else { |
| 732 | // ok so we need to check each side of the |
| 733 | // wait i just realized there is no way that only the l or r side is touching the digonal |
| 734 | //wait there might be hold on |
| 735 | // ok jsut check all of them |
| 736 | |
| 737 | let tl = this.currentPos.copy(); |
| 738 | let tr = tl.copy(); |
| 739 | tr.x += this.width; |
| 740 | let bl = tl.copy(); |
| 741 | bl.y += this.height - 1; |
| 742 | let br = bl.copy(); |
| 743 | br.x += this.width; |
| 744 | |
| 745 | let leftCollision = AreLinesColliding(tl.x, tl.y, bl.x, bl.y, l.x1, l.y1, l.x2, l.y2); |
| 746 | let rightCollision = AreLinesColliding(tr.x, tr.y, br.x, br.y, l.x1, l.y1, l.x2, l.y2); |
| 747 | let topCollision = AreLinesColliding(tl.x, tl.y, tr.x, tr.y, l.x1, l.y1, l.x2, l.y2); |
| 748 | let bottomCollision = AreLinesColliding(bl.x, bl.y, br.x, br.y, l.x1, l.y1, l.x2, l.y2); |
| 749 | |
| 750 | if (leftCollision[0] || rightCollision[0] || topCollision[0] || bottomCollision[0]) { |
| 751 | let collisionInfo = new DiagonalCollisionInfo(); |
| 752 | collisionInfo.leftSideOfPlayerCollided = leftCollision[0] |
| 753 | collisionInfo.rightSideOfPlayerCollided = rightCollision[0]; |
| 754 | collisionInfo.topSideOfPlayerCollided = topCollision[0]; |
| 755 | collisionInfo.bottomSideOfPlayerCollided = bottomCollision[0]; |
| 756 | |
| 757 | if (leftCollision[0]) |
| 758 | collisionInfo.collisionPoints.push(createVector(leftCollision[1], leftCollision[2])) |
| 759 | if (rightCollision[0]) |
| 760 | collisionInfo.collisionPoints.push(createVector(rightCollision[1], rightCollision[2])) |
| 761 | if (topCollision[0]) |
| 762 | collisionInfo.collisionPoints.push(createVector(topCollision[1], topCollision[2])) |
| 763 | if (bottomCollision[0]) |
| 764 | collisionInfo.collisionPoints.push(createVector(bottomCollision[1], bottomCollision[2])) |
| 765 | |
| 766 | l.diagonalCollisionInfo = collisionInfo; |
| 767 | return true; |
| 768 | } else { |
| 769 | return false; |
| 770 | } |
| 771 |
no test coverage detected