chore: small fixes 59e07d40
Steve · 2026-03-27 18:32 2 file(s) · +36 −5
src/game/DinoGame.js +19 −3
356 356
        newBird.speed = settings.birdSpeed
357 357
        newBird.wingsRate = settings.birdWingsRate
358 358
        newBird.x = this.width
359 -
        // ensure birds are always at least 5px higher than a ducking dino
360 -
        newBird.y =
359 +
        // lowest y: just above a ducking dino
360 +
        const minY =
361 361
          this.height -
362 362
          Bird.maxBirdHeight -
363 363
          Bird.wingSpriteYShift -
364 364
          5 -
365 365
          sprites.dinoDuckLeftLeg.h / 2 -
366 366
          settings.dinoGroundOffset
367 +
        // highest y: near top of canvas
368 +
        const maxY = 20
369 +
        newBird.y = randInteger(maxY, minY)
367 370
        birds.push(newBird)
368 371
      }
369 372
    }
370 -
    this.paintInstances(birds)
373 +
    this.paintBirdInstances(birds)
371 374
  }
372 375
373 376
  drawScore() {
425 428
  paintInstances(instances) {
426 429
    for (const instance of instances) {
427 430
      this.paintSprite(instance.sprite, instance.x, instance.y)
431 +
    }
432 +
  }
433 +
434 +
  paintBirdInstances(instances) {
435 +
    const { canvasCtx } = this
436 +
    for (const instance of instances) {
437 +
      const { h, w, x, y } = sprites[instance.sprite]
438 +
      const drawW = w / 2
439 +
      const drawH = h / 2
440 +
      canvasCtx.save()
441 +
      canvasCtx.scale(-1, 1)
442 +
      canvasCtx.drawImage(this.spriteImage, x, y, w, h, -(instance.x + drawW), instance.y, drawW, drawH)
443 +
      canvasCtx.restore()
428 444
    }
429 445
  }
430 446
src/index.js +17 −2
99 99
  return div.innerHTML
100 100
}
101 101
102 +
function isTopTenScore(score) {
103 +
  if (!leaderboardCache.data || !leaderboardCache.data.scores) return true
104 +
  const scores = leaderboardCache.data.scores
105 +
  if (scores.length < 10) return true
106 +
  const lowestTopScore = scores[scores.length - 1].score
107 +
  return score > lowestTopScore
108 +
}
109 +
102 110
function showOverlay(score, eventLog) {
103 111
  overlayState.visible = true
104 112
  overlayState.submitted = false
110 118
  modalTitle.textContent = 'GAME OVER'
111 119
  finalScoreDisplay.textContent = `SCORE: ${score}`
112 120
  initialsInput.value = ''
113 -
  submitSection.style.display = ''
114 121
  initialsInput.disabled = false
115 122
  submitBtn.disabled = false
116 123
  submitBtn.textContent = 'SUBMIT'
117 124
  overlay.style.display = ''
125 +
126 +
  const qualifies = isTopTenScore(score)
127 +
  submitSection.style.display = qualifies ? '' : 'none'
128 +
118 129
  updateFocusTrap()
119 -
  initialsInput.focus()
130 +
  if (qualifies) {
131 +
    initialsInput.focus()
132 +
  } else {
133 +
    actionBtn.focus()
134 +
  }
120 135
  loadLeaderboard(false) // Use cache if available
121 136
}
122 137