Actually working swipe controls for pacman game

This commit is contained in:
Tyler
2025-05-01 21:49:06 -10:00
committed by GitHub
parent 1c1fed1dd5
commit 61193320d4
7 changed files with 1508 additions and 1394 deletions
+5
View File
@@ -464,6 +464,8 @@ def restart_server():
restart_script = f""" restart_script = f"""
@echo off @echo off
timeout /t 2 /nobreak timeout /t 2 /nobreak
taskkill /F /PID {current_pid}
set PRODUCTION=true
start "" "python" "app.py" start "" "python" "app.py"
""" """
with open("restart.bat", "w") as f: with open("restart.bat", "w") as f:
@@ -477,10 +479,13 @@ def restart_server():
# Get the current Python interpreter and script path # Get the current Python interpreter and script path
python_path = sys.executable python_path = sys.executable
script_path = os.path.abspath(__file__) script_path = os.path.abspath(__file__)
current_pid = os.getpid()
# Create a shell script to restart the server # Create a shell script to restart the server
restart_script = f"""#!/bin/bash restart_script = f"""#!/bin/bash
sleep 2 sleep 2
kill -9 {current_pid}
export PRODUCTION=true
{python_path} {script_path} {python_path} {script_path}
""" """
+80
View File
@@ -21,6 +21,13 @@ export function setupGame() {
} }
export function startPacman() { export function startPacman() {
// Scroll to the Pacman section
const pacmanSection = document.getElementById("pacman-section");
if (pacmanSection) {
pacmanSection.scrollIntoView({ behavior: 'smooth' });
}
// Initialize game state
initializeGame(); initializeGame();
setupGameLoop(); setupGameLoop();
} }
@@ -28,6 +35,11 @@ export function startPacman() {
export function stopPacman() { export function stopPacman() {
clearInterval(gameInterval); clearInterval(gameInterval);
if (ctx) ctx.clearRect(0, 0, canvas.width, canvas.height); if (ctx) ctx.clearRect(0, 0, canvas.width, canvas.height);
// Restore scrolling
document.body.style.overflow = '';
document.removeEventListener('wheel', preventScroll);
document.removeEventListener('touchmove', preventScroll);
} }
export function resetGame() { export function resetGame() {
@@ -68,6 +80,55 @@ function initializeGame() {
pacman.dx = pacman.dy = 0; pacman.dx = pacman.dy = 0;
document.addEventListener("keydown", movePacman); document.addEventListener("keydown", movePacman);
// Prevent scrolling
document.body.style.overflow = 'hidden';
document.addEventListener('wheel', preventScroll, { passive: false });
document.addEventListener('touchmove', preventScroll, { passive: false });
// Add touch controls
let touchStartX = 0;
let touchStartY = 0;
canvas.addEventListener('touchstart', (e) => {
e.preventDefault();
touchStartX = e.touches[0].clientX;
touchStartY = e.touches[0].clientY;
}, { passive: false });
canvas.addEventListener('touchmove', (e) => {
e.preventDefault();
}, { passive: false });
canvas.addEventListener('touchend', (e) => {
e.preventDefault();
const touchEndX = e.changedTouches[0].clientX;
const touchEndY = e.changedTouches[0].clientY;
const dx = touchEndX - touchStartX;
const dy = touchEndY - touchStartY;
// Determine swipe direction based on the larger movement
if (Math.abs(dx) > Math.abs(dy)) {
// Horizontal swipe
if (dx > 0) {
pacman.dx = PACMAN_SPEED;
pacman.dy = 0;
} else {
pacman.dx = -PACMAN_SPEED;
pacman.dy = 0;
}
} else {
// Vertical swipe
if (dy > 0) {
pacman.dx = 0;
pacman.dy = PACMAN_SPEED;
} else {
pacman.dx = 0;
pacman.dy = -PACMAN_SPEED;
}
}
}, { passive: false });
} }
function setupGameLoop() { function setupGameLoop() {
@@ -283,6 +344,20 @@ function eatDots() {
return true; return true;
}); });
// Check if all dots are eaten
if (dots.length === 0) {
// Trigger password generator for new random map
const generateBtn = document.getElementById("generate-btn");
if (generateBtn) {
generateBtn.click();
}
// Auto-restart the game after a short delay
setTimeout(() => {
resetGame();
}, 1000);
}
ctx.fillStyle = "white"; ctx.fillStyle = "white";
dots.forEach(d => { dots.forEach(d => {
ctx.beginPath(); ctx.beginPath();
@@ -294,3 +369,8 @@ function eatDots() {
// ===== Global Functions ===== // ===== Global Functions =====
window.resetGame = resetGame; window.resetGame = resetGame;
window.exitGame = exitGame; window.exitGame = exitGame;
// Add scroll prevention function
function preventScroll(e) {
e.preventDefault();
}
+40 -11
View File
@@ -221,18 +221,47 @@ function copyToClipboard(elementId, feedbackId) {
if (!el || !el.value) return; if (!el || !el.value) return;
navigator.clipboard.writeText(el.value).then(() => { // Create a temporary textarea element
if (feedback) { const textarea = document.createElement('textarea');
feedback.style.display = "block"; textarea.value = el.value;
feedback.classList.add("show"); textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
// Select and copy the text
textarea.select();
textarea.setSelectionRange(0, 99999); // For mobile devices
try {
// Try using the modern clipboard API first
navigator.clipboard.writeText(el.value).then(() => {
showFeedback(feedback);
}).catch(() => {
// Fallback to execCommand for older browsers
document.execCommand('copy');
showFeedback(feedback);
});
} catch (err) {
// Final fallback
document.execCommand('copy');
showFeedback(feedback);
}
// Clean up
document.body.removeChild(textarea);
}
function showFeedback(feedback) {
if (feedback) {
feedback.style.display = "block";
feedback.classList.add("show");
setTimeout(() => {
feedback.classList.remove("show");
setTimeout(() => { setTimeout(() => {
feedback.classList.remove("show"); feedback.style.display = "none";
setTimeout(() => { }, 300);
feedback.style.display = "none"; }, 3000);
}, 300); // Wait for fade-out animation to complete }
}, 3000);
}
});
} }
function clearAll() { function clearAll() {