Pong.PongExample.ResetPlayfield C# (CSharp) Method

ResetPlayfield() public method

public ResetPlayfield ( int loserIndex ) : void
loserIndex int
return void
        public void ResetPlayfield(int loserIndex)
        {
            Paddles = new Paddle[] {
                new Paddle {
                    Bounds = new Bounds(
                        new Vector2(24, Playfield.Bounds.Center.Y - 48),
                        new Vector2(24 + 16, Playfield.Bounds.Center.Y + 48)
                    ),
                    Playfield = this.Playfield
                },
                new Paddle {
                    Bounds = new Bounds(
                        new Vector2(Graphics.PreferredBackBufferWidth - 24 - 16, Playfield.Bounds.Center.Y - 48),
                        new Vector2(Graphics.PreferredBackBufferWidth - 24, Playfield.Bounds.Center.Y + 48)
                    ),
                    Playfield = this.Playfield
                }
            };

            var random = new Random();
            var velocity = new Vector2(loserIndex == 0 ? 1 : -1, (float)random.NextDouble(-1, 1));
            velocity.Normalize();
            if (Math.Abs(velocity.Y) < 0.15f)
                velocity.Y += Math.Sign(velocity.Y) * 0.15f;
            velocity *= 4;

            Ball = new Ball {
                Position = Playfield.Bounds.Center,
                Velocity = velocity,
                Playfield = this.Playfield,
                Radius = 8.0f
            };
        }