Atölye › Scorched Earth Tarzı Topçu › 13/23. adım
Patlamanın içindeki tank can kaybetsin: tam üstüne düşerse 60, uzaklaştıkça daha az, kenarda hiç. Her tankın üstünde 30'un altında kırmızıya dönen bir can çubuğu olsun.
```js
for (const t of tanks) {
const d = Math.hypot(t.x - x, t.y - 6 - y)
if (d < BLAST) t.hp = Math.max(0, Math.round(t.hp - (1 - d / BLAST) * 60))
}
// Health bar
ctx.fillStyle = '#0f172a'
ctx.fillRect(t.x - 16, t.y - 22, 32, 4)
ctx.fillStyle = t.hp > 30 ? '#22c55e' : '#ef4444'
ctx.fillRect(t.x - 16, t.y - 22, (32 * t.hp) / 100, 4)
```Math.hypot(t.x - x, t.y - 6 - y) → patlamadan tankın ortasına (altından 6 piksel yukarı) uzaklık.(1 - d / BLAST) * 60 → ortada 60, kenarda 0: hasar uzaklıkla azalır.Math.max(0, Math.round(...)) → can tam sayı kalsın ve 0'ın altına inmesin.explode'da kazma döngüsünün altına hasar döngüsünü yaz.draw'ın tank döngüsünde ctx.stroke() satırının altına can çubuğu satırlarını yaz. Çalıştır.Beceriler: Çarpışma tespiti, Oyun durumları