一聚教程网:一个值得你收藏的教程网站

flash as3实现打字小游戏代码

时间:2014-05-28 00:00:00 编辑:简简单单 来源:转载

游戏效果

flash as3实现打字小游戏代码
新建Fla,在第一帧F9添加代码即可。

 代码如下

var arr:Array = new Array();
var time:uint=0;
var angle:Number=0;
var zfun;
[SWF(width=800, height=465,backgroundColor=0xffffff, frameRate=24)]
this.addEventListener(Event.ENTER_FRAME,function(event){
 time++;
 angle+=0.1;
      if(time>=13){
           var tf:TextField = addChild(new TextField()) as TextField;
     zfun = function(){time = 0,tf.htmlText ='<font size="'+String(Math.round(Math.random()*35)+15)+'" color="#'+String(Math.random()*16777215)+'">'+ String.fromCharCode(int(Math.random()*26+65).toString())+'</font>',tf.x = Math.random()*-760+780,tf.y = -10,tf.name = (Math.random()*-10+5).toString(),arr.unshift(tf)}.apply();  
      }
      for(var i:Number = arr.length-1;i>=0;i--){
     zfun =function(){arr[i].y+=3,arr[i].x+= Math.sin(angle)*int(arr[i].name)}.apply();
           if(arr[i].y>=stage.stageHeight){
                        zfun =function(){removeChild(arr[i]),arr.splice(i,1)}.apply();
      break;
           }
      }
});
stage.addEventListener(KeyboardEvent.KEY_DOWN,function(event){
    for(var i:Number = arr.length-1;i>=0;i--){
            if(arr[i].text==String.fromCharCode(event.keyCode)){
                         zfun =function(){removeChild(arr[i]),arr.splice(i,1)}.apply();
       break;
            }
        }
});

文章评论

热门栏目