some fixes

This commit is contained in:
henry-hiles 2021-12-13 14:35:18 -05:00
parent 25b3f97fd2
commit bb3a048d15
5 changed files with 10 additions and 7 deletions

View file

@ -9,13 +9,15 @@ const setTop = ( top ) => birdElem.style.setProperty( "--bird-top", top )
const getTop = () => parseFloat( getComputedStyle( birdElem ).getPropertyValue( "--bird-top" ) )
const handleJump = ( event ) => {
if ( event.code === "Space" ) timeSinceLastJump = 0
if ( event.code === "Space" || event.type == "click") timeSinceLastJump = 0
}
export const setupBird = () => {
setTop( window.innerHeight / 2 )
document.removeEventListener( "keydown", handleJump )
document.addEventListener( "keydown", handleJump )
document.removeEventListener( "click", handleJump )
document.addEventListener( "click", handleJump )
}
export const updateBird = ( delta ) => {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Before After
Before After

View file

@ -12,10 +12,10 @@
<body>
<h1 class="title" data-title>
Press Any Key To Start
Press Any Key or Click To Start
<small data-subtitle class="subtitle"></small>
</h1>
<img data-bird src="images/bird.png" class="bird"></img>
<img data-bird src="images/bird.png" draggable="false" class="bird"></img>
</body>
</html>

View file

@ -48,8 +48,10 @@ const handleLose = () => setTimeout( () => {
}
subtitle.innerHTML = `Score: ${score}<br />Highscore: ${highscore}`
document.addEventListener( "keydown", handleStart, { once: true } )
document.addEventListener( "keypress", handleStart, { once: true } )
document.addEventListener( "click", handleStart, { once: true } )
}, 100 )
subtitle.innerHTML = `Highscore: ${parseFloat(localStorage.getItem('highscore')) || 0}`
document.addEventListener( "keypress", handleStart, { once: true } )
document.addEventListener( "click", handleStart, { once: true } )

View file

@ -3,12 +3,10 @@
*::before {
box-sizing: border-box;
}
body {
margin: 0;
background-image: url(images/background.png);
background-size: cover;
width: 100vw;
height: 100vh;
font-family: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
"Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",
@ -41,6 +39,7 @@ body {
.bird {
--bird-top: -1000;
--bird-size: 60px;
user-select: none;
position: absolute;
width: var(--bird-size);
left: var(--bird-size);