Skip to content

Commit

Permalink
main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed-Ramzan authored Aug 28, 2023
1 parent 86fec2a commit 5476eb6
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Block Down Game/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,30 @@ document.addEventListener('keydown', (event) => {
moveLeft()
}
else if (event.key == "ArrowRight") moveRight();
})
})

let touchStartX = 0;
let touchEndX = 0;

document.addEventListener('touchstart', (event) => {
touchStartX = event.touches[0].clientX;
touchEndX = touchStartX; // Initialize touchEndX to the same value as touchStartX
});

document.addEventListener('touchmove', (event) => {
touchEndX = event.touches[0].clientX;
});

document.addEventListener('touchend', () => {
const swipeDistance = touchEndX - touchStartX;
if (swipeDistance > 50) {
moveRight(); // Handle right swipe
} else if (swipeDistance < -50) {
moveLeft(); // Handle left swipe
}
});



block.addEventListener('animationiteration', () => {
const randPos = Math.floor((Math.random() * 3)) * 100;
Expand Down

0 comments on commit 5476eb6

Please sign in to comment.