Spaces:
Running
Running
Update index.html
Browse files- index.html +38 -0
index.html
CHANGED
|
@@ -309,6 +309,7 @@
|
|
| 309 |
music.currentTime = 0; // Reset to start
|
| 310 |
}
|
| 311 |
|
|
|
|
| 312 |
document.addEventListener('keydown', (event) => {
|
| 313 |
if (game && game.state === 'start') {
|
| 314 |
switch (event.key) {
|
|
@@ -331,6 +332,43 @@
|
|
| 331 |
}
|
| 332 |
});
|
| 333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
window.onload = () => {
|
| 335 |
document.getElementById('welcomeScreen').style.display = 'block';
|
| 336 |
// No need to play music on window load
|
|
|
|
| 309 |
music.currentTime = 0; // Reset to start
|
| 310 |
}
|
| 311 |
|
| 312 |
+
// Handle keyboard controls
|
| 313 |
document.addEventListener('keydown', (event) => {
|
| 314 |
if (game && game.state === 'start') {
|
| 315 |
switch (event.key) {
|
|
|
|
| 332 |
}
|
| 333 |
});
|
| 334 |
|
| 335 |
+
// Handle touch controls
|
| 336 |
+
let touchStartX = 0;
|
| 337 |
+
let touchStartY = 0;
|
| 338 |
+
|
| 339 |
+
canvas.addEventListener('touchstart', (event) => {
|
| 340 |
+
event.preventDefault();
|
| 341 |
+
touchStartX = event.touches[0].clientX;
|
| 342 |
+
touchStartY = event.touches[0].clientY;
|
| 343 |
+
});
|
| 344 |
+
|
| 345 |
+
canvas.addEventListener('touchend', (event) => {
|
| 346 |
+
event.preventDefault();
|
| 347 |
+
const touchEndX = event.changedTouches[0].clientX;
|
| 348 |
+
const touchEndY = event.changedTouches[0].clientY;
|
| 349 |
+
const dx = touchEndX - touchStartX;
|
| 350 |
+
const dy = touchEndY - touchStartY;
|
| 351 |
+
|
| 352 |
+
if (Math.abs(dx) > Math.abs(dy)) {
|
| 353 |
+
if (dx > 30) { // Swipe right
|
| 354 |
+
game.goSide(1);
|
| 355 |
+
} else if (dx < -30) { // Swipe left
|
| 356 |
+
game.goSide(-1);
|
| 357 |
+
}
|
| 358 |
+
} else {
|
| 359 |
+
if (dy > 30) { // Swipe down
|
| 360 |
+
game.goDown();
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
drawGrid();
|
| 364 |
+
drawFigure();
|
| 365 |
+
drawText();
|
| 366 |
+
});
|
| 367 |
+
|
| 368 |
+
canvas.addEventListener('touchmove', (event) => {
|
| 369 |
+
event.preventDefault();
|
| 370 |
+
});
|
| 371 |
+
|
| 372 |
window.onload = () => {
|
| 373 |
document.getElementById('welcomeScreen').style.display = 'block';
|
| 374 |
// No need to play music on window load
|