In order to code PacMan moving across the page while opening and closing his mouth a 2D array was created. In the pacArray index[0][0] and [0][1] contains the opened and closed mouth images for PacMan moving to the left while index [1][0] and [1][1] contain the images for PacMan going to the right. Function Run was created with a setInterval so PacMac will move automatically on the page. Lastly, function checkPageBounds was created for the purpose of edge dections utilizing if conditional statments to reverse the current direction.
Download a copy of the PacMan File folder. Drag and drop PacMan.Html onto a blank webpage and load the page. You should see PacMan running back and fourth on the page.
This project is good example of edge dection, setInterval and alternating images using a 2D array.
The future outcome from this project is to add a ghost on the screen that stays ahead of pacMan.
MIT XPro