Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 有多个敌人的问题,如果被导弹击中,则玩游戏_Flash_Actionscript 2_Flash Cs4 - Fatal编程技术网

Flash 有多个敌人的问题,如果被导弹击中,则玩游戏

Flash 有多个敌人的问题,如果被导弹击中,则玩游戏,flash,actionscript-2,flash-cs4,Flash,Actionscript 2,Flash Cs4,我正在为一个班级制作一个简单的flash游戏。我想制作一个二级游戏,但似乎无法让敌人独立爆炸。我使实例名称相同的enemy2、enemy3、enemy4和enemy5符号。为了以防万一,我还另外安排了一名球员。下面的代码在播放器的框架上。如有任何建议,将不胜感激 onClipEvent(load) { var shipSpeed:Number = 15; var rotationSpeed:Number = 15; var missileNum:Number = 0;

我正在为一个班级制作一个简单的flash游戏。我想制作一个二级游戏,但似乎无法让敌人独立爆炸。我使实例名称相同的enemy2、enemy3、enemy4和enemy5符号。为了以防万一,我还另外安排了一名球员。下面的代码在播放器的框架上。如有任何建议,将不胜感激

onClipEvent(load) {
    var shipSpeed:Number = 15;
    var rotationSpeed:Number = 15;
    var missileNum:Number = 0;
    var missile:Array = new Array();
    var missleSpeed:Number = 20;
}



onClipEvent (enterFrame) {
if(Key.isDown(Key.LEFT)) {
    _rotation -= shipSpeed;
}

if(Key.isDown(Key.RIGHT)) {
    _rotation += shipSpeed;
}

var radian:Number = (-1 * _rotation + 90) * Math.PI/180;

if(Key.isDown(Key.UP)) {
    _x += shipSpeed * Math.cos(radian);
    _y -= shipSpeed * Math.sin(radian);
}

if(Key.isDown(Key.DOWN)) {
    _x -= shipSpeed * Math.cos(radian);
    _y += shipSpeed * Math.sin(radian);
}


// keeps player in the frame    
if(this._x >= 800)  this._x = 11;
if(this._x <= 10)  this._x = 799;
if(this._y >= 600)  this._y = 11;
if(this._y <= 10)  this._y = 599;




 if(this.hitTest(_root.enemy2))
 {
    _root.player2.play ();
 }

if(this.hitTest(_root.enemy3))
 {
    _root.player2.play ();
 }

 if(this.hitTest(_root.enemy4))
 {
    _root.player2.play ();
 }

 if(this.hitTest(_root.enemy5))
 {
    _root.player2.play ();
 }

//Shoot missile in direction the ship is facing
if(Key.isDown(Key.SPACE)) {
    missile[missileNum] = _root.attachMovie("missile","missile"+missileNum,_root.getNextHighestDepth(),{_x:_x,_y:_y,_rotation:_rotation});
    missile[missileNum].ySpeed = Math.sin(radian)*missleSpeed;
    missile[missileNum].xSpeed = Math.cos(radian)*missleSpeed;
    missile[missileNum].onEnterFrame = function() {
        if(this.hitTest(_root.enemy2)) {
            _root.enemy2.play ();}


        if(this.hitTest(_root.enemy3)) {
            _root.enemy3.play ();}

    if(this.hitTest(_root.enemy4)) {
        _root.enemy4.play();}

    if(this.hitTest(_root.enemy5)) {
        _root.enemy5.play();}

           // this.attachMovie("enemy", "enemy", 3 );
        }
        this._y -= this.ySpeed;
        this._x += this.xSpeed;
        trace("missile: " + missileNum);
        if(0 > this._x || this._x > 800 || 0 > this._y || this._y > 600)
            this.removeMovieClip();
    }
    missileNum++;
}
}
onClipEvent(加载){
var shipSpeed:数字=15;
var旋转速度:数字=15;
var Misselenum:数字=0;
var导弹:数组=新数组();
var missleSpeed:Number=20;
}
onClipEvent(enterFrame){
if(键isDown(键左)){
_旋转-=船速;
}
if(键isDown(键右侧)){
_旋转+=船速;
}
变弧度:数字=(-1*_旋转+90)*数学PI/180;
if(键isDown(键UP)){
_x+=船速*数学cos(弧度);
_y-=船速*数学sin(弧度);
}
if(键isDown(键DOWN)){
_x-=船速*数学cos(弧度);
_y+=船速*数学sin(弧度);
}
//保持球员在框架内
如果(this.\ux>=800)this.\ux=11;
如果(this._x=600)this._y=11;
如果(这个.|这个.|这个.| 800 | | 0>这个.|这个.|这个.|y>600)
这是。removeMovieClip();
}
Misselenum++;
}
}

您肯定需要学习如何正确缩进代码。正如您所看到的,它不仅会导致混乱,还会导致许多错误

问题是这部分代码

    this._y -= this.ySpeed;
    this._x += this.xSpeed;
    trace("missile: " + missileNum);
    if(0 > this._x || this._x > 800 || 0 > this._y || this._y > 600)
        this.removeMovieClip();
不在导弹的单帧事件侦听器中。将}花括号移到此代码下方。同时将
missleNum++
零件置于1号括号上方

换言之,将其转换为:

       // this.attachMovie("enemy", "enemy", 3 );
    }
    this._y -= this.ySpeed;
    this._x += this.xSpeed;
    trace("missile: " + missileNum);
    if(0 > this._x || this._x > 800 || 0 > this._y || this._y > 600)
        this.removeMovieClip();
}
missileNum++;
为此:

       // this.attachMovie("enemy", "enemy", 3 );
    this._y -= this.ySpeed;
    this._x += this.xSpeed;
    trace("missile: " + missileNum);
    if(0 > this._x || this._x > 800 || 0 > this._y || this._y > 600)
        this.removeMovieClip();

    }

missileNum++;
}
此外,您提供的代码似乎在代码末尾包含2个不必要/未使用的}括号

让我给你完整的、适当缩进的“导弹”部分:

我的另一个建议是将你的敌人排成一列,让我们先说“敌人”

 var enemies:Array = new Array(); //initiate them now or later
然后你可以把敌人推进去,就像你用导弹一样 敌人。推(根。一些新创建的敌人)

然后呢

foreach(enemy in enemies){
  if(this.hitTest(enemy)) {
    enemy.play();}
}

我的导弹没有一个接一个地进行静态检查,而是不会离开玩家的区域,无论我在哪里射击,它都会停留在那里。。
foreach(enemy in enemies){
  if(this.hitTest(enemy)) {
    enemy.play();}
}