Ejemplo n.º 1
0
        //make the player
        private void Player()
        {
            int width  = this.ClientSize.Width;
            int height = this.ClientSize.Height;

            player = new ActiveSprite(width / 2 - 30, height - height / 96, Image.FromFile("images\\Ship.png"), 60, 32, 0, 0);
        }
Ejemplo n.º 2
0
        //spawn the aliens
        private void Aliens()
        {
            int          width     = this.ClientSize.Width;
            int          height    = this.ClientSize.Height;
            int          numAliens = 0;
            int          row       = 1;
            float        alienX    = width / 192;
            float        alienY    = height / 108;
            ActiveSprite alien;

            while (numAliens < 11 && row <= 5)
            {
                if (row == 1)
                {
                    alien = new ActiveSprite(alienX, alienY, Image.FromFile("images\\InvaderC" + one + ".png"), 48, 32, 3, 0);
                }
                else if (row == 2 || row == 3)
                {
                    alien = new ActiveSprite(alienX, alienY, Image.FromFile("images\\InvaderB" + one + ".png"), 48, 32, 3, 0);
                }
                else if (row == 4 || row == 5)
                {
                    alien = new ActiveSprite(alienX, alienY, Image.FromFile("images\\InvaderA" + one + ".png"), 48, 32, 3, 0);
                }
                else
                {
                    alien = new ActiveSprite(alienX, alienY, Image.FromFile("images\\InvaderC1.png"), 48, 32, 0, 0);
                }

                aliens.Add(alien);

                alienX += width / 192 + 48;
                numAliens++;

                if (numAliens >= 11)
                {
                    alienY += 32 + height / 108;
                    alienX  = width / 192;
                    row++;
                    numAliens = 0;
                }
            }
        }
Ejemplo n.º 3
0
 private void T_Tick(object sender, EventArgs e)
 {
     counter++;
     this.Refresh();
     if (aliens.Count == 0)
     {
         won = true;
     }
     for (int i = 0; i < bullets.Count; i++)
     {
         //remove off screen bullets
         if (bullets.ElementAt(i).Y + bullets.ElementAt(i).Height < 0)
         {
             bullets.Remove(bullets.ElementAt(i));
             continue;
         }
         //remove shot aliens
         for (int j = 0; j < aliens.Count; j++)
         {
             if (aliens.ElementAt(j).Contains(bullets.ElementAt(i).X, bullets.ElementAt(i).Y))
             {
                 aliens.Remove(aliens.ElementAt(j));
                 bullets.ElementAt(i).Y = -bullets.ElementAt(i).Height;
                 continue;
             }
         }
     }
     for (int i = 0; i < aliens.Count; i++)
     {
         //let the aliens shoot back
         if (rand.NextDouble() > 0.999)
         {
             ActiveSprite alienBullet = new ActiveSprite(aliens.ElementAt(i).X + 21, aliens.ElementAt(i).Y - aliens.ElementAt(i).Height - 17, Image.FromFile("images\\bullet.png"), 6, 17, 0, 15);
             alienBullets.Add(alienBullet);
         }
     }
     //clear the alien shots
     for (int i = 0; i < alienBullets.Count; i++)
     {
         if (alienBullets.ElementAt(i).Y > ClientSize.Height)
         {
             alienBullets.Remove(alienBullets.ElementAt(i));
             continue;
         }
         if (player.Contains(alienBullets.ElementAt(i).X, alienBullets.ElementAt(i).Y))
         {
             lost = true;
         }
     }
     //check the blocks for shots
     for (int i = 0; i < blocks.Count; i++)
     {
         for (int j = 0; j < bullets.Count(); j++)
         {
             if (blocks.ElementAt(i).Contains(bullets.ElementAt(j).X, bullets.ElementAt(j).X))
             {
                 bullets.ElementAt(i).Y = -bullets.ElementAt(i).Height;
                 continue;
             }
         }
         for (int j = 0; j < alienBullets.Count; j++)
         {
             if (blocks.ElementAt(i).Contains(alienBullets.ElementAt(j).X, alienBullets.ElementAt(j).Y))
             {
                 alienBullets.Remove(alienBullets.ElementAt(j));
                 continue;
             }
         }
     }
     //change alien skins
     if (counter % 33 == 0)
     {
         for (int i = 0; i < aliens.Count; i++)
         {
             if (counter % 2 == 1 && i < 55)
             {
                 aliens.ElementAt(i).Image = Image.FromFile("images\\InvaderA" + two + ".png");
             }
             if (counter % 2 == 0 && i < 55)
             {
                 aliens.ElementAt(i).Image = Image.FromFile("images\\InvaderA" + one + ".png");
             }
             if (counter % 2 == 1 && i < 33)
             {
                 aliens.ElementAt(i).Image = Image.FromFile("images\\InvaderB" + two + ".png");
             }
             if (counter % 2 == 0 && i < 33)
             {
                 aliens.ElementAt(i).Image = Image.FromFile("images\\InvaderB" + one + ".png");
             }
             if (counter % 2 == 1 && i < 11)
             {
                 aliens.ElementAt(i).Image = Image.FromFile("images\\InvaderC" + two + ".png");
             }
             if (counter % 2 == 0 && i < 11)
             {
                 aliens.ElementAt(i).Image = Image.FromFile("images\\InvaderC" + one + ".png");
             }
         }
     }
 }
Ejemplo n.º 4
0
        //let the player fight
        private void Engine_PlayerShoot(object sender, MouseEventArgs e)
        {
            ActiveSprite bullet = new ActiveSprite(player.X + 27, player.Y - 17, Image.FromFile("images\\bullet.png"), 6, 17, 0, -15);

            bullets.Add(bullet);
        }