美文网首页
拳皇八神(几个简单的技能)

拳皇八神(几个简单的技能)

作者: 霁雨轩阁 | 来源:发表于2017-12-09 13:49 被阅读0次
    <head>
        <meta charset="utf-8" />
        <title>拳皇小游戏</title>
        <style type="text/css">
        *{margin: 0;
          padding: 0;
        }
        html{height: 100%;}
        body{height: 100%; background: url(img/bg.jpg) no-repeat; background-size:100% ;}
        #site{
            position: relative;
            height: 100%;
        }
        img{
            position: absolute;
            bottom: 50px;
            width: 200px;
            height: 350px;
        }
        </style>
    </head>
    <body>
        <div id="site">
            <img src="img/stand.gif" id="MC"/>
        </div>
        
    </body>
    

    JS部分
    <script type="text/javascript " >

            function Yagami(imgobj){
                this.obj=imgobj;
                this.Left=0;
                this.timer=null;
                
            }
            Yagami.prototype.action=function(code){
                if(this.skill[code]){
                    this.skill[code].call(this);
                    
                }
                
            }
            Yagami.prototype.skill={
                "40":function(){
                    this.obj.src='img/7490881c38cfba5ef724e4ba.gif'
                    
                },
                
                "37":function(){
                    this.timer=setInterval(function(){
                        this.Left-=5;
                        this.obj.style.left=this.Left+"px"; 
                    }.bind(this),13);
                    this.obj.src='img/retreat.gif'
                },
                "39":function(){
                    this.timer=setInterval(function(){
                        this.Left+=5;
                        this.obj.style.left=this.Left+"px"; 
                    }.bind(this),13);
                    this.obj.src='img/advance.gif'
                },
                "stop":function(){
                    this.obj.src='img/stand.gif'
                }
            }
            Yagami.prototype.stop=function(){
                this.skill.stop.call(this);
                clearInterval(this.timer);
            }
                
            
            
            var imgobj=document.getElementById("MC");
            var MC=new Yagami(imgobj);
            document.onkeydown=keys;
            function keys(evt){
                var code=evt.keyCode;
                MC.action(code);
                this.onkeyup=function(){
                    MC.stop();
                    this.onkeydown=keys;
                }
                this.onkeydown=null; 
            }
    

    </script>

    效果图:


    IMG_3486.GIF

    相关文章

      网友评论

          本文标题:拳皇八神(几个简单的技能)

          本文链接:https://www.haomeiwen.com/subject/cliuixtx.html