JavaScript Aircraft Wars-----003 Create a Hero Machine

Source: Internet
Author: User

/*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 (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 = (;//the left center point of the hero machine equals (the width of the game-the width of the hero Machine) divided by 2 = Engine. game.offsetheight-Img.offsetheight; _this.left+ ' px '; ' 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 =;vart =;//Boundary Processing            varLmax =;//Maximum Boundary            varBmax =;//Maximum BoundaryL = L < 0? 0: (L > Lmax?)lmax:l); T= T < 0? 0: (T > Bmax?)bmax:t); //Assign = l + ' px '; t+ ' px '; }}}hero.init ();

JavaScript Aircraft Wars-----003 Create a Hero Machine

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.