什么代码将使我们的角色能够携带对象

时间:2011-01-29 07:10:39

标签: flash actionscript-2 cs4

我们创建了一个平台游戏,角色只能携带角色前面的对象。条件是,如果在所述对象的顶部没有任何东西,则角色只能携带对象。

这是当前的代码:

onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 7;
var maxJump:Number = -7;
var touchingGround:Boolean = false;
}

onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y +20, true)) {
_y -= gravity;
grav = 0;
}

if (ground.hitTest(_x, _y+ 50, true)) {
touchingGround = true;
} else {
touchingGround = false;
}

if (Key.isDown(Key.RIGHT)) {
this.moveMC = "RIGHT";
/*this._x++;*/
this.gotoAndStop('right');
_x += speed;
}

if (Key.isDown(Key.LEFT)) {
this.moveMC = "LEFT";
this._x--;
this.gotoAndStop('left');
_x -= speed;
}

if (Key.isDown(Key.UP) && touchingGround) {
this.moveMC = "UP";
this._y--;
this.gotoAndStop('front');
grav = maxJump;
}

if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
_x -= speed;
}

if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
_x += speed;
}

if (ground.hitTest(_x, _y-(height), true)) {
grav = 3;
}

for(i=1;i<4;i++){
while(_root["box" + i].hitTest(_root.saab._x, _root.saab._y + 16, true)){
_root.saab._y --;
}
while(_root["box" + i].hitTest(_root.saab._x, _root.saab._y - 5, true)){
_root.saab._y ++;

}
while(_root.saab.hitTest(_root["box" + i]._x - 16, _root["box" + i]._y, true)){
_root["box" + i]._x ++;
}
while(_root.saab.hitTest(_root["box" + i]._x + 20, _root["box" + i]._y, true)){
_root["box" + i]._x --;
}
}

} 

0 个答案:

没有答案