var dy:Number;//两者Y轴之间的距离
var dx:Number;
var dxspeed:Number;
var dyspeed:Number;
var r:Number;
var du:Number;
ship.addEventListener(Event.ENTER_FRAME,runing);
function runing(event:Event):void{
dy=Math.round(mouseY-ship.y);
dyspeed=Math.round(dy/5);
ship.y+=dyspeed;
dx=Math.round(mouseX-ship.x);
dxspeed=Math.round(dx/5);
ship.x+=dxspeed;
r=Math.atan2(mouseY-ship.y,mouseX-ship.x)//计算出鼠标与物体的角度
du=Math.round(r*180/Math.PI);
ship.rotation=du;
}
lan1.addEventListener(Event.ENTER_FRAME,top_hitting);
function top_hitting(event:Event):void{
while(lan1.hitTestObject(ship))
{
ship.y=ship.y+50;
}
}
lan2.addEventListener(Event.ENTER_FRAME,bottom_hitting);
function bottom_hitting(event:Event):void{
while(lan2.hitTestObject(ship))
{
ship.y=ship.y-50;
}
}
lan3.addEventListener(Event.ENTER_FRAME,left_hitting);
function left_hitting(event:Event):void{
while(lan3.hitTestObject(ship))
{
ship.x=ship.x+50;
}
}
lan4.addEventListener(Event.ENTER_FRAME,right_hitting);
function right_hitting(event:Event):void{
while(lan4.hitTestObject(ship))
{
ship.x=ship.x-50;
}
}
角色:一个为ship 的影片剪辑 ,四个是栏杆 分别是lan1, lan2, lan3, lan4
这个是可以用鼠标拖动的飞船,周围有很多墙壁 一旦发生就会出事情了 ,呵呵