AS3 AI屏障检测和移动

时间:2015-06-17 11:55:07

标签: actionscript-3 flash artificial-intelligence game-physics detection

我正在使用flash CC上学,我正在使用动作脚本3制作一个自上而下的RPG。 我遇到的问题是多层次的;我需要用AI来检测设定的边界,我需要它们在它们到达这些边界时改变方向。目前我已经使用跟踪功能来找出AI何时达到边界,所以我知道这是有效的。然而,之后它不会运行代码。此刻的地图是一个迷宫,所以障碍物是一个影片剪辑,在迷宫内有长方形的墙壁。它适用于用户控制的播放器,为什么它不能在这里工作?以下是AI运动的代码:

    switch (guyFacing) { // which way the AI has turned (left, right, up, down) (this is randomly generated below
            case 0:
                OverworldMC.guyMC.gotoAndStop("walk back frame");
                OverworldMC.guyMC.y -= guySpeed;
                break;

            case 1:
                OverworldMC.guyMC.gotoAndStop("walk front frame");
                OverworldMC.guyMC.y += guySpeed;
                break;

            case 2:
                OverworldMC.guyMC.gotoAndStop("walk left frame");
                OverworldMC.guyMC.x -= guySpeed;
                break;

            case 3:
                OverworldMC.guyMC.gotoAndStop("walk right frame");
                OverworldMC.guyMC.x += guySpeed;
                break;
        }
        guyTimer++; //duration that the AI is moving around the screen
    } else {
        guyWalkDur = Math.random() * 75;
        guyFacing = Math.floor(Math.random() * 4);
        guyTimer = 0;
    }
}
if (OverworldMC.collisionMC.hitTestPoint(OverworldMC.guyMC.x + GleftBumpPoint.x, OverworldMC.guyMC.y + GleftBumpPoint.y, true)) {
    trace("GleftBumping");
    GleftBumping = true;
} else {
    GleftBumping = false;
}
if (OverworldMC.collisionMC.hitTestPoint(OverworldMC.guyMC.x + GrightBumpPoint.x, OverworldMC.guyMC.y + GrightBumpPoint.y, true)) {
    trace("GrightBumping");
    GrightBumping = true;
} else {
    GrightBumping = false;
}
if (OverworldMC.collisionMC.hitTestPoint(OverworldMC.guyMC.x + GupBumpPoint.x, OverworldMC.guyMC.y + GupBumpPoint.y, true)) {
    trace("GupBumping");
    GupBumping = true;
} else {
    GupBumping = false;
}
if (OverworldMC.collisionMC.hitTestPoint(OverworldMC.guyMC.x + GdownBumpPoint.x, OverworldMC.guyMC.y + GdownBumpPoint.y, true)) {
    trace("GdownBumping");
    GdownBumping = true;
} else {
    GdownBumping = false;
}

if (GleftBumping) {
    OverworldMC.guyMC.gotoAndStop("walk right frame");
    OverworldMC.guyMC.x -= guySpeed;
    trace("hitting is true");
}

if (GrightBumping) {
    OverworldMC.guyMC.gotoAndStop("walk left frame");
    OverworldMC.guyMC.x += guySpeed;
}

if (GupBumping) {
    OverworldMC.guyMC.gotoAndStop("walk front frame");
    OverworldMC.guyMC.y -= guySpeed;
}

if (GdownBumping) {
    OverworldMC.guyMC.gotoAndStop("walk back frame");
    OverworldMC.guyMC.y += guySpeed;
}

这段代码的目的是随机生成一个动作(它会这样做),检测它何时撞到障碍物,然后根据它与障碍物的交互方式行动,只是我在最后一部分遇到了一些麻烦。任何和所有的帮助表示赞赏。 问候。

0 个答案:

没有答案