所以,我试图让我的游戏中一些小行星随机移动,如果你击中一颗,它会移动到其他地方,并有一条新的、也是随机的飞行路径。我的问题是当我撞上一颗小行星时,它确实创建了一条新路径,但如果我击中它 3 次以上,它只会不断重置到同一路径的同一位置。谁能帮我这个?(常规层)导入 flash.events.Event;addEventListener(Event.ENTER_FRAME, massGain); 停止();
var speedX = (Math.random() * 20 - 10);
var speedY = (Math.random() * 20 - 10);
var speedX1 = (Math.random() * 20 - 10);
var speedY1 = (Math.random() * 20 - 10);
var speedX2 = (Math.random() * 20 - 10);
var speedY2 = (Math.random() * 20 - 10);
var speedX3 = (Math.random() * 20 - 10);
var speedY3 = (Math.random() * 20 - 10);
var speedX4 = (Math.random() * 20 - 10);
var speedY4 = (Math.random() * 20 - 10);
var speedX5 = (Math.random() * 20 - 10);
var speedY5 = (Math.random() * 20 - 10);
var speedX6 = (Math.random() * 20 - 10);
var speedY6 = (Math.random() * 20 - 10);
function massGain(e:Event)
{
Mouse.hide();
Cosmo.x = mouseX;
Cosmo.y = mouseY;
Asteroid5.x = Asteroid5.x + speedX;
Asteroid5.y = Asteroid5.y + speedY;
if (Asteroid5.x > 1100 || Asteroid5.x < -100)
{
speedX = -speedX
}
if (Asteroid5.y > 800 || Asteroid5.y < -100)
{
speedY = -speedY
}
Asteroid6.x = Asteroid6.x + speedX1;
Asteroid6.y = Asteroid6.y + speedY1;
if (Asteroid6.x > 1100 || Asteroid6.x < -100)
{
speedX1 = - speedX1;
}
if (Asteroid6.y > 800 || Asteroid6.y < -100)
{
speedY1 = - speedY1;
}
Asteroid7.x = Asteroid7.x + speedX2;
Asteroid7.y = Asteroid7.y + speedY2;
if (Asteroid7.x > 1100 || Asteroid7.x < -100)
{
speedX2 = - speedX2;
}
if (Asteroid7.y > 800 || Asteroid7.y < -100)
{
speedY2 = - speedY2;
}
Asteroid8.x = Asteroid8.x + speedX3;
Asteroid8.y = Asteroid8.y + speedY3;
if (Asteroid8.x > 1100 || Asteroid8.x < -100)
{
speedX3 = - speedX3;
}
if (Asteroid8.y > 800 || Asteroid8.y < -100)
{
speedY3 = - speedY3;
}
Deathroid1.x = Deathroid1.x + speedX4;
Deathroid1.y = Deathroid1.y + speedY4;
if (Deathroid1.x > 1100 || Deathroid1.x < -100)
{
speedX4 = - speedX4;
}
if (Deathroid1.y > 800 || Deathroid1.y < -100)
{
speedY4 = - speedY4;
}
Deathroid2.x = Deathroid2.x + speedX5;
Deathroid2.y = Deathroid2.y + speedY5;
if (Deathroid2.x > 1100 || Deathroid2.x < -100)
{
speedX5 = - speedX5;
}
if (Deathroid2.y > 800 || Deathroid2.y < -100)
{
speedY5 = - speedY5;
}
Deathroid3.x = Deathroid3.x + speedX6;
Deathroid3.y = Deathroid3.y + speedY6;
if (Deathroid3.x > 1100 || Deathroid3.x < -100)
{
speedX6 = - speedX6;
}
if (Deathroid3.y > 800 || Deathroid3.y < -100)
{
speedY6 = - speedY6;
}
}
(动作层)var mySound1:Sound = new menuSelectionClick(); var mySound2:Sound = 新的爆炸();var nCount1:Number = 0;
timer_Text1.text = nCount1.toString();
addEventListener(Event.ENTER_FRAME,massCollect);
function massCollect(e:Event)
{
if (Cosmo.hitTestObject(Asteroid5))
{
mySound1.play();
nCount1++;
timer_Text1.text = nCount1.toString();
Asteroid5.y = (Math.random() * 20 - 5);
Asteroid5.x = (Math.random() * 20 - 15);
Asteroid5.x = Asteroid5.x + (Math.random() * 20 - 15);//+ speedAgainX1;
Asteroid5.y = Asteroid5.y + (Math.random() * 20 - 5);//+ speedAgainY1;
}
if (Asteroid5.x > 1100 || Asteroid5.x < -100)
{
Asteroid5.x = Asteroid5.x * -1;
}
if (Asteroid5.y > 800 || Asteroid5.y < -100)
{
Asteroid5.y = - Asteroid5.y * -1;
}
if (Cosmo.hitTestObject(Asteroid6))
{
mySound1.play();
nCount1++;
timer_Text1.text = nCount1.toString();
Asteroid6.y = (Math.random() * 20 - 5);
Asteroid6.x = (Math.random() * 20 - 15);
//Asteroid6.x = Math.floor(Math.random() * 20 - 15);
// Asteroid6.y = Math.floor(Math.random() * 20 - 5);
Asteroid6.x = Asteroid6.x + (Math.random() * 20 - 15);//+ speedAgainX1;
Asteroid6.y = Asteroid6.y + (Math.random() * 20 - 5);//+ speedAgainY1;
}
if (Asteroid6.x > 1100 || Asteroid6.x < -100)
{
Asteroid6.x = - Asteroid6.x * -1;
}
if (Asteroid6.y > 800 || Asteroid6.y < -100)
{
Asteroid6.y = - Asteroid6.y * -1;
}
if (Cosmo.hitTestObject(Asteroid7))
{
mySound1.play();
nCount1++;
timer_Text1.text = nCount1.toString();
Asteroid7.y = (Math.random() * 20 - 5);
Asteroid7.x = (Math.random() * 20 - 15);
Asteroid7.x = Asteroid7.x + (Math.random() * 20 - 15);//+ speedAgainX1;
Asteroid7.y = Asteroid7.y + (Math.random() * 20 - 5);//+ speedAgainY1;
}
if (Asteroid7.x > 1100 || Asteroid7.x < -100)
{
Asteroid7.x = - Asteroid7.x * -1;
}
if (Asteroid7.y > 800 || Asteroid7.y < -100)
{
Asteroid7.y = - Asteroid7.y * -1;
}
if (Cosmo.hitTestObject(Asteroid8))
{
mySound1.play();
nCount1++;
timer_Text1.text = nCount1.toString();
Asteroid8.y = (Math.random() * 20 - 5);
Asteroid8.x = (Math.random() * 20 - 15);
Asteroid8.x = Asteroid8.x + (Math.random() * 20 - 15);//+ speedAgainX1;
Asteroid8.y = Asteroid8.y + (Math.random() * 20 - 5);//+ speedAgainY1;
}
if (Asteroid8.x > 1100 || Asteroid8.x < -100)
{
Asteroid8.x = - Asteroid8.x * -1;
}
if (Asteroid8.y > 800 || Asteroid8.y < -100)
{
Asteroid8.y = - Asteroid8.y * -1;
}
if (Cosmo.hitTestObject(Deathroid1))
{
mySound2.play();
removeEventListener(Event.ENTER_FRAME,massCollect);
removeEventListener(Event.ENTER_FRAME,massGain);
gotoAndStop(352, "Scene 1");
}
if (Cosmo.hitTestObject(Deathroid2))
{
mySound2.play();
removeEventListener(Event.ENTER_FRAME,massCollect);
removeEventListener(Event.ENTER_FRAME,massGain);
gotoAndStop(352, "Scene 1");
}
if (Cosmo.hitTestObject(Deathroid3))
{
mySound2.play();
removeEventListener(Event.ENTER_FRAME,massCollect);
removeEventListener(Event.ENTER_FRAME,massGain);
gotoAndStop(352, "Scene 1");
}
if (nCount1 >= 25)
{
removeEventListener(Event.ENTER_FRAME,massCollect);
removeEventListener(Event.ENTER_FRAME,massGain);
gotoAndStop(351, "Scene 1");
}
}