public void AddTeamPlayer(Player player) { players.Add(player); }
/// <summary> /// Handles the end of a shot animation. /// </summary> /// <param name="p">Player who took the shot</param> /// <param name="x">X coordinate of the shot</param> /// <param name="y">Y coordinate of the shot</param> /// <param name="s">SightsControl being fired</param> public void ShotEnded(Player p, float x, float y, SightsControl s) { // Remove the control. MainCanvas.Children.Remove(s); // Locking here prevents concurrence from the network listener. lock (this.players) { if (p.PlayerActive && hitSkeleton.DamageTaken < 1.0) { float pX = x * (float)this.ActualWidth; float pY = y * (float)this.ActualHeight; // Build bullet polygon. Polygon pol = new Polygon(); pol.Points = hitSkeleton.RegularPolygonToPointCollection(new Vector2(pX, pY), (float)p.Sights.ActualWidth * 0.5f, 15); // Check for weapon hits. if (Tools.IsPolygonColliding(pol, hitSkeleton.PaddleRight.Shape)) { hitSkeleton.PaddleRight.State = PaddleState.Hit; SetFlyout("DEFEND!", pX, pY, Brushes.MidnightBlue); p.Status = ShotStatus.Defend; } else if (Tools.IsPolygonColliding(pol, hitSkeleton.PaddleLeft.Shape)) { hitSkeleton.PaddleLeft.State = PaddleState.Hit; SetFlyout("DEFEND!", pX, pY, Brushes.MidnightBlue); p.Status = ShotStatus.Defend; } // Possible body part hits. else { var hitParts = hitSkeleton.BodyParts.Where(pa => pa.Key != HitSkeletonBodyPart.ForearmRight && pa.Key != HitSkeletonBodyPart.ForearmLeft && Tools.IsPolygonColliding(pa.Value.Shape, pol)); BodyPart part = hitParts.FirstOrDefault(pa => pa.Value.State == BodyPartState.NotHit).Value; // Only one part may be hit per shot, but precedence is // always given to parts that haven't been shot before. if (part != null) { part.State = BodyPartState.Hit; SetFlyout("HIT!", pX, pY, Brushes.MidnightBlue); p.Status = ShotStatus.Hit; } // A part previously hit was hit again. else if (hitParts.Count() > 0) { SetFlyout("HIT!", pX, pY, Brushes.MidnightBlue); p.Status = ShotStatus.Hit; } // Nothing was hit. else { SetFlyout("MISSED!", pX, pY, Brushes.MidnightBlue); p.Status = ShotStatus.Miss; } } // Build response to server. StringBuilder response = new StringBuilder(""); foreach (Player pl in this.players) { // Current shot player. if (p == pl) { switch (pl.Status) { case ShotStatus.Defend: response.Append("3,"); break; case ShotStatus.Hit: response.Append("2,"); break; case ShotStatus.Miss: response.Append("1,"); break; case ShotStatus.None: response.Append("0,"); break; } pl.Status = ShotStatus.None; } // Other players. else { // If player is active. if (pl.PlayerActive) { response.Append("0,"); } // If player is not active. else { response.Append("-1,"); } } } // Append player health to response and send it. float damage = hitSkeleton.DamageTaken; response.Append(damage); ws.Send(response.ToString()); } } }