我正在尝试为 Flash 制作一种气球格斗游戏。我在屏幕顶部有一个天花板,所以当玩家击中它时,它应该会从上面反弹。问题是,我不知道该怎么做。这是代码。
我在乱搞数字。在问题所在的 upBumping 变量中,我想让角色在击中后反弹,但它只执行一次。之后,它只是穿过天花板。也许我正在以错误的方式解决这个问题?
//gravity and stuff
var gravity:Number = 0.3;
var fall:Number = 0.3;
var downBumping:Boolean = false;
var upBumping:Boolean = false;
//direction I guess
var leftKeyDown:Boolean = false;
var upKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;
var spaceKeyDown:Boolean = false;
//character movement ya'll
var mainSpeed:Number = 6;
stage.addEventListener(Event.ENTER_FRAME, game);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
function game(e:Event): void{
//if certain keys are down then move dat fool
if(leftKeyDown){
Monkey.x -= mainSpeed;
}
if(rightKeyDown){
Monkey.x += mainSpeed;
}
if(upKeyDown){
fall = fall-0.9;
gravity = 0.3;
}
if(Floor.hitTestObject(Monkey)){
downBumping = true;
trace("downBumping");
}
if(Ceiling.hitTestObject(Monkey)){
upBumping = true;
trace("upBumping");
trace(Monkey.y);
}
if(upBumping){
Monkey.y += 20;
}
Monkey.y = Monkey.y+fall;
gravity = gravity*1.0;
fall = fall+gravity;
}