/// <summary> /// Copies pending shots to player shots /// </summary> public void IncludePendingShots() { while (PendingShots.Count > 0) { PlayerShots.Add(PendingShots.Dequeue()); } }
/// <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); } }
/// <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(); }
/// <summary> /// Sets the game from the initial state /// </summary> public void InitializeGameStatus() { GameOver = false; Lives = 2; Wave = 0; PlayerShots.Clear(); InvaderShots.Clear(); Invaders.Clear(); }
/// <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; }
private void Awake() { // Initialize rb = GetComponent <Rigidbody2D>(); collider = GetComponent <BoxCollider2D>(); playerShooter = GetComponent <PlayerShots>(); defaultColliderSize = collider.size; screenBorderDetector = FindObjectOfType <ScreenBorderDetector>(); GameManager.Instance.PlayerSpawned(this.gameObject); }
/// <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); } }
/// <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); }
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); } }
/// <summary> /// Remove a player shot /// </summary> public void RemovePlayerShot(UiElement playerShot) { playerShot.Clear(); PlayerShots.Remove(playerShot); }