function handleKeyPress(event) { const key = event.key; if (key === 'ArrowLeft' && direction.x !== 1) { direction = { x: -1, y: 0 }; } else if (key === 'ArrowUp' && direction.y !== 1) { direction = { x: 0, y: -1 }; } else if (key === 'ArrowRight' && direction.x !== -1) { direction = { x: 1, y: 0 }; } else if (key === 'ArrowDown' && direction.y !== -1) { direction = { x: 0, y: 1 }; } }