我添加了一个专门用于导弹的类。代码如下所示:
class Missile
{
Vector2 Position;
public Missile(int XInitialPos, int YInitialPos)
{
Position = new Vector2(XInitialPos, YInitialPos);
}
public void Move()
{
Position.Y = Position.Y - 8;
}
public void MoveMissile()
{
Position.Y = Position.Y + 8;
}
public Vector2 GetPosition()
{
return Position;
}
}
我知道如何调用 move 方法使发射器射击,但是,我不知道如何随机调用某些东西来使入侵者射击。任何帮助,将不胜感激。谢谢你。
code which invokes launcher to shoot in the update method:
if (MissileFired != null && MissileFired.GetPosition().Y < 20) MissileFired = null;
if (Keyboard.GetState().IsKeyDown(Keys.Space) && MissileFired == null)
{
MissileFired = new Missile(LauncherXPos, 650);
}