zeroed-some/cob / 0d3f103

Browse files

fix one way collision

Authored by espadonne
SHA
0d3f103070aebb294d9c21a436574149cb2f7b98
Parents
c0b541e
Tree
55de2ee

1 changed file

StatusFile+-
M js/entities.js 30 0
js/entities.jsmodified
@@ -71,27 +71,56 @@ class Spider {
7171
             }
7272
         }
7373
 
74
+        // Check ground collision
7475
         if (this.pos.y >= height - this.radius) {
7576
             this.pos.y = height - this.radius;
7677
             this.land();
7778
         }
7879
 
80
+        // Check wall collisions
7981
         if (this.pos.x <= this.radius || this.pos.x >= width - this.radius) {
8082
             this.pos.x = constrain(this.pos.x, this.radius, width - this.radius);
8183
             this.vel.x *= -0.5;
8284
         }
8385
 
86
+        // Check ceiling
8487
         if (this.pos.y <= this.radius) {
8588
             this.pos.y = this.radius;
8689
             this.vel.y *= -0.5;
8790
         }
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
+        }
88115
 
116
+        // Check obstacle collisions
89117
         for (let obstacle of obstacles) {
90118
             if (this.checkObstacleCollision(obstacle)) {
91119
                 this.landOnObstacle(obstacle);
92120
             }
93121
         }
94122
 
123
+        // Check web strand collisions
95124
         for (let strand of webStrands) {
96125
             if (strand === currentStrand) continue;
97126
             
@@ -100,6 +129,7 @@ class Spider {
100129
             }
101130
         }
102131
         
132
+        // Check food box collisions
103133
         for (let i = foodBoxes.length - 1; i >= 0; i--) {
104134
             let box = foodBoxes[i];
105135
             if (dist(this.pos.x, this.pos.y, box.pos.x, box.pos.y) < this.radius + box.radius) {