Flash游戏制作笔记:跳跃

var Isjump:Boolean;
var Vy:Number=0;
var up:Boolean;
var left:Boolean;
var right:Boolean;

mc.up=false;
mc.left=false;
mc.right=false;
mc.Isjump=false;


function Move(Mc:MovieClip,V:Number,Y:Number):void {
 Mc.x+=Math.cos(Mc.rotation*Math.PI/180)*V;
 Mc.y+=Math.sin(Mc.rotation*Math.PI/180)*V;
 if (!bottom.hitTestPoint(Mc.x,Mc.y+Y,true)) {
  Mc.y=Mc.y+Y;
 }

}


/////////////////////键盘按下的时候//////////////////////////////////////////
stage.addEventListener(KeyboardEvent.KEY_DOWN,Keydown);
function Keydown(event:KeyboardEvent):void {
 switch (event.keyCode) {
  case Keyboard.UP :
   if (!mc.Isjump) {
    mc.Isjump=true;
    Vy=-10;
   }
   break;

  case Keyboard.RIGHT :
   if (!mc.right) {
    mc.right=true;
   }
   break;

  case Keyboard.LEFT :
   mc.left=true;
   break;
  default :
   break;

 }
}

////////////////////键盘防开的时候/////////////////////////////////////////
stage.addEventListener(KeyboardEvent.KEY_UP,Keyup);
function Keyup(event:KeyboardEvent):void {
 if (event.keyCode==Keyboard.UP && mc.Isjump) {
  mc.Isjump=false;

 }
 if (event.keyCode==Keyboard.RIGHT && mc.right) {

  mc.right=false;


 }
 if (event.keyCode==Keyboard.LEFT && mc.left) {
  mc.left=false;
 }

}


////////////////////人物////////////////////////////////////////
stage.addEventListener(Event.ENTER_FRAME,PlayerMove);
function PlayerMove(event:Event):void {
 if (mc.Isjump) {
  Move(mc,0,-5);//上升
  Move(mc,0,Vy++);//下降
  trace(Vy);
  if (Vy>14) {
   mc.Isjump=false;
  }
 }
 if (1) {
  Move(mc,0,5);//xia

 }
 if (mc.right) {
  Move(mc,5,0);
 }
 if (mc.left) {
  Move(mc,-5,0);
 }
}

posted on 2008-08-15 12:01  夏天的树人  阅读(115)  评论(0编辑  收藏  举报