Flash:使箭头移动

时间:2014-05-19 13:23:35

标签: flash

如何让箭头一直移动并让它在撞到墙壁时死亡,就像蛇一样。当我的代码是:

import flash.events.Event;

ting.stop();

var hastighed:Number = 50;
var flyt_vertikal:Number = 0;
var flyt_horizontal:Number = 0;

var point:Boolean = true;
var taeller:Number = 0;

stage.addEventListener (KeyboardEvent.KEY_DOWN, onKeydown);

function onKeydown (e:KeyboardEvent):void

{
    if (e.keyCode == Keyboard.RIGHT)

    {this.flyt_horizontal = hastighed;
        this.ting.gotoAndStop (1);

    }


    if (e.keyCode == Keyboard.LEFT)

    {this.flyt_horizontal = hastighed*-1;
        this.ting.gotoAndStop (2);

    }

    if (e.keyCode == Keyboard.UP)

    {this.flyt_vertikal = hastighed*-1;
        this.ting.gotoAndStop (3);

    }


    if (e.keyCode == Keyboard.DOWN)
    {
     this.flyt_vertikal = hastighed;
       this.ting.gotoAndStop (4);

    }

    }


stage.addEventListener (KeyboardEvent.KEY_UP, onKeyup);

function onKeyup(e:KeyboardEvent)

{


    if(e.keyCode == Keyboard.RIGHT)
    {
        flyt_horizontal = 0;
    }



    if(e.keyCode == Keyboard.LEFT)
    {

        flyt_horizontal = 0;
    }



    if(e.keyCode == Keyboard.UP)
    {
        flyt_vertikal = 0;
    }



    if(e.keyCode == Keyboard.DOWN)
    {
        flyt_vertikal = 0;
    }
}




this.addEventListener(Event.ENTER_FRAME,animerObjekt);

function animerObjekt(evt:Event) {
   this.ting.x += flyt_horizontal;
      this.ting.y += flyt_vertikal;

      if(this.ting.x>stage.stageWidth - 10) {
         this.ting.x=stage.stageWidth -25;
         }

        if(this.ting.x< 25){
           this.ting.x =35;
           }

      if(this.ting.y > stage.stageHeight -25 ){
         this.ting.y = stage.stageHeight - 35;
         }

      if(this.ting.y< 25){
           this.ting.y =35;
           }

           if(this.ting.hitTestObject(this.maal) && point == true ){
               taeller++;
               point = false;
               }

            if(this.ting.hitTestObject(this.maal) == false) {

               point = true;
               }   



              if((this.ting.hitTestObject(this.maal2) && point == true )){
               taeller++;
               point = false;
               }

            if(this.ting.hitTestObject(this.maal2) == false) {

               point = true;
               }  

               this.point_tekst.text = String(taeller + "point");


}

如果有人可以帮助我,我会很高兴。

您可以在http://grafisk.kts.dk/elever/chpe22/Jinn/snake_spil.html

上看到它的版本

0 个答案:

没有答案