game: draw hints

This commit is contained in:
He4eT 2025-06-11 03:48:23 +02:00
commit dd0e24288c

25
game.js
View file

@ -497,6 +497,25 @@ function drawLetters() {
rect(screenPos.x - 7, screenPos.y - 7, 16, 16, 4) rect(screenPos.x - 7, screenPos.y - 7, 16, 16, 4)
rectb(screenPos.x - 7, screenPos.y - 7, 16, 16, 3) rectb(screenPos.x - 7, screenPos.y - 7, 16, 16, 3)
print(enemy.letter, screenPos.x - 4, screenPos.y - 4, 2, false, 2) print(enemy.letter, screenPos.x - 4, screenPos.y - 4, 2, false, 2)
drawHint(enemy.letter, screenPos.x - 7, screenPos.y + 9)
})
}
function drawHint(letter, x, y) {
const code = letterToMorse[letter].split('')
const l = code.reduce((acc, c) => acc + (c === '-' ? 4 : 2), 0)
let offset = x + (8 - Math.floor((l - 1) / 2)) - 1
rect(x, y, 16, 2, 3)
code.forEach((c) => {
if (c === '-') {
rect(offset, y, 3, 1, 2)
offset += 4
} else {
rect(offset, y, 1, 1, 2)
offset += 2
}
}) })
} }
@ -584,10 +603,10 @@ function getDirection(from, to) {
} }
} }
function arenaToScreen ({ x, y }) { function arenaToScreen({ x, y }) {
return { return {
x: x + arena.screenPosition.x, x: Math.floor(x + arena.screenPosition.x),
y: y + arena.screenPosition.y, y: Math.floor(y + arena.screenPosition.y),
} }
} }