diff --git a/script.js b/script.js index aca7180..25809c5 100644 --- a/script.js +++ b/script.js @@ -4,7 +4,7 @@ const gameOverScreen = document.getElementById('gameOver'); const profilePicUpload = document.getElementById('profilePicUpload'); const startGameButton = document.getElementById('startGame'); const flashOverlay = document.getElementById('flashOverlay'); -const controls = document.getElementById('controls'); + const collisionSound = document.getElementById('collisionSound'); const gameOverSound = document.getElementById('gameOverSound'); @@ -19,12 +19,12 @@ const player = { image: null, velocityX: 0, velocityY: 0, - acceleration: 2, + acceleration: 0.75, friction: 0.85 }; let difficultyFactor = 1; // Initialize the difficulty factor -let obstacleCreationRate = 0.02; // Initial obstacle creation rate +let obstacleCreationRate = 0.04; // Initial obstacle creation rate let obstacles = []; let score = 0; let lives = 10; @@ -48,10 +48,10 @@ const obstacleImages = { // Load obstacle images (replace with actual image URLs) const imageUrls = { - onlyfans: 'images/onlyfans.png', // Replace with actual image URL for OF creator - marketer: 'images/marketer.png', // Replace with actual image URL for Network Marketer - fitness: 'images/fitness.png', // Replace with actual image URL for Fitness Influencer - crypto: 'images/crypto.png' // Replace with actual image URL for Crypto Bro + onlyfans: 'https://raw.githubusercontent.com/heybobjones/dodgy-dodger/main/images/OFCreator.png', // Replace with actual image URL for OF creator +marketer: 'https://raw.githubusercontent.com/heybobjones/dodgy-dodger/main/images/NetworkMarketer.png', // Replace with actual image URL for Network Marketer +fitness: 'https://raw.githubusercontent.com/heybobjones/dodgy-dodger/main/images/FitnessBro.png', // Replace with actual image URL for Fitness Influencer +crypto: 'https://raw.githubusercontent.com/heybobjones/dodgy-dodger/main/images/CryptoBro.png' // Replace with actual image URL for Crypto Bro }; // Load all images and start the game once all images are loaded @@ -85,7 +85,7 @@ function drawPlayer() { ctx.clip(); if (player.image) { - const scaleFactor = 1.5; // Increase this factor to make the image larger + const scaleFactor = 1; // Increase this factor to make the image larger ctx.drawImage(player.image, player.x - player.radius * scaleFactor, player.y - player.radius * scaleFactor, player.radius * 2 * scaleFactor, player.radius * 2 * scaleFactor); } else { ctx.fillStyle = '#0F0'; @@ -169,7 +169,25 @@ function moveObstacles() { } function movePlayer() { - // Ensure the player stays within the canvas bounds + if (keysPressed['ArrowLeft']) { + player.velocityX -= player.acceleration; + } + if (keysPressed['ArrowRight']) { + player.velocityX += player.acceleration; + } + if (keysPressed['ArrowUp']) { + player.velocityY -= player.acceleration; + } + if (keysPressed['ArrowDown']) { + player.velocityY += player.acceleration; + } + + player.velocityX *= player.friction; + player.velocityY *= player.friction; + + player.x += player.velocityX; + player.y += player.velocityY; + player.x = Math.max(player.radius, Math.min(canvas.width - player.radius, player.x)); player.y = Math.max(player.radius, Math.min(canvas.height - player.radius, player.y)); } @@ -299,53 +317,6 @@ function playSound(sound) { } } -// Handle touch events -let touchStartX = 0; -let touchStartY = 0; - -function handleTouchStart(evt) { - const firstTouch = evt.touches[0]; - touchStartX = firstTouch.clientX; - touchStartY = firstTouch.clientY; -} - -function handleTouchMove(evt) { - if (!touchStartX || !touchStartY) { - return; - } - - const touchMoveX = evt.touches[0].clientX; - const touchMoveY = evt.touches[0].clientY; - - const diffX = touchStartX - touchMoveX; - const diffY = touchStartY - touchMoveY; - - if (Math.abs(diffX) > Math.abs(diffY)) { - if (diffX > 0) { - // Swipe left - player.x -= player.speed; - } else { - // Swipe right - player.x += player.speed; - } - } else { - if (diffY > 0) { - // Swipe up - player.y -= player.speed; - } else { - // Swipe down - player.y += player.speed; - } - } - - // Reset values - touchStartX = touchMoveX; - touchStartY = touchMoveY; -} - -document.addEventListener('touchstart', handleTouchStart, false); -document.addEventListener('touchmove', handleTouchMove, false); - // Load images and start the game loadImages(() => { startGameButton.style.display = 'block';