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

热门教程

flash as3实现打字小游戏代码

时间:2022-06-28 22:12:15 编辑:袖梨 来源:一聚教程网

游戏效果

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 =''+ String.fromCharCode(int(Math.random()*26+65).toString())+'',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;
            }
        }
});

热门栏目