diff options
author | elioat <hi@eli.li> | 2023-12-31 21:20:19 -0500 |
---|---|---|
committer | elioat <hi@eli.li> | 2023-12-31 21:20:19 -0500 |
commit | 98378acd20c2c3291e21a2cb467dd07117547a9e (patch) | |
tree | 24eef7eff1aee41c43f15479c1cff5595ba23f12 /js/hill | |
parent | f168c43e18645e1811e9bfa0b7704f8e01b164c7 (diff) | |
download | tour-98378acd20c2c3291e21a2cb467dd07117547a9e.tar.gz |
*
Diffstat (limited to 'js/hill')
-rw-r--r-- | js/hill/game.js | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/js/hill/game.js b/js/hill/game.js index 2dc0716..b9c2e14 100644 --- a/js/hill/game.js +++ b/js/hill/game.js @@ -91,12 +91,12 @@ const initialize = () => { const drawPlayer = () => { - /* - ctx.fillStyle = 'lightgrey'; - ctx.font = '22px Arial'; - const text = `vx: ${player.vx.toFixed(2)}, vy: ${player.vy.toFixed(2)}`; - ctx.fillText(text, player.x, player.y - 12); - */ + if (player.vx < 4) { + ctx.fillStyle = COLORS.player; + ctx.font = '22px Arial'; + const text = 'Jump to build up speed!'; + ctx.fillText(text, player.x, player.y - 12); + } ctx.fillStyle = COLORS.player; ctx.fillRect(player.x, player.y, player.width, player.height); @@ -205,12 +205,6 @@ const gameLoop = () => { gameLoop(); -window.addEventListener('resize', () => { - canvas.width = window.innerWidth; - canvas.height = window.innerHeight; - draw(); -}); - const playerDoJump = () => { const terrainY = (terrain.end.y - terrain.start.y) / (terrain.end.x - terrain.start.x) * (player.x - terrain.start.x) + terrain.start.y; if (player.y + player.height >= terrainY) { @@ -230,3 +224,35 @@ const handleKeyDown = event => { canvas.addEventListener('click', playerDoJump); canvas.addEventListener('touchstart', playerDoJump); window.addEventListener('keydown', handleKeyDown); + +window.addEventListener('resize', () => { + canvas.width = window.innerWidth; + canvas.height = window.innerHeight; + draw(); +}); + +document.addEventListener('keydown', function(event) { + if (event.key === 'f') { + if (canvas.requestFullscreen) { + canvas.requestFullscreen(); + } else if (canvas.mozRequestFullScreen) { + canvas.mozRequestFullScreen(); + } else if (canvas.webkitRequestFullscreen) { + canvas.webkitRequestFullscreen(); + } else if (canvas.msRequestFullscreen) { + canvas.msRequestFullscreen(); + } + } +}); + +canvas.addEventListener('touchstart', function(event) { + if (canvas.requestFullscreen) { + canvas.requestFullscreen(); + } else if (canvas.mozRequestFullScreen) { + canvas.mozRequestFullScreen(); + } else if (canvas.webkitRequestFullscreen) { + canvas.webkitRequestFullscreen(); + } else if (canvas.msRequestFullscreen) { + canvas.msRequestFullscreen(); + } +}); |