萬盛學電腦網

 萬盛學電腦網 >> 圖文處理 >> Flash教程 >> flash as3實現打字小游戲代碼

flash as3實現打字小游戲代碼

   游戲效果

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;
            }
        }
});

copyright © 萬盛學電腦網 all rights reserved