我已经编写代码来重置ufo在离开屏幕时的x位置。我已经考虑到了不明飞行物可能发生的一切。 下面是说明如果ufo从屏幕移出的代码,那么ufo的x位置回到0,并且它通过false被关闭。我不知道我还能补充些什么。飞碟移动关闭屏幕,不应当被视为有史以来再次(可怜):(任何帮助重置图像的X位置
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;
}
}
}
}
编辑的代码:以上
您是否正确复制了您的代码?它看起来好像缺少至少一个附加大括号。例如,目前'if(ufo.alive == true)'*在由if(ufo.alive == false)'控制的块内*。既然你说你的UFO向右移动,我猜测你实际运行的代码是不同的。 – 2012-04-25 12:23:54
问题是什么? – neeKo 2012-04-25 12:28:10