public void DrawBall(Ball ball)
{
if (ball.AttachedRope != null)
DrawRope(ball.AttachedRope);
BallEffect.DiffuseColor = Vector3.One;
if(ball.Player.TeamName != null)
BallEffect.Texture = TeamTextures[ball.Player.TeamName];
Matrix world = Matrix.CreateRotationY((float)(2 * Math.PI * ball.ViewRotation * 50f / 360f)) * Matrix.CreateTranslation(new Vector3(ball.Position, 0));
BallEffect.World = world;
GraveEffect.World = world * Matrix.CreateScale(0.3f);
if (ball.Health > 0)
{
BallModel.Draw(world, Game.Camera.View, Game.Camera.Projection);
var aimTarget = ball.Position + ball.AimDirection * 2;
var aimTargetScreen = WorldToScreen(aimTarget);
var aimRotation = ball.AimDirection.RotationFromDirection();
var effects = SpriteEffects.None;
if (!string.IsNullOrEmpty(ball.HoldingWeapon))
{
var weaponRotation = aimRotation;
if (ball.AimDirection.X < 0)
{
effects = SpriteEffects.FlipHorizontally;
weaponRotation += (float)Math.PI;
}
var weaponPosScreen = WorldToScreen(ball.Position - new Vector2(0, 0.33f));
var weaponTexture = Game.Content.Load<Texture2D>("Textures/" + ball.HoldingWeapon);
var weaponTextureScale = 256f / weaponTexture.Width * (float)Game.Window.ClientBounds.Width / 1920f; //assume the weapon texture was designed for full HD 1080p resolution
// Draw weapon
SpriteBatch.Draw(weaponTexture, position: weaponPosScreen, color: Color.White, rotation: weaponRotation, scale: new Vector2(weaponTextureScale, weaponTextureScale), origin: new Vector2(weaponTexture.Width / 2f, weaponTexture.Height / 2f), effects: effects);
}
if (ball.IsAiming && (!Game.Match.UsePlayerTurns || ball == Game.Match.ActivePlayer?.ActiveBall))
{
int width = (int)(ball.ShootCharge * 100);
var aimIndicator = ball.Position + ball.AimDirection * 2.1f;
var aimIndicatorScreen = WorldToScreen(aimIndicator);
var aimIndicatorSize = new Vector2(width, 20);
if (ball.ShootCharge > 0)
{
var chargeColor = GetChargeColor(ball.ShootCharge);
// Draw charge indicator
SpriteBatch.Draw(WhiteTexture, position: aimIndicatorScreen, scale: new Vector2(100, 20), color: new Color(Color.Black, (int)(64*ball.ShootCharge)), rotation: aimRotation, origin: new Vector2(0, 0.5f));
SpriteBatch.Draw(WhiteTexture, position: aimIndicatorScreen, scale: aimIndicatorSize, color: new Color(chargeColor), rotation: aimRotation, origin: new Vector2(0, 0.5f));
}
// Draw crosshair
SpriteBatch.Draw(CrosshairTexture, position: aimTargetScreen, color: Color.White, rotation: aimRotation, origin: new Vector2(16, 16));
}
}
else // Player is dead
{
GraveModel.Draw(world, Game.Camera.View, Game.Camera.Projection);
}
var screenPos = WorldToScreen(ball.Position + new Vector2(0, 2.5f));
DrawText(ball.Health.ToString("0"), screenPos, 0.5f, Color.White, 1, true, true);
screenPos += new Vector2(0, 25) * resolutionFactor;
DrawText(ball.Name, screenPos, 0.5f, Color.LawnGreen, 1, true, true);
screenPos += new Vector2(0, 25) * resolutionFactor;
DrawText(ball.Player.Name, screenPos, 0.33f, Color.LawnGreen, 1, true, true);
if (Game.Match.UsePlayerTurns && Game.Match.TurnState == TurnState.Running && Game.Match.ActivePlayer == ball.Player && ball.Player.ActiveBall == ball)
{
// Show turn-indicator for a couple of seconds only
if (Game.Match.TurnTime < 4)
{
screenPos -= new Vector2(0, resolutionFactor *(30 + (float)(15 * Math.Sin(5 * ElapsedTime.TotalSeconds))));
SpriteBatch.Draw(Game.Content.Load<Texture2D>("Textures/RedArrow"), screenPos, color: Color.White, origin: new Vector2(29, 38));
}
}
}