zoukankan      html  css  js  c++  java
  • 接水果小游戏的制作

                                                                接水果小游戏

    首先把所需要的素材导入Flash库中,然后发不成SWF格式,在程序中,用代码调用。

    然后接下来,把下面的代码打上就可以了。

    package

    {

            import flash.display.Sprite;

            import flash.events.Event;

            import flash.events.KeyboardEvent;

            import flash.events.TimerEvent;

            import flash.text.TextField;

            import flash.utils.Timer;

           import flash.system.fscommand;

     [SWF(width = "800", height = "600")]

         public class JSG extends Sprite  

                {

                        private var BJ:bj;

      private var RW:rw;

      private var YD:String;

      private var timer:Timer;

      private var arr:Array = [];

      private var txt:TextField;

      private var FS:int;

      private var SW:int;

            public function JSG()

      {

       initbj();

       initrw();

       inittxt();

       initSG();

       move();

      }      

    private function inittxt():void   

    {

               txt = new TextField();

         txt.text = "分数";

         txt.x = stage.stageWidth - txt.width;

         txt.y = 47;

         txt.border = true;

         txt.textColor = 0x00ff00;

         txt.width = 40;

         txt.height = 20;

         stage.addChild(txt);

    }      

    private function initSG():void   

    {

                timer = new Timer(600);

          timer.addEventListener(TimerEvent.TIMER,OnTimerHandler);

          timer.start();

    }      

    protected function OnTimerHandler(event:TimerEvent):void   

    {

              var MD:md = new md();

       MD.x = Math.random()* (800 - MD.width);

       MD.y = -(MD.height);

       arr.push(MD);

       stage.addChild(MD);

    }   

    private function initbj():void   

    {

       BJ = new bj();

       stage.addChild(BJ);

    }      

    private function initrw():void   

    {

       RW = new rw();

       RW.x = stage.stageWidth/2;

       RW.y = stage.stageHeight - RW.height/2;

       stage.addChild(RW);

    }      

    private function move():void   

    {

              stage.addEventListener(KeyboardEvent.KEY_DOWN,OnDOWNHandler);

              stage.addEventListener(KeyboardEvent.KEY_UP,OnUPandler);

             stage.addEventListener(Event.ENTER_FRAME,OnFrameHandler);

    }      

    protected function OnDOWNHandler(event:KeyboardEvent):void

    {

            if(event.keyCode == 37)

                 {     YD = "左";    }

           else if (event.keyCode == 39)    

                {     YD ="右";    }

    }      

    protected function OnUPandler(event:KeyboardEvent):void   

    {    

    YD ="停止";   

    }   

    protected function OnFrameHandler(e:Event):void   

    {    

          if(YD == "左")

            {     RW.x -= 10;    }

         else if (YD == "右")    

           {     RW.x += 10;     }

       else if(YD == "停止")    

          {          }

       if(RW.x < RW.width/2)   

        {     RW.x = RW.width/2;    }   

     else if(RW.x > stage.stageWidth - RW.width/2 )   

                {     RW.x = stage.stageWidth - RW.width/2;       }    

    for(var i:int = 0;i < arr.length; i++)    

         {      

                   arr[i].y += 10;

                   if(arr[i].hitTestObject(RW) == true)

                     {       

                          FS += 10;

                          txt.text = String(FS);

                          stage.removeChild(arr[i]);

                         arr.splice(i,1);

                     }      

                   if(arr[i].y > stage.stageHeight + arr[i].height)      

                         {       

                                          SW ++;

                                          stage.removeChild(arr[i]);

                                         arr.splice(i,1);

                                          if(SW >= 5)

                                             {        

                                                    fscommand("quit");

                                             }      

    }    

    }   

    }  

    }

    }

  • 相关阅读:
    安卓android.support.design使用中的问题
    处理requests SSl 证书问题
    python-excel
    post 请求包含相同参数
    关于zk 页面滚动问题 scroll
    Usefull Jquery
    Git 安装
    Comparison issues in TD
    Work Diary 12/13/17
    Unit10 I don't like work in the weekend
  • 原文地址:https://www.cnblogs.com/klh5211314/p/2754249.html
Copyright © 2011-2022 走看看