/// <summary> /// Invaders are shooting at player. There can be max Wave+1 shots in play area; /// </summary> private void ReturnFire() { if (_invaders.Count <= 0) return; int possibleShots = Wave + 1; int shotsInvadersCanShot = _invaderShots.Count - possibleShots; if (shotsInvadersCanShot > 0 && !(_random.Next(10)< 10 - Wave)) { Point shotLocation; Shot shot; // Select invaders from last row ( only this invaders can shot) var groupedByYPosition = from invader in _invaders group invader by invader.Location.Y into invadersGroups orderby invadersGroups.Key select invadersGroups; var bottomInvaders = groupedByYPosition.Last(); for (int i = 0; i < possibleShots; i++) { Invader invader = bottomInvaders.ElementAt(_random.Next(0, bottomInvaders.Count())); shotLocation = new Point(invader.Location.X, invader.Location.Y + invader.Size.Height / 2); shot = new Shot(shotLocation, Direction.Down); _invaderShots.Add(shot); OnShotMoved(_invaderShots.Last(), false); } } }
public ShotMovedEventArgs(Shot shot, bool disappeared) { Shot = shot; Disappeared = disappeared; }
/// <summary> /// Checks if shot collides with given invader /// </summary> /// <param name="playerShot"></param> /// <param name="invader"></param> /// <returns>True if there is collision</returns> private bool CheckForInvaderCollision(Shot playerShot, Invader invader) { return CollisionHelper.CheckCollision(invader.Area, playerShot.Location); }
/// <summary> /// Checks if shot collides with player /// </summary> /// <param name="enemyShot"></param> /// <returns>True if there is collision</returns> private bool CheckForPlayerCollision(Shot enemyShot) { return CollisionHelper.CheckCollision(_player.Area, enemyShot.Location); }
/// <summary> /// Fire shot in the invaders /// </summary> public void FireShot() { //Check if there is place for next shot if (MaximumPlayerShots <= _playerShots.Count) return; else { // Add new shot Point shotLocation = new Point(_player.Location.X, _player.Location.Y + Player.PlayerSize.Height/2); Shot shot = new Shot(shotLocation, Direction.Up); _playerShots.Add(shot); OnShotMoved(shot, false); } }
public void OnShotMoved(Shot shot, bool disappeared) { var shotMoved = ShotMoved; if (shotMoved != null) shotMoved(this, new ShotMovedEventArgs(shot, disappeared)); }
/// <summary> /// Checks if shot collides with given invader /// </summary> /// <param name="playerShot"></param> /// <param name="invader"></param> /// <returns>True if there is collision</returns> private bool CheckForInvaderCollision(Shot playerShot, Invader invader) { return(CollisionHelper.CheckCollision(invader.Area, playerShot.Location)); }
private void ReturnFire() { if (_invaderShots.Count() > Wave + 1 || _random.Next(10) < 10 - Wave) return; var invaderColumns = from invader in _invaders group invader by invader.Location.X into invaderGroup orderby invaderGroup.Key descending select invaderGroup; var randomGroup = invaderColumns.ElementAt(_random.Next(invaderColumns.Count())); var shooter = randomGroup.Last(); Point shotLocation = new Point(shooter.Area.X + (shooter.Size.Width / 2) - 1, shooter.Area.Bottom); Shot invaderShot = new Shot(shotLocation, Direction.Down); _invaderShots.Add(invaderShot); OnShotMoved(invaderShot, false); }
/// <summary> /// Checks if shot collides with player /// </summary> /// <param name="enemyShot"></param> /// <returns>True if there is collision</returns> private bool CheckForPlayerCollision(Shot enemyShot) { return(CollisionHelper.CheckCollision(_player.Area, enemyShot.Location)); }
public void FireShot() { // This method checks the number of player shots on screen to make sure there aren’t too many, // then it adds a new Shot to the _playerShots collection and fires the ShotMoved event. if (GameOver || PlayerDying || _lastUpdated == DateTime.MinValue) return; if (_playerShots.Count < MaximumPlayerShots) { Shot shotFired = new Shot(new Point(_player.Location.X + (_player.Size.Width / 2) - 1, _player.Location.Y), Direction.Up); _playerShots.Add(shotFired); OnShotMoved(shotFired, false); } }
public ShotMovedEventArgs(Shot shot, bool removed, bool isBomb) { Shot = shot; Removed = removed; IsBomb = isBomb; }
public void FireShot() { if (_playerShots.Count() < MaximumPlayerShots) { Shot shot = new Shot(_player.Location, Direction.Up); _playerShots.Add(shot); OnShotMoved(shot, false); } }
private void InvaderFire(Invader invader) { // Get a point at the bottom center of the invader Point shotLocation = new Point((invader.Area.BottomRight.X + invader.Area.BottomLeft.X) / 2, invader.Area.Bottom); Shot newShot = new Shot(shotLocation, Direction.Down); _invaderShots.Add(newShot); OnShotMoved(newShot, false); }
protected void OnShotMoved(Shot shot, bool disappeared) { EventHandler<ShotMovedEventArgs> shotMoved = ShotMoved; if (shotMoved != null) { shotMoved(this, new ShotMovedEventArgs(shot, disappeared)); } }