'keydown', (e) => { if(isAnimation)return; const speed = 10; // Adjust as needed let newDirection = ''; switch (e.key) { case 'ArrowUp': newDirection = 'up'; img.style.top = `${parseInt(img.style.top) - speed}px`; break; case 'ArrowDown': newDirection = 'down'; img.style.top = `${parseInt(img.style.top) + speed}px`; break; case 'ArrowLeft': newDirection = 'left'; img.style.left = `${parseInt(img.style.left) - speed}px`; break; case 'ArrowRight': newDirection = 'right'; img.style.left = `${parseInt(img.style.left) + speed}px`; break; } if (newDirection && newDirection !== currentDirection) { img.src = 'strong_"+newDirection+'_walk.gif'; // Change to walking animation currentDirection = newDirection; } }); document.addEventListener('keyup', () => { img.src = 'strong_down_idle.png'; // Change back to idle animation currentDirection = ''; }); });