Arrays 阵列中的多个敌人在碰撞过程中受到影响 私有函数enemyCollisionGoblin():void { var goblinCanMove:Boolean=true;; for(变量i:int=0;i
程序员您好,我对数组和逻辑有问题 我所做的是在阵列中循环,以确保三个敌人,地精都在循环中 在我将一个名为goblin的变量输入到goblin类之后,它等于goblin数组,变量I等于1、2和3,它们是数组中的goblin 如果地精击中敌人,那么地精可以攻击,地精可以移动=false; 这意味着阵列中击中敌人的地精不应该移动,应该攻击 但问题是,当第一个敌人击中地精时,(地精1)这个地精停止移动并在地精1和地精2移动时攻击。但是当妖精2击中敌人时,妖精2会停下来攻击。但是妖精1和妖精3停止移动 当小妖精3攻击敌人时,它会停止并攻击,虽然小妖精1停止移动,但是小妖精2会毫不犹豫地移动 同样的事情也适用于攻击,当我攻击妖精1时,他停止移动,妖精2和3移动 我攻击地精2,所有地精都受到影响。我攻击妖精3,他停止,妖精1也停止 这是地精班Arrays 阵列中的多个敌人在碰撞过程中受到影响 私有函数enemyCollisionGoblin():void { var goblinCanMove:Boolean=true;; for(变量i:int=0;i,arrays,actionscript-3,flash,Arrays,Actionscript 3,Flash,程序员您好,我对数组和逻辑有问题 我所做的是在阵列中循环,以确保三个敌人,地精都在循环中 在我将一个名为goblin的变量输入到goblin类之后,它等于goblin数组,变量I等于1、2和3,它们是数组中的goblin 如果地精击中敌人,那么地精可以攻击,地精可以移动=false; 这意味着阵列中击中敌人的地精不应该移动,应该攻击 但问题是,当第一个敌人击中地精时,(地精1)这个地精停止移动并在地精1和地精2移动时攻击。但是当妖精2击中敌人时,妖精2会停下来攻击。但是妖精1和妖精3停止移动 当
private function enemyCollisionGoblin():void
{
var goblinCanMove:Boolean = true;;
for (var i:int = 0; i < aGoblinArray.length; i++)
{
var goblin:Goblin = aGoblinArray[i];
//goblin hits player
if (goblin.hitTestPoint(_character.x + 30, _character.y - 45, true) || goblin.hitTestPoint(_character.x - 30, _character.y - 45, true))
{
if (!defendKey)
{
currentHP -= 1;
updateHealthBar();
chckDeathCon();
}
goblinCanMove = false;
goblin.canAttack();
}
if (attackKey && lookingLeft &&!lookingRight)
{
if (goblin.hitTestPoint(_character.x + 100, _character.y - 45, true))
{
goblinCanMove = false;
trace("lance hits");
//hitOnce
if (!hitOnce)
{
hitOnce = true;
goblin.moveBack();
trace("take on damage");
}
}
}
if (goblinCanMove)
{
goblin.canMove();
}
}
}
//this is before this happens, declared on top of main constructor
private var aGoblinArray = new Array(container.goblin1, container.goblin2, container.goblin3);
包{
导入flash.display.MovieClip;
导入flash.events.Event;
进口主管道;
进口球员;
/**
* ...
*@作者莫伊努尔·侯赛因
*/
公共级地精扩展MovieClip{
私有变量:数字;
私人生活;
公共静态var lookingRight:布尔值;
公共静态变量canAttackLeft:布尔值;
公共静态变量canAttackRight:布尔值;
公共var攻击:布尔攻击;
公共速度:int;
公共静态变量移动:布尔;
公共功能地精(){
move=true;
nTimer=0;
速度=1;
goblinLife=2;
this.addEventListener(Event.ADDED_至_阶段,onAdd)
}
onAdd的私有函数(e:事件):无效{
//痕迹(“添加的地精”);
移除EventListener(将Event.add添加到舞台,onAdd);
//this.addEventListener(Event.ENTER_FRAME,goblinLoop);
}
公共函数goblinLoop():void
{
}
公共函数canAttack():void
{
这个。gotoAndStop(“攻击”);
}
公共函数canMove():void
{
nTimer=nTimer+0.05;
如果(nTimer<5)
{
lookingRight=错误;
this.scaleX=-1;
这个。gotoAndStop(“run”);
这个.x+=速度;
lookingRight=正确;
//跟踪(“权利”);
}
其他的
{
lookingRight=错误;
//痕迹(“向左看”);
这个.x-=速度;
这个。gotoAndStop(“run”);
这个.scaleX=1;
如果(nTimer>10)//这不能是5,这是不符合逻辑的,所以必须是10)
{
nTimer=0;
}
}
}
公共函数moveRight():void
{
这个.x-=速度;
这个。gotoAndStop(“run”);
这个.scaleX=1;
}
公用函数rangeAttack():void
{
}
公共函数takeDamage():void
{
妖精生活;
}
公共函数不带任何内容():void
{
这是gotoAndStop(1);
}
公共函数moveBack():void
{
这是gotoAndStop(“beenHit”);
这个.x
}
}
}
很抱歉,如果要接受的内容太多。问题是您的布尔值最初设置为true,但一旦有一个golblin将其设置为false,所有地精的布尔值都将变为false。请尝试将其移动到for循环中:
package {
import flash.display.MovieClip;
import flash.events.Event;
import Main;
import player;
/**
* ...
* @author Moynul Hussain
*/
public class Goblin extends MovieClip {
private var nTimer: Number;
private var goblinLife; int;
public static var lookingRight: Boolean;
public static var canAttackLeft: Boolean;
public static var canAttackRight: Boolean;
public var attack: Boolean;
public var speed: int;
public static var move: Boolean;
public function Goblin() {
move = true;
nTimer = 0;
speed = 1;
goblinLife = 2;
this.addEventListener(Event.ADDED_TO_STAGE, onAdd)
}
private function onAdd(e: Event): void {
//trace("added Goblin");
removeEventListener(Event.ADDED_TO_STAGE, onAdd);
//this.addEventListener(Event.ENTER_FRAME, goblinLoop);
}
public function goblinLoop():void
{
}
public function canAttack():void
{
this.gotoAndStop("attack");
}
public function canMove(): void
{
nTimer = nTimer + 0.05;
if (nTimer < 5)
{
lookingRight = false;
this.scaleX = -1;
this.gotoAndStop("run");
this.x += speed;
lookingRight = true;
//trace("right");
}
else
{
lookingRight = false;
//trace("looking LEFT");
this.x -= speed;
this.gotoAndStop("run");
this.scaleX = 1;
if (nTimer > 10) //this can't be 5, it's not logical, so it has to be 10)
{
nTimer = 0;
}
}
}
public function moveRight():void
{
this.x -= speed;
this.gotoAndStop("run");
this.scaleX = 1;
}
public function rangeAttack():void
{
}
public function takeDamage():void
{
goblinLife--;
}
public function doNothing():void
{
this.gotoAndStop(1);
}
public function moveBack():void
{
this.gotoAndStop("beenHit");
this.x
}
}
私有函数enemyCollisionGoblin():void
{
变量goblinCanMove:布尔值;
for(变量i:int=0;i
这么多妖精。你的问题是什么?哦,忘了这个问题。问题是我如何确保阵列中的其他地精不受影响。例如,goblin2击中我,它将停止行走并击中我。但是,妖精1和妖精3也会停止移动。但他们不会攻击。他们会停止移动。我怎样才能阻止这个。谢谢,我所做的是提升这个变量,并在主构造函数中初始化它。如果没有击中玩家,地精可以移动。我猜什么会发生,什么会发生!因果报应确实帮助了我;D
private function enemyCollisionGoblin():void
{
var goblinCanMove:Boolean;
for (var i:int = 0; i < aGoblinArray.length; i++)
{
goblinCanMove = true;
/* rest of the code */
}
}