Making a scrolling space shooting video game in C# where the player will fight one on one with their opponent. I was able to figure out how to make the missile go up if the opponent was above the player. But, I can't seem to make it work if the opponent is below or right infront of the player. Can someone help me? I know the answer is right under my nose.
The function below handles the movement of the missile
void movemissile()
{
foreach (Control y in this.Controls)
{
if (y is PictureBox && y.Tag == "missile")
{
//y.Left += 100;//x.Top -= 10;
if (y.Left > enemy.Left)//<100
{
y.Left += 10;
//this.Controls.Remove(y);
}
//plyer missile goes up if opponent is above
if (y.Top > enemy.Top)
{
y.Left += 10;
y.Top -= 20;
y.Left += 10;
//this.Controls.Remove(y);
}
y.Left += 100;//x.Top -= 10;
if (y.Top > enemy.Left)//<100
{
this.Controls.Remove(y);
}
}
}
}
This function handles drawing the missile of the player for the game.
void Missile()
{
PictureBox m = new PictureBox();
m.SizeMode = PictureBoxSizeMode.AutoSize;
m.Image = Properties.Resources.Missile1;
m.BackColor = System.Drawing.Color.Transparent;
m.Tag = "missile";
m.Left = Player.Left + 100;//moves bullet left or right
m.Top = Player.Top + 55;//55 is perfect
this.Controls.Add(m);
m.BringToFront();
}