示例#1
0
 private void Shoot(bool fromPlayer, int x, int y)
 {
     if (fromPlayer)
     {
         shots temp = new shots();
         temp.shot = new Rectangle(x + person.ship.Width / 2 - 2, y - 10, 3, 10);
         temp.up   = true;
         shotsFired.Add(temp);
         timer1.Start();
     }
     else
     {
         shots temp = new shots();
         temp.shot = new Rectangle(x + 6, y + 15, 3, 10);
         temp.up   = false;
         shotsFired.Add(temp);
     }
 }
示例#2
0
 private void UpdateShots()
 {
     for (int i = 0; i < shotsFired.Count; i++)
     {
         bool  done = false;
         bool  keep = true;
         shots temp = shotsFired[i];
         if (shotsFired[i].up)
         {
             temp.shot.Y -= 8;
             if ((temp.shot.Y - y) / 15 >= 0 && (temp.shot.Y - y) / 15 < 5 && (temp.shot.X - x) / 20 >= 0 && (temp.shot.X - x) / 20 < 11 && invaders[(temp.shot.X - x) / 20][(temp.shot.Y - y) / 15].alive)
             {
                 invaders[(temp.shot.X - x) / 20][(temp.shot.Y - y) / 15].alive = false;
                 keep        = false;
                 score      += 10 * Convert.ToInt32(invaders[(temp.shot.X - x) / 20][(temp.shot.Y - y) / 15].type[5] - '0');
                 label2.Text = Convert.ToString(score);
                 numLeft--;
                 if (numLeft == 0)
                 {
                     x     = 0;
                     right = true;
                     y     = 0;
                     for (int k = 0; k < 11; k++)
                     {
                         for (int j = 4; j >= 0; j--)
                         {
                             invaders[k][j].alive = true;
                         }
                     }
                     numLeft         = 55;
                     timer3.Interval = (int)(.9 * timer3.Interval);
                 }
             }
         }
         else
         {
             temp.shot.Y += 8;
             if (temp.shot.Height + temp.shot.Y > 260 && temp.shot.X < person.x + person.ship.Width && temp.shot.X >= person.x)
             {
                 lives--;
                 label4.Text = Convert.ToString(lives);
                 shotsFired.Clear();
                 done = true;
                 if (lives == 0)
                 {
                     timer3.Stop();
                     timer2.Stop();
                     updateGraphics();
                     panel1.Invalidate();
                     button1.Show();
                     button2.Show();
                     button2.Enabled = true;
                     button1.Enabled = true;
                     button3.Enabled = false;
                     button3.Hide();
                     MessageBox.Show("Game over, you died.");
                     CheckHighScore();
                 }
             }
         }
         if (!done)
         {
             if (temp.shot.Y > panel1.Height || temp.shot.Y < 0 || !keep)
             {
                 shotsFired.RemoveAt(i);
                 i--;
             }
             else
             {
                 shotsFired[i] = temp;
             }
         }
     }
 }