function update() {
  // loop over pacmen array and move each one and move image in DOM

  if (stopMovement === true) {
    stopMovement = false;
    gameRunning = false;
    return;
  }
  gameRunning = true;

  pacMen.forEach((item) => {
    checkCollisions(item);

    item.newimg.src = pacArray[item.direction][item.focus];
    item.focus = (item.focus + 1) % 2;

    item.position.x += item.velocity.x;
    item.position.y += item.velocity.y;

    item.newimg.style.left = item.position.x;
    item.newimg.style.top = item.position.y;
  });
  setTimeout(update, 20);
}
//  updates the position of all the pacmen
updates the position of all the pacmen
updates the position of all the pacmen
function update() {
  if (stopMovement === true) {
    stopMovement = false;
    gameRunning = false;
    return;
  }
  gameRunning = true;
  pacMen.forEach((item) => {
    checkCollisions(item);
    item.newimg.src = pacArray[item.direction][item.focus];
    item.focus = (item.focus + 1) % 2;
    item.position.x += item.velocity.x;
    item.position.y += item.velocity.y;
    item.newimg.style.left = item.position.x;
    item.newimg.style.top = item.position.y;
  });
  setTimeout(update, 20);
}
function update ( ) { if ( stopMovement === true ) { stopMovement = false ; gameRunning = false ; return ; } gameRunning = true ; pacMen . forEach ( ( item ) => { checkCollisions ( item ) ; item . newimg . src = pacArray [ item . direction ] [ item . focus ] ; item . focus = ( item . focus + 1 ) % 2 ; item . position . x += item . velocity . x ; item . position . y += item . velocity . y ; item . newimg . style . left = item . position . x ; item . newimg . style . top = item . position . y ; } ) ; setTimeout ( update , 20 ) ; }
updates the position of all the pacmen
updates the position of all the pacmen
// loop over pacmen array and move each one and move image in DOM