我在AS3做了一个迷宫,当玩家击中出口时,迷宫不会进入我的胜利屏幕

时间:2016-05-11 15:18:46

标签: puzzle maze actionscript-3

我制作了一个迷宫和动作脚本3.0,一切正常,除非玩家触摸退出框(一个叫做退出的电影剪辑),迷宫不会进入我的胜利屏幕。  如果有人能帮助我,那就太棒了,因为这是学校的最终项目

这是我的代码

  var rightArrow:Boolean = false;   
    var leftArrow:Boolean = false;
    var upArrow:Boolean = false;
    var downArrow:Boolean = false;
    var speed:int = 5;

    stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_onKeyDown);
    stage.addEventListener(KeyboardEvent.KEY_UP, stage_onKeyUp);
    stage.addEventListener(Event.ENTER_FRAME, stage_onEnterFrame);

    function stage_onKeyDown(event:KeyboardEvent):void {
        if(event.keyCode == Keyboard.RIGHT) rightArrow = true;
        if(event.keyCode == Keyboard.LEFT) leftArrow = true;
        if(event.keyCode == Keyboard.UP) upArrow = true;
        if(event.keyCode == Keyboard.DOWN) downArrow = true;
    }
    function stage_onKeyUp(event:KeyboardEvent):void {
        if(event.keyCode == Keyboard.RIGHT) rightArrow = false;
        if(event.keyCode == Keyboard.LEFT) leftArrow = false;
        if(event.keyCode == Keyboard.UP) upArrow = false;
        if(event.keyCode == Keyboard.DOWN) downArrow = false;
    }
    function stage_onEnterFrame(event:Event):void {
        var rect:Rectangle = player.getBounds(this);
        var i:int = 0;
        var xBump:int = 0;
        var yBump:int = 0;
        if(rightArrow) {
            xBump = speed;
            for(i = 0; i < speed; i++) {
                if(maze.hitTestPoint(rect.right + i, player.y, true)) {
                    xBump = i - 1;
                    break;
                }
            }
        }
        if(leftArrow) {
            xBump = -speed;
            for(i = 0; i < speed; i++) {
                if(maze.hitTestPoint(rect.left - i, player.y, true)) {
                    xBump = -i + 1;
                    break;
                }
            }
        }
        if(upArrow) {
            yBump = -speed;
            for(i = 0; i < speed; i++) {
                if(maze.hitTestPoint(player.x, rect.top - i, true)) {
                    yBump = -i + 1;
                    break;
                }
            }
        }
        if(downArrow) {
            yBump = speed;
            for(i = 0; i < speed; i++) {
                if(maze.hitTestPoint(player.x, rect.bottom + i, true)) {
                    yBump = i - 1;
                    break;
                }
            }
        }
        player.x += xBump;
        player.y += yBump;
    }

if(player.hitTestObject(exit)) {
                gotoAndStop("win");
            }
stop();

1 个答案:

答案 0 :(得分:-1)

你的考试:

=OR(ISNUMBER(MATCH($A2, $A$1:$A1, 0)), ISNUMBER(MATCH($A2, $A3:$A$99999, 0)))

似乎在函数if(player.hitTestObject(exit)) { gotoAndStop("win"); } 之外,因此只执行一次。确保函数的右大括号:

stage_onEnterFrame

在测试之后,就像这样:

    player.x += xBump;
    player.y += yBump;
}         // this one