Переместить picturebox не работает
Всем привет, Меня зовут Дэн, и я новичок на форуме
Мой вопрос заключается в следующем.
У меня есть школьный проект, это игра истребитель.
Мне нужно, чтобы мой корабль мог стрелять (PictureBox) с помощью клавиши пробела, поэтому много раз нажмите клавишу пробела, чтобы отправить PictureBox (shoot)
Но я не вижу, где моя ошибка.
Это и есть код:
&низкотемпературный;
Полный проект находится здесь:
https://drive.google.com/file/d/1T_stjuQx-g1_jn0VijbTQ0yij3o0OqCz/view?usp=sharing
Заранее спасибо
DS
Что я уже пробовал:
int indice_Bala = 0; public PictureBox[] pbBala = new PictureBox[1]; public void AgregarBala(PictureBox pbPadre) { Array.Resize(ref pbBala, indice_Bala + 2); pbBala[indice_Bala] = new PictureBox(); pbBala[indice_Bala].Visible = true; pbBala[indice_Bala].Image = Image.FromFile(Application.StartupPath + "\\Cohete.jpg"); pbBala[indice_Bala].Height = 10; pbBala[indice_Bala].Width = 75; pbBala[indice_Bala].Top = pbPadre.Top + (pbPadre.Height / 2); pbBala[indice_Bala].Left = pbPadre.Left + pbPadre.Width; pbBala[indice_Bala].SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.Controls.Add(pbBala[indice_Bala]); indice_Bala++; //Timer Function private void playTimer(object sender, EventArgs e) { //player.Left += moveLeft; PicEne1.Top += enemyMove; PicEne2.Top += enemyMove; PicEne3.Top += enemyMove; PicEne4.Top += enemyMove; PicEne5.Top += enemyMove; LblPuntos.Text = "" + score; for (int i = 0; i < indice_Bala; i++) { pbBala[i].Left = pbBala[i].Left + 20; } if (PicEne1.Top == 660 || PicEne2.Top == 660 || PicEne3.Top == 660 || PicEne4.Top == 660 || PicEne5.Top == 660) { gameOver(); private void Form1_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Up: { if ((PicNave.Location.Y - Distancia) >= 0) PicNave.Location = new Point(PicNave.Location.X, PicNave.Location.Y - Distancia); break; } case Keys.Down: { if ((PicNave.Height + (PicNave.Location.Y + Distancia)) <= ClientSize.Height) PicNave.Location = new Point(PicNave.Location.X, PicNave.Location.Y + Distancia); break; } case Keys.Left: { if ((PicNave.Location.X - Distancia) >= 0) PicNave.Location = new Point(PicNave.Location.X - Distancia, PicNave.Location.Y); break; } case Keys.Right: { if ((PicNave.Width + (PicNave.Location.X + Distancia)) <= ClientSize.Width) PicNave.Location = new Point(PicNave.Location.X + Distancia, PicNave.Location.Y); break; } case Keys.Space: { { AgregarBala(PicNave); break; } } } } }
Dani Solis
Здравствуйте, спасибо за ваш ответ. Еще один вопрос, этот кодовый блок каким он будет в конечном итоге?
Когда "AgregarBala(PicNave)" пересекается с любым PicEnemy, то мой счет затем увеличивается.
Это кодовый блок:
Скрыть Расширять скопировать код
//Funcion Enemigos private void enemyHit() { if (Misil.Bounds.IntersectsWith(PicEne1.Bounds)) { score += 1; PicEne1.Top = -500; int ranP = rnd.Next(1, 300); PicEne1.Left = ranP; shooting = false; bulletSpeed = 0; } else if (Misil.Bounds.IntersectsWith(PicEne2.Bounds)) { score += 1; PicEne2.Top = -900; int ranP = rnd.Next(1, 400); PicEne2.Left = ranP; shooting = false; bulletSpeed = 0; } else if (Misil.Bounds.IntersectsWith(PicEne3.Bounds)) { score += 1; PicEne3.Top = -1300; int ranP = rnd.Next(1, 500); PicEne3.Left = ranP; shooting = false; bulletSpeed = 0; } else if (Misil.Bounds.IntersectsWith(PicEne4.Bounds)) { score += 1; PicEne3.Top = -1300; int ranP = rnd.Next(1, 500); PicEne4.Left = ranP; shooting = false; bulletSpeed = 0; } else if (Misil.Bounds.IntersectsWith(PicEne5.Bounds)) { score += 1; PicEne5.Top = -1300; int ranP = rnd.Next(1, 500); PicEne5.Left = ranP; shooting = false; bulletSpeed = 0; } } //Funcion Juego Terminado private void gameOver() { tmr.Enabled = false; MessageBox.Show("You Score = " + score + " Click OK to play Again"); score = 0; LblPuntos.Text = "0"; PicEne1.Top = -500; PicEne2.Top = -900; PicEne3.Top = -1300; tmr.Enabled = true; }
Заранее спасибо за вас.
DS