Пример #1
0
 /// <summary>
 /// Copies pending shots to player shots
 /// </summary>
 public void IncludePendingShots()
 {
     while (PendingShots.Count > 0)
     {
         PlayerShots.Add(PendingShots.Dequeue());
     }
 }
Пример #2
0
        /// <summary>
        ///     Removes all shots went out of bounds
        /// </summary>
        public void RemoveOutOfBoundShots(double playerShotsBound, double invadorShotBound)
        {
            var outOfBoundsPlayerShots = (from shot in PlayerShots
                                          where shot.Location.Y < playerShotsBound
                                          select shot).ToList();


            var outOfBoundsInvadersShots =
                (from shot in InvaderShots
                 where shot.Location.Y > invadorShotBound
                 select shot).ToList();

            if (outOfBoundsPlayerShots != null)
            {
                foreach (var shot in outOfBoundsPlayerShots)
                {
                    PlayerShots.Remove(shot);
                    TriggerShotMoved(shot, true);
                }
            }

            if (outOfBoundsInvadersShots == null)
            {
                return;
            }


            foreach (var shot in outOfBoundsInvadersShots)
            {
                InvaderShots.Remove(shot);
                TriggerShotMoved(shot, true);
            }
        }
Пример #3
0
 /// <summary>
 /// Handles the variables when the player spawns
 /// </summary>
 public void PlayerSpawned(GameObject player)
 {
     latestPlayerShots = player.GetComponent <PlayerShots>();
     score             = 0;
     UIManager.Instance.ShowScore();
     UIManager.Instance.ShowKnifesCount();
     UIManager.Instance.ShowBombsCount();
 }
Пример #4
0
 /// <summary>
 ///     Sets the game from the initial state
 /// </summary>
 public void InitializeGameStatus()
 {
     GameOver = false;
     Lives    = 2;
     Wave     = 0;
     PlayerShots.Clear();
     InvaderShots.Clear();
     Invaders.Clear();
 }
Пример #5
0
 /// <summary>
 /// Handles the player's death
 /// </summary>
 public void PlayerDeath(GameObject player)
 {
     UIManager.Instance.HideScore();
     UIManager.Instance.HideKnifesCount();
     UIManager.Instance.HideBombsCount();
     UIManager.Instance.ShowDeathMenu(score);
     player.SetActive(false);
     latestPlayerShots = null;
 }
Пример #6
0
        private void Awake()
        {
            // Initialize
            rb                   = GetComponent <Rigidbody2D>();
            collider             = GetComponent <BoxCollider2D>();
            playerShooter        = GetComponent <PlayerShots>();
            defaultColliderSize  = collider.size;
            screenBorderDetector = FindObjectOfType <ScreenBorderDetector>();

            GameManager.Instance.PlayerSpawned(this.gameObject);
        }
Пример #7
0
 /// <summary>
 ///     Removes all the shots from the screen
 /// </summary>
 public void RemoveShots()
 {
     foreach (var shot in PlayerShots.ToList())
     {
         PlayerShots.Remove(shot);
         TriggerShotMoved(shot, true);
     }
     foreach (var shot in InvaderShots.ToList())
     {
         InvaderShots.Remove(shot);
         TriggerShotMoved(shot, true);
     }
 }
Пример #8
0
        /// <summary>
        ///     Creates a rocket shot by the player
        /// </summary>
        public void RocketShot(Point startingPoint)
        {
            if (GameOver)
            {
                return;
            }
            if (PlayerShots.Count >= MaximumPlayerShots)
            {
                return;
            }

            var shot = new Shot(startingPoint, Direction.Up, ShotType.Rocket);

            PlayerShots.Add(shot);
            TriggerShotMoved(shot, false);
        }
Пример #9
0
        public void CheckForInvaderHit()
        {
            if (_isPlayerDead)
            {
                return;
            }

            var shotsHit       = new List <Shot>();
            var invadersKilled = new List <Invader>();

            foreach (var shot in PlayerShots)
            {
                var invadersShot = (from invader in Invaders
                                    where invader.Area.Contains(shot.Location) && shot.Direction == Direction.Up
                                    select new { InvaderKilled = invader, ShotHit = shot }).ToList();

                if (!invadersShot.Any())
                {
                    continue;
                }

                foreach (var invadershot in invadersShot)
                {
                    shotsHit.Add(invadershot.ShotHit);
                    invadersKilled.Add(invadershot.InvaderKilled);
                }
            }
            foreach (var invader in invadersKilled)
            {
                Score += invader.Score;
                Invaders.Remove(invader);
                TriggerShipChanged(invader, true);
            }
            foreach (var shot in shotsHit)
            {
                PlayerShots.Remove(shot);
                TriggerShotMoved(shot, true);
            }
        }
Пример #10
0
 /// <summary>
 /// Remove a player shot
 /// </summary>
 public void RemovePlayerShot(UiElement playerShot)
 {
     playerShot.Clear();
     PlayerShots.Remove(playerShot);
 }