zeroed-some/cob / a16082e

Browse files

branch tip finally, cleaning, fixes

Authored by espadonne
SHA
a16082edc43d4090eed99abc714a09dc45b9c33b
Parents
6ebac57
Tree
3cf5805

2 changed files

StatusFile+-
M js/entities.js 40 52
M js/game.js 3 3
js/entities.jsmodified
@@ -242,76 +242,64 @@ class Spider {
242242
 
243243
     // Check home branch collision (one-way platform)
244244
     if (window.homeBranch && this.isAirborne && this.vel.y > 0.1) {
245
-      // Only when actually falling
246245
       let branch = window.homeBranch
247246
 
248
-      // Check if spider is within branch X range
249
-      let branchStart = Math.min(branch.startX, branch.endX)
250
-      let branchEnd = Math.max(branch.startX, branch.endX)
247
+      // Calculate the actual geometric bounds
248
+      let leftX = Math.min(branch.startX, branch.endX)
249
+      let rightX = Math.max(branch.startX, branch.endX)
251250
 
252
-      // FIX: Extend collision detection beyond visual tip
253
-      // The visual branch ends at branchEnd, but we need collision slightly beyond
254
-      let collisionPadding = 15 // Extra collision at the tip
251
+      // IMPORTANT: Extend the check zone beyond the mathematical end
252
+      // The branch visually extends past endX due to strokeWeight and bezier curves
253
+      let checkPadding = 20 // Add padding for the visual overhang
255254
 
256255
       if (
257
-        this.pos.x >= branchStart - 10 &&
258
-        this.pos.x <= branchEnd + collisionPadding
256
+        this.pos.x >= leftX - checkPadding &&
257
+        this.pos.x <= rightX + checkPadding
259258
       ) {
260
-        // Calculate position along branch (0 to 1)
261
-        // FIX: Clamp t to ensure we handle tip properly
262
-        let t = (this.pos.x - branchStart) / (branchEnd - branchStart)
259
+        // Calculate normalized position along branch
260
+        let t
263261
 
264
-        // Allow t to go slightly beyond 1.0 for tip collision
265
-        if (this.pos.x > branchEnd) {
266
-          t = 1.0 // At the tip, use tip thickness
262
+        if (branch.side === 'left') {
263
+          // Left branch: startX is base, endX is tip
264
+          t = (this.pos.x - branch.startX) / (branch.endX - branch.startX)
267265
         } else {
268
-          t = constrain(t, 0, 1)
266
+          // Right branch: startX is base, endX is tip (but startX > endX)
267
+          t = (branch.startX - this.pos.x) / (branch.startX - branch.endX)
269268
         }
270269
 
271
-        // Branch visual thickness tapers from full at start to 35% at end
272
-        let branchTopThickness
273
-        if (t >= 1.0) {
274
-          // At the very tip, maintain minimum collision thickness
275
-          branchTopThickness = branch.thickness * 0.35
276
-        } else {
277
-          branchTopThickness = lerp(
278
-            branch.thickness * 0.9,
279
-            branch.thickness * 0.35,
280
-            t
281
-          )
282
-        }
283
-
284
-        // The branch is drawn centered at branch.y
285
-        let branchSurfaceY = branch.y - branchTopThickness
270
+        // CRITICAL FIX: Allow t to exceed 1 for the tip overhang
271
+        // The visual branch extends past the mathematical endpoint
272
+        let maxT = 1.15 // Allow 15% overshoot for visual overhang
273
+        t = constrain(t, 0, maxT)
286274
 
287
-        // FIX: Correct angle calculation based on branch side
288
-        let angleCorrection
289
-        if (branch.side === 'right') {
290
-          // Right branch slopes down to the left (negative angle)
291
-          // Use distance from the end point (which is on the left for right branches)
292
-          angleCorrection = -(this.pos.x - branchEnd) * abs(branch.angle)
275
+        // Calculate thickness
276
+        let visualThickness
277
+        if (t > 1.0) {
278
+          // Past the mathematical end - use minimum tip thickness
279
+          visualThickness = branch.thickness * 0.35
293280
         } else {
294
-          // Left branch slopes down to the right (positive angle)
295
-          // Use distance from the start point
296
-          angleCorrection = (this.pos.x - branchStart) * abs(branch.angle)
281
+          // Normal taper
282
+          visualThickness = lerp(branch.thickness, branch.thickness * 0.35, t)
297283
         }
298
-        branchSurfaceY += angleCorrection
299284
 
300
-        // Check if spider is crossing the branch from above
301
-        let prevY = this.pos.y - this.vel.y
285
+        // The branch is drawn centered at branch.y; compute top/bottom with rotation
286
+        let rotationOffset = this.pos.x * branch.angle
287
+        let branchTopY = (branch.y - visualThickness) + rotationOffset
288
+        let branchBottomY = (branch.y + visualThickness) + rotationOffset
302289
 
303
-        // FIX: More generous collision detection at the tip
304
-        let collisionBuffer = t >= 0.9 ? 5 : 0 // Extra buffer near tip
290
+        // Check collision
291
+        let prevY = this.pos.y - this.vel.y
305292
 
293
+        // One-way platform collision
306294
         if (
307
-          prevY <= branchSurfaceY + collisionBuffer && // Was above (with buffer)
308
-          this.pos.y + this.radius >= branchSurfaceY && // Now at or below
309
-          this.pos.y < branch.y + branch.thickness
295
+          prevY <= branchTopY && // Was above
296
+          this.pos.y + this.radius >= branchTopY && // Now at or below
297
+          this.pos.y - this.radius < branchBottomY // Not completely below the rotated bottom
310298
         ) {
311
-          // Not too far below
299
+          // Not completely below
312300
 
313
-          // Place spider on the branch surface
314
-          this.pos.y = branchSurfaceY - this.radius
301
+          // Land on branch
302
+          this.pos.y = branchTopY - this.radius
315303
           this.land()
316304
           this.attachedObstacle = null
317305
         }
@@ -2199,7 +2187,7 @@ class Bird {
21992187
 
22002188
         // If spider has no stamina, GAME OVER!
22012189
         if (jumpStamina <= 0) {
2202
-          triggerGameOver('Exhausted spider caught by bird!')
2190
+          triggerGameOver('Oof')
22032191
           return
22042192
         }
22052193
 
js/game.jsmodified
@@ -477,7 +477,7 @@ function setup () {
477477
   numObstacles = constrain(numObstacles, 15, 25)
478478
 
479479
   // Create ant balloons
480
-  let numBalloons = Math.floor(random(11, 15))
480
+  let numBalloons = Math.floor(random(15, 21))
481481
   for (let i = 0; i < numBalloons; i++) {
482482
     let attempts = 0
483483
     let placed = false
@@ -520,7 +520,7 @@ function setup () {
520520
   }
521521
 
522522
   // Create beetles
523
-  let numBeetles = Math.floor(random(8, 11))
523
+  let numBeetles = Math.floor(random(9, 15))
524524
   for (let i = 0; i < numBeetles; i++) {
525525
     let attempts = 0
526526
     let placed = false
@@ -563,7 +563,7 @@ function setup () {
563563
   }
564564
 
565565
   // Create LESS leaves. they're unrealistic!
566
-  let numLeaves = Math.floor(random(4, 7))
566
+  let numLeaves = Math.floor(random(7, 9))
567567
   for (let i = 0; i < numLeaves; i++) {
568568
     let attempts = 0
569569
     let placed = false