Beispiel #1
0
 public void FireShot()
 {
     if (playerShots.Count < 2)
     {
         Shot newShot = new Shot(
             new Point((playerShip.Location.X + (playerShip.image.Width / 2))
                 , playerShip.Location.Y),
             Direction.Up, formArea);
         playerShots.Add(newShot);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Return fire method
        /// </summary>
        private void returnFire()
        {
            //// invaders check their location and fire at the player
            if (invaderShots.Count == wave)
            {
                return;
            }
            if (random.Next(10) < (10 - wave))
            {
                return;
            }

            if (wave != bossWave)
            {
                var invaderColumns =
                    from invader in invaders
                    group invader by invader.Location.X into columns
                    select columns;

                int randomColumnNumber = random.Next(invaderColumns.Count());
                var randomColumn       = invaderColumns.ElementAt(randomColumnNumber);

                var invaderRow =
                    from invader in randomColumn
                    orderby invader.Location.Y descending
                    select invader;

                Invader shooter         = invaderRow.First();
                Point   newShotLocation = new Point
                                              (shooter.Location.X + (shooter.Area.Width / 2),
                                              shooter.Location.Y + shooter.Area.Height);

                Shot newShot = new Shot(newShotLocation, Direction.Down,
                                        formArea);
                invaderShots.Add(newShot);
            }
            else
            {
                if (bossShots.Count > 10)
                {
                    return;
                }

                int randomNo = random.Next(3);

                Point newShotLocation = new Point(boss.Location.X + (boss.Area.Width / 2),
                                                  boss.Location.Y + boss.Area.Height - 35);

                // Different shooting patterns for boss
                switch (randomNo)
                {
                case 1:
                {
                    Shot newBossShot  = new Shot(newShotLocation, Direction.Down, formArea);
                    Shot newBossShot2 = new Shot(newShotLocation, Direction.Down20L, formArea);
                    Shot newBossShot3 = new Shot(newShotLocation, Direction.Down20R, formArea);

                    bossShots.Add(newBossShot);
                    bossShots.Add(newBossShot2);
                    bossShots.Add(newBossShot3);

                    break;
                }

                case 2:
                {
                    Shot newBossShot  = new Shot(newShotLocation, Direction.Down, formArea);
                    Shot newBossShot2 = new Shot(newShotLocation, Direction.Down20L, formArea);
                    Shot newBossShot3 = new Shot(newShotLocation, Direction.Down20R, formArea);
                    Shot newBossShot4 = new Shot(newShotLocation, Direction.Down40L, formArea);
                    Shot newBossShot5 = new Shot(newShotLocation, Direction.Down40R, formArea);

                    bossShots.Add(newBossShot);
                    bossShots.Add(newBossShot2);
                    bossShots.Add(newBossShot3);
                    bossShots.Add(newBossShot4);
                    bossShots.Add(newBossShot5);

                    break;
                }
                }
            }
        }
Beispiel #3
0
        private void returnFire()
        {
            //// invaders check their location and fire at the player
            if (invaderShots.Count == wave)
                return;
            if (random.Next(10) < (10 - wave))
                return;

            var invaderColumns =
                from invader in invaders
                group invader by invader.Location.X into columns
                select columns;

            int randomColumnNumber = random.Next(invaderColumns.Count());
            var randomColumn = invaderColumns.ElementAt(randomColumnNumber);

            var invaderRow =
            from invader in randomColumn
            orderby invader.Location.Y descending
            select invader;

            Invader shooter = invaderRow.First();
            Point newShotLocation = new Point
                (shooter.Location.X + (shooter.Area.Width / 2),
            shooter.Location.Y + shooter.Area.Height);

            Shot newShot = new Shot(newShotLocation, Direction.Down,
            formArea);
            invaderShots.Add(newShot);
        }