我编写了代码来重置 ufo 离开屏幕时的 x 位置。我已经考虑了不明飞行物可能发生的一切。下面的代码说明如果 ufo 离开屏幕,则 ufo 的 x 位置设置回 0,并通过 false 将其杀死。我不知道我还能补充什么。不明飞行物离开屏幕,再也看不到了(可怜的东西):(有什么帮助吗?
if (ufo.alive == false)
{
Random random = new Random();
int randomNumber = random.Next(0, 100);
{
if (randomNumber == 1)
{
ufo.alive = true;
}
}
{
if (ufo.XPos > 1000)
{
// kill the ufo if it goes off th
ufo.alive = false;
ufo.XPos = 0;
}
}
//make a new one
// here you want to do it randomly .
// so
//int random = random number (you have to do some code to make a random number google it.
//if (random number == 1)
// ufo = new ufo();
// so if you tell it to make a random number between 1 and 1000, then every now and then, 1 will be the number it makes
// fo when it amkes one, and randomnumber is equal to 1, it will make a new ufo.
// i will let you figure out how to do the random bit.
// i guess haha
}
//if ufo is alive
// check for collision
if (ufo.alive == true)
{
// also, we need to make it move
ufo.XPos = ufo.XPos + 1;
if (MissileFired != null)
{
// if you miss, and the ufo carries on, it will go forever.
//so
Rectangle rectMissile = new Rectangle((int)MissileFired.GetPosition().X, (int)MissileFired.GetPosition().Y, MissileImg.Width, MissileImg.Height);
Rectangle rectUFO = new Rectangle(ufo.XPos, 30, UFOImage.Width, UFOImage.Height);
if (rectMissile.Intersects(rectUFO))
{
PlayerScore = PlayerScore + 1000;
// we needed to kill the missile, other wise it gives you a point for every time it goes through.
MissileFired = null;
//now only 1000 points for winning
ExplosionSoundInstance.Play();
ufo.alive = false;
}
}
}
}
编辑代码:以上