0
我正在爲一個班級製作一個簡單的flash遊戲。我想要讓一個等級爲2,但似乎無法讓敵人獨立爆炸。我製作了實例名稱相同的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++;
}
}
什麼是你的問題是什麼呢? – alxx 2011-03-16 13:27:49
我的導彈不會離開玩家所在的區域,無論我在哪裏拍攝,它都是它所在的地方。 – bissm 2011-03-16 16:40:04