As part of the challenge, I am tasked with creating a Pacman game using HTML, CSS, and JavaScript. One key aspect is to control the movement of the ghosts throughout the game. However, I am facing an issue with the current function that controls the ghost's movement - it only gets called once, causing the ghost to stop. Is there a way to make this function run continuously for an infinite amount of time?
function moveEnemy() {
var e1 = document.getElementById("e1");
if(parseInt(e1.style.left)>10 && parseInt(e1.style.left)<1000)
e1.style.left = parseInt(e1.style.left) + 5 + 'px';
else if(parseInt(e1.style.left)<10 && parseInt(e1.style.top)<500)
e1.style.top = parseInt(e1.style.top) + 5 + 'px';
else if(parseInt(e1.style.left)<10 && parseInt(e1.style.top)>500)
e1.style.top = parseInt(e1.style.top) - 5 + 'px';
else if(parseInt(e1.style.left)>1000 && parseInt(e1.style.top)>500)
e1.style.left = parseInt(e1.style.left) - 5 + 'px';
}
Since I'm unable to utilize jQuery for this task, any solution using pure JS would be greatly appreciated :)