我正在尝试制作我的脚本,以便它根据数组制作关卡。积木放置得很好,但我必须保证,如果你跳下来摔倒,玩家就会停止碰撞。
我已经尝试了一些方法,但我无法弄清楚,所以我在这里寻求帮助。
变量列表:
var player1:MovieClip;
var up:Boolean = false;
var left:Boolean = false;
var right:Boolean = false;
var isWalking:Boolean = false;
var isJumping:Boolean = false;
var isOnFloor:Boolean = false;
var lastPressed = "";
var jumpSpeedLimit:int = 15;
var jumpSpeed:Number = jumpSpeedLimit;
var currentLevel:Number;
var newBlock:MovieClip;
var level1:Array
var blockHolder:Sprite = new Sprite;
跳转脚本:
public function playerJumpRight():void {
if (!isJumping) {
isOnFloor = false;
isJumping = true;
var xVel:Number = 2;
var yVel:Number = -jumpSpeedLimit; //velocity = snelheid
var yAcc:Number = 1;
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(e:Event):void {
if (isJumping) {
player1.y += yVel;
yVel += yAcc;
if (player1.hitTestObject(newBlock)) {
isOnFloor = true;
}
}
}
}
}
创建级别脚本:
function createLevel() {
addChild(blockHolder);
level1 = new Array(
0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1
);
for (var i:int = 1; i < level1.length; i++) {
if (level1[i] == 1) {
newBlock = new MovieClip();
newBlock.graphics.beginFill(0xFF0000, 1);
newBlock.graphics.drawRect(0, 0, 25, 25);
newBlock.y = 400;
newBlock.x = (i*newBlock.width+i)
blockHolder.addChild(newBlock);
}
}
}