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

<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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. tab列表折叠效果 html: 能源系统事业部 岗位名称: 工作地点 岗位名...
    lilyping阅读 1,899评论 0 1
  • 1、垂直对齐 如果你用CSS,则你会有困惑:我该怎么垂直对齐容器中的元素?现在,利用CSS3的Transform,...
    kiddings阅读 3,205评论 0 11
  • 各种纯css图标 CSS3可以实现很多漂亮的图形,我收集了32种图形,在下面列出。直接用CSS3画出这些图形,要比...
    剑残阅读 9,700评论 0 8
  • 新年伊始,我们总是向岁月许下美好的愿望。健康、平安、快乐、升职、加薪、旅游、升学、生娃、结婚、恋爱······ 可...
    铅笔芒种阅读 563评论 0 1
  • 优优,我本来是想做你的全能老爸的, 做那个在你遇到困难时,披着斗篷赶到助你一臂之力的人; 做那个在你迷路时,信手拈...
    tong堡阅读 186评论 0 0