@@ -71,27 +71,56 @@ class Spider { |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | + // Check ground collision |
| 74 | 75 | if (this.pos.y >= height - this.radius) { |
| 75 | 76 | this.pos.y = height - this.radius; |
| 76 | 77 | this.land(); |
| 77 | 78 | } |
| 78 | 79 | |
| 80 | + // Check wall collisions |
| 79 | 81 | if (this.pos.x <= this.radius || this.pos.x >= width - this.radius) { |
| 80 | 82 | this.pos.x = constrain(this.pos.x, this.radius, width - this.radius); |
| 81 | 83 | this.vel.x *= -0.5; |
| 82 | 84 | } |
| 83 | 85 | |
| 86 | + // Check ceiling |
| 84 | 87 | if (this.pos.y <= this.radius) { |
| 85 | 88 | this.pos.y = this.radius; |
| 86 | 89 | this.vel.y *= -0.5; |
| 87 | 90 | } |
| 88 | 91 | |
| 92 | + // Check home branch collision (one-way platform) |
| 93 | + if (window.homeBranch && this.vel.y > 0) { // Only when falling |
| 94 | + let branch = window.homeBranch; |
| 95 | + // Collision should be right at the visual surface |
| 96 | + let branchTop = branch.y - 5; // Much closer to actual visual surface |
| 97 | + |
| 98 | + // Check if spider is within branch X range |
| 99 | + let inXRange = false; |
| 100 | + if (branch.side === 'left') { |
| 101 | + inXRange = this.pos.x >= 0 && this.pos.x <= branch.endX + 20; |
| 102 | + } else { |
| 103 | + inXRange = this.pos.x >= branch.endX - 20 && this.pos.x <= width; |
| 104 | + } |
| 105 | + |
| 106 | + // One-way collision: only collide when falling from above |
| 107 | + if (inXRange && |
| 108 | + this.pos.y - this.radius <= branchTop && |
| 109 | + this.pos.y + this.radius >= branchTop && |
| 110 | + this.pos.y - this.radius < branchTop) { |
| 111 | + this.pos.y = branchTop - this.radius; |
| 112 | + this.land(); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + // Check obstacle collisions |
| 89 | 117 | for (let obstacle of obstacles) { |
| 90 | 118 | if (this.checkObstacleCollision(obstacle)) { |
| 91 | 119 | this.landOnObstacle(obstacle); |
| 92 | 120 | } |
| 93 | 121 | } |
| 94 | 122 | |
| 123 | + // Check web strand collisions |
| 95 | 124 | for (let strand of webStrands) { |
| 96 | 125 | if (strand === currentStrand) continue; |
| 97 | 126 | |
@@ -100,6 +129,7 @@ class Spider { |
| 100 | 129 | } |
| 101 | 130 | } |
| 102 | 131 | |
| 132 | + // Check food box collisions |
| 103 | 133 | for (let i = foodBoxes.length - 1; i >= 0; i--) { |
| 104 | 134 | let box = foodBoxes[i]; |
| 105 | 135 | if (dist(this.pos.x, this.pos.y, box.pos.x, box.pos.y) < this.radius + box.radius) { |