zeroed-some/cob / 59d53dc

Browse files

divebomb fixes, cleanup

Authored by espadonne
SHA
59d53dce1295ab8c9e7487fc59aaf242e451873e
Parents
aa1f028
Tree
0180dd3

1 changed file

StatusFile+-
M js/entities.js 27 10
js/entities.jsmodified
@@ -1242,7 +1242,6 @@ class Obstacle {
12421242
 
12431243
       pop()
12441244
     } else if (this.type === 'beetle') {
1245
-      // Big floating beetle! (KEEP EXISTING CODE)
12461245
       push()
12471246
       rotate(this.rotation)
12481247
 
@@ -1365,7 +1364,6 @@ class Obstacle {
13651364
 
13661365
       pop()
13671366
     } else if (this.type === 'leaf') {
1368
-      // Original leaf code (KEEP EXISTING)
13691367
       rotate(this.rotation)
13701368
 
13711369
       if (gamePhase === 'NIGHT') {
@@ -1599,10 +1597,18 @@ class Bird {
15991597
       if (abs(dx) < 50 && abs(dy) < 30) {
16001598
         this.state = 'attacking'
16011599
         this.attacking = true
1600
+        // Initialize diveFrames and pullUpY for new attack
1601
+        this.diveFrames = 0
1602
+        // Calculate pullUpY: spider.pos.y + spider.radius + 8, but not below canvas
1603
+        let candidatePullUpY = spider.pos.y + spider.radius + 8
1604
+        this.pullUpY = Math.min(candidatePullUpY, height - 12)
16021605
         this.updateTarget()
16031606
       }
16041607
     } else if (this.state === 'attacking') {
1605
-      // FIX: Better tracking dive that reaches bottom
1608
+      // Track how many frames we've been attacking
1609
+      if (typeof this.diveFrames !== 'number') this.diveFrames = 0
1610
+      this.diveFrames++
1611
+
16061612
       let dx = this.targetX - this.x
16071613
       let dy = this.targetY - this.y
16081614
 
@@ -1619,16 +1625,15 @@ class Bird {
16191625
         this.targetY = spider.pos.y
16201626
       }
16211627
 
1622
-      // FIX: Extend dive range to reach bottom spiders
1623
-      // Check if we've reached the target OR the absolute bottom
1624
-      let reachedTarget = this.y > this.targetY - 10
1628
+      // Only consider bailing out after a minimum number of dive frames
1629
+      let canBailOut = this.diveFrames > 15
1630
+      // Use pullUpY for stable bailout check
1631
+      let reachedPullUpY = (typeof this.pullUpY === 'number') ? (this.y > this.pullUpY) : false
16251632
       let reachedBottom = this.y > height - 20 // Go almost to canvas bottom
1626
-
1627
-      // FIX: Also check if we're very close horizontally for bottom edge spiders
16281633
       let closeToSpider = dist(this.x, this.y, spider.pos.x, spider.pos.y) < 50
16291634
 
1630
-      if (reachedTarget || reachedBottom || closeToSpider) {
1631
-        // FIX: If spider is at bottom and we haven't hit it yet, do a horizontal sweep
1635
+      if (canBailOut && (reachedPullUpY || reachedBottom || closeToSpider)) {
1636
+        // If spider is at bottom and we haven't hit it yet, do a horizontal sweep
16321637
         if (spider.pos.y > height - 30 && !closeToSpider && !this.sweeping) {
16331638
           this.sweeping = true
16341639
           this.y = spider.pos.y // Match spider height
@@ -1643,6 +1648,8 @@ class Bird {
16431648
             this.sweeping = false
16441649
             this.state = 'retreating'
16451650
             this.attacking = false
1651
+            this.diveFrames = 0
1652
+            this.pullUpY = null
16461653
           }, 500) // Sweep for 0.5 seconds
16471654
         } else if (!this.sweeping) {
16481655
           // Normal attack completion
@@ -1653,11 +1660,15 @@ class Bird {
16531660
             this.state = 'approaching'
16541661
             this.attacking = false
16551662
             this.y = min(this.y, height - 50)
1663
+            this.diveFrames = 0
1664
+            this.pullUpY = null
16561665
             this.updateTarget()
16571666
           } else {
16581667
             // Finally retreat
16591668
             this.state = 'retreating'
16601669
             this.attacking = false
1670
+            this.diveFrames = 0
1671
+            this.pullUpY = null
16611672
           }
16621673
         }
16631674
       }
@@ -1668,11 +1679,15 @@ class Bird {
16681679
         if (!this.sweeping) {
16691680
           this.state = 'retreating'
16701681
           this.attacking = false
1682
+          this.diveFrames = 0
1683
+          this.pullUpY = null
16711684
         }
16721685
       }
16731686
     } else if (this.state === 'retreating') {
16741687
       // Clear sweep flag
16751688
       this.sweeping = false
1689
+      this.diveFrames = 0
1690
+      this.pullUpY = null
16761691
 
16771692
       // Fly back up
16781693
       this.vy = -this.retreatSpeed
@@ -1686,6 +1701,8 @@ class Bird {
16861701
         this.x = random(width)
16871702
         this.consecutiveAttacks = 0
16881703
         this.maxConsecutiveAttacks = random(2, 4)
1704
+        this.diveFrames = 0
1705
+        this.pullUpY = null
16891706
       }
16901707
     }
16911708
   }