C# Space Shooter Game - Windows Forms
<p>I've created a space shooting game for my degree. I have created 3 classes; an Alien class, a Bullet class and a Ship class which all use Rectangles. I've got the Alien to bounce around within my form and am able to move the spaceship around the form using the mouse. I would now like to get the Alien ship to shoot bullets from itself. I'm a bit stuck with this as I guess I would need to set the bullet recatangle location to the same location as the Alien rectangle? Any ideas on how I could do this? I can upload the code if anyone needs it.</p>

<pre><code>namespace ArkanoidGame
{
public partial class Form1 : Form
{
    Graphics paper;
    Ship ship = new Ship();
    Alien alien = new Alien();
    Random randFuel = new Random();
    Fuel fuel;
    Bullet bullet = new Bullet();

    int score = 0;      



    public Form1()
    {
        InitializeComponent();
        fuel = new Fuel(randFuel);
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        paper = e.Graphics;

        ship.drawShip(paper);  //paints the ship on the form

        alien.drawAlien(paper); //paints the alien on the form

        fuel.drawFuel(paper); //paints the fuel on the form

        bullet.drawBullet(paper);


            if (ship.ShipRec.IntersectsWith(fuel.fuelRec)) //If the ship rectangle intersects with the fuel rectangle then 10 points is added to the score
            {
                fuel.fuelLocation(randFuel);
                score += 10;                    
                scoreLabel.Text = Convert.ToString(score);              

            }




    }

    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        ship.moveShip(e.X, e.Y);
        //this.Invalidate();

    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        alien.moveAlien();
        alien.collideWall();
        bullet.moveBullet();
        this.Refresh();
        this.Invalidate();

    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }




}
</code></pre>

<p>}</p>

<pre><code> namespace ArkanoidGame
 {
 public class Alien
 {


    public int x, y, width, height;
    private int xspeed, yspeed;
    private Random randomSpeed;
    public int alienPos { get; }



    private Image alienImage;    //Add alien to the image class
    public Rectangle alienRec;

    //Property
    public Rectangle AlienRec
    {
        get { return alienRec; }
    }

    //Constructor
    public Alien()
    {
        randomSpeed = new Random();
        x = 800;
        y = 100;
        width = 50;
        height = 40;



        xspeed = randomSpeed.Next(3, 5);
        yspeed = randomSpeed.Next(3, 5);

        alienImage = Image.FromFile("E:\\C#/MyArkanoidGame/alien.png");

        alienRec = new Rectangle(x, y, width, height);


    }

    //Methods

    public void drawAlien(Graphics paper)
    {
        paper.DrawImage(alienImage, alienRec);
    }

    public void moveAlien()
    {
        //alienRec.X += xspeed;
        //alienRec.Y += yspeed;

    }

    public void collideWall()
    {
        if (alienRec.X &gt; 900)
        {
            xspeed += -1;
        }
        if (alienRec.Y &gt; 480)
        {
            yspeed += -1;
        }
        if (alienRec.X &lt; 0)
        {
            xspeed += +1;
        }
        if (alienRec.Y &lt; 0)
        {
            yspeed += +1;
        }
    }




}
</code></pre>

<p>}</p>

<pre><code>  namespace ArkanoidGame
  {
  public class Bullet
  {


    private int x, y, width, height;


    private Image bulletImage;    //Add bullet to the image class
    private Rectangle bulletRec;

    //Property
    public Rectangle BulletRec
    {
        get { return bulletRec; }
    }

    //Constructor
    public Bullet()
    {

        width = 8;
        height = 8;

        bulletImage = Image.FromFile("E:\\C#/MyArkanoidGame/bullet.png");

        bulletRec = new Rectangle(x, y, width, height);
    }

    //Methods

    public void drawBullet(Graphics paper)
    {
        paper.DrawImage(bulletImage, bulletRec);
    }

    public void moveBullet()
    {

    }

}
</code></pre>

<p>}</p>
