0

我正在尝试为 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;

}
4

1 回答 1

0

这是我将如何进行跳跃和弹跳的方法-这不包括其他代码,例如从左向右移动,因为您已经掌握了

function game(e:Event):void {
    if(jumping){
        yVelocity += 0.1; //gravity
        Monkey.y += yVelocity;
        if(Floor.hitTestObject(Monkey)){
            jumping = false;
            while(Floor.hitTestObject(Monkey)){
                y--;
            }
        }
        if(Ceiling.hitTestObject(Monkey)){
            yVelocity = 0;
            while(Ceiling.hitTestObject(Monkey)){
                y++;
            }
        }
    }
    if(upKeyDown && !jumping){
        jumping = true;
        yVelocity = -3;
    }
}

显然,声明此示例中使用的变量。

于 2012-11-25T03:03:10.277 回答