我正在尝试制作一种用于闪光灯的气球格斗游戏。我在屏幕顶部有一个天花板,所以当玩家击中它时,它应该从它反弹。问题是,我不知道如何去做。这是代码。
我正在弄乱数字。在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;
}
答案 0 :(得分: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;
}
}
显然,声明此示例中使用的变量。