/*Hero Machine: Because the hero machine only one, so do not need to use the constructor*/varHero = { //Initial pictureSelfNULL, //Initial Leftleft:0, //Initial Toptop:0, //Health ValueLife:3, //Images loaded in and explodedimgs:[' image/hero.gif ', ' image/hero-bang.gif '], //InitializeInit:function(){ //Create a single element varimg = document.createelement (' img ')); //assign a picture path to itImg.src= This. imgs[0]; //inserting into the gameEngine.game.appendChild (IMG); //assign a value to the original image of the hero machine This. Self =img; //Get the height and width of the picture when the picture is finished loading var_this = This;//This point in the function will change, so we'll save it in advance.Img.onload =function(){ //because the property above has this.left, we should assign it as a picture._this.left = (engine.game.offsetwidth-img.offsetwidth)/2;//the left center point of the hero machine equals (the width of the game-the width of the hero Machine) divided by 2 _this.top = Engine. game.offsetheight-Img.offsetheight; Img.style.left= _this.left+ ' px '; Img.style.top= _this.top+ ' px '; }; //call Move when initializing This. Move (); }, //The hero machine also moves when the mouse moves.Movefunction(){ //similar to Magnifier var_this = This; Document.onmousemove=function(e) {varE = e| |event; varL = e.clientx-engine.game.offsetleft-_this.self.offsetwidth/2;vart = e.clienty-engine.game.offsettop-_THIS.SELF.OFFSETHEIGHT/2;//Boundary Processing varLmax = Engine.game.offsetwidth-_this.self.offsetwidth;//Maximum Boundary varBmax = Engine.game.offsetheight-_this.self.offsetheight;//Maximum BoundaryL = L < 0? 0: (L > Lmax?)lmax:l); T= T < 0? 0: (T > Bmax?)bmax:t); //Assign Value_this.self.style.left = l + ' px '; _this.self.style.top= t+ ' px '; }}}hero.init ();
JavaScript Aircraft Wars-----003 Create a Hero Machine