// JavaScript Document $(document).ready(function(){ $("#right").click(function(){ $("#eat")[0].play(); $("#box").animate({ left: "+=100"},500); $("#box").attr("src","images/pacmanRight.gif"); }) $("#left").click(function(){ $("#eat")[0].play(); $("#box").animate({ left: "-=100"},500); $("#box").attr("src","images/pacmanLeft.gif"); }) $("#up").click(function(){ $("#eat")[0].play(); $("#box").animate({ top: "-=100"},500); $("#box").attr("src","images/pacmanUp.gif"); }) $("#down").click(function(){ $("#eat")[0].play(); $("#box").animate({ top: "+=100"},500); $("#box").attr("src","images/pacmanDown.gif"); }) }); $(document).keypress(function(e){ if(e.keyCode ==115){ //115 is the 'S' key $("#eat")[0].play(); $("#box").animate({ top: "+=100"},500); $("#box").attr("src","images/pacmanDown.gif"); } if(e.keyCode ==119){ //119 is the 'W' key $("#eat")[0].play(); $("#box").animate({ top: "-=100"},500); $("#box").attr("src","images/pacmanUp.gif"); } if(e.keyCode ==97){ //97 is the 'A' key $("#eat")[0].play(); $("#box").animate({ left: "-=100"},500); $("#box").attr("src","images/pacmanLeft.gif"); } if(e.keyCode ==100){ //100 is the 'D' key $("#eat")[0].play(); $("#box").animate({ left: "+=100"},500); $("#box").attr("src","images/pacmanRight.gif"); } })