Our next block of code will give the aliens their motion, causing them to advance to the right along the canvas first, then down a line, then to the left, and so on and so forth. Replace the alienMotion()
function we previously defined with the following code:
alienMotion = function (dir) { var alienLength = aliens.length; if (dirCounter < 4) { for (var x = 0; x < alienLength; x++) { context.clearRect(aliens[x].posX, aliens[x].posY, aliens[x].img.width, aliens[x].img.height); } for (var y = 0; y < alienLength; y++) { aliens[y].posX = (dir === "right") ? aliens[y].posX + 35 : aliens[y].posX - 35; context.drawImage(aliens[y].img, aliens[y].posX, aliens[y].posY); } dirCounter++; } else { clearInterval(motionInt); dirCounter = 0; for (var z = 0; z < alienLength; z++) { context.clearRect(aliens[z].posX, aliens[z].posY, aliens[z].img.width, aliens[z].img.height); } if (aliens...