<commit_before>using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.Instructions;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;
using FlatRedBall.Math.Geometry;
using FlatRedBall.Localization;



namespace Dodgeball.Screens
{
	public partial class GameScreen
	{
        #region Initialize

        void CustomInitialize()
        {
            InitializeInput();

            SharePlayerReferences();

        }

        private void SharePlayerReferences()
        {
            foreach(var player in this.PlayerList)
            {
                player.AllPlayers = PlayerList;
            }
        }

        private void InitializeInput()
        {
            Player1.InitializeXbox360Controls(InputManager.Xbox360GamePads[0]);
        }

        #endregion

        #region Activity

        void CustomActivity(bool firstTimeCalled)
		{
            CollisionActivity();

#if DEBUG
            DebugActivity();
#endif
        }

#if DEBUG
        private void DebugActivity()
        {
            if(InputManager.Keyboard.KeyPushed(Microsoft.Xna.Framework.Input.Keys.R))
            {
                this.RestartScreen(reloadContent: true);
            }
        }
#endif

        private void CollisionActivity()
        {
            BallVsPlayerCollision();

            BallVsWallsCollision();

            CheckForEndOfGame();
        }

        private void BallVsWallsCollision()
        {

            if(BallInstance.XVelocity < 0 && BallInstance.X < -1920/2.0f)
            {
                BallInstance.XVelocity *= -1;
                BallInstance.CurrentOwnershipState = Entities.Ball.OwnershipState.Free;
            }
            if (BallInstance.XVelocity > 0 && BallInstance.X > 1920 / 2.0f)
            {
                BallInstance.XVelocity *= -1;
                BallInstance.CurrentOwnershipState = Entities.Ball.OwnershipState.Free;
            }

            float top = 300;
            float bottom = -1080 / 2.0f;

            if(BallInstance.YVelocity > 0 && BallInstance.Y > top)
            {
                BallInstance.YVelocity *= -1;
                BallInstance.CurrentOwnershipState = Entities.Ball.OwnershipState.Free;
            }
            if (  BallInstance.YVelocity < 0 && BallInstance.Y < bottom)
            {
                BallInstance.YVelocity *= -1;
                BallInstance.CurrentOwnershipState = Entities.Ball.OwnershipState.Free;
            }
        }

        private void BallVsPlayerCollision()
        {
            if (BallInstance.CurrentOwnershipState == Entities.Ball.OwnershipState.Free)
            {
                foreach (var player in PlayerList)
                {
                    if (player.CollideAgainst(BallInstance))
                    {
                        PerformPickupLogic(player);

                        break;
                    }
                }
            }
            else if (BallInstance.CurrentOwnershipState == Entities.Ball.OwnershipState.Thrown)
            {
                // reverse loop since players can be removed:
                for(int i = PlayerList.Count - 1; i > -1; i--)
                {
                    var player = PlayerList[i];

                    if (BallInstance.ThrowOwner != player && player.CollideAgainst(BallInstance))
                    {
                        PerformGetHitLogic(player);
                    }<commit_msg>Tightened up the collision on level 3.<commit_after>using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.Instructions;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;
using FlatRedBall.Math.Geometry;
using FlatRedBall.Localization;



namespace Dodgeball.Screens
{
	public partial class GameScreen
	{
        #region Initialize

        void CustomInitialize()
        {
            InitializeInput();

            SharePlayerReferences();

        }

        private void SharePlayerReferences()
        {
            foreach(var player in this.PlayerList)
            {
                player.AllPlayers = PlayerList;
            }
        }

        private void InitializeInput()
        {
            Player1.InitializeXbox360Controls(InputManager.Xbox360GamePads[0]);
        }

        #endregion

        #region Activity

        void CustomActivity(bool firstTimeCalled)
		{
            CollisionActivity();

#if DEBUG
            DebugActivity();
#endif
        }

#if DEBUG
        private void DebugActivity()
        {
            if(InputManager.Keyboard.KeyPushed(Microsoft.Xna.Framework.Input.Keys.R))
            {
                this.RestartScreen(reloadContent: true);
            }
        }
#endif

        private void CollisionActivity()
        {
            BallVsPlayerCollision();

            BallVsWallsCollision();

            CheckForEndOfGame();
        }

        private void BallVsWallsCollision()
        {

            if(BallInstance.XVelocity < 0 && BallInstance.X < -1920/2.0f + 30)
            {
                BallInstance.XVelocity *= -1;
                BallInstance.CurrentOwnershipState = Entities.Ball.OwnershipState.Free;
            }
            if (BallInstance.XVelocity > 0 && BallInstance.X > 1920 / 2.0f - 30)
            {
                BallInstance.XVelocity *= -1;
                BallInstance.CurrentOwnershipState = Entities.Ball.OwnershipState.Free;
            }

            float top = 200;
            float bottom = -1080 / 2.0f;

            if(BallInstance.YVelocity > 0 && BallInstance.Y > top)
            {
                BallInstance.YVelocity *= -1;
                BallInstance.CurrentOwnershipState = Entities.Ball.OwnershipState.Free;
            }
            if (  BallInstance.YVelocity < 0 && BallInstance.Y < bottom + 30)
            {
                BallInstance.YVelocity *= -1;
                BallInstance.CurrentOwnershipState = Entities.Ball.OwnershipState.Free;
            }
        }

        private void BallVsPlayerCollision()
        {
            if (BallInstance.CurrentOwnershipState == Entities.Ball.OwnershipState.Free)
            {
                foreach (var player in PlayerList)
                {
                    if (player.CollideAgainst(BallInstance))
                    {
                        PerformPickupLogic(player);

                        break;
                    }
                }
            }
            else if (BallInstance.CurrentOwnershipState == Entities.Ball.OwnershipState.Thrown)
            {
                // reverse loop since players can be removed:
                for(int i = PlayerList.Count - 1; i > -1; i--)
                {
                    var player = PlayerList[i];

                    if (BallInstance.ThrowOwner != player && player.CollideAgainst(BallInstance))
                    {
                        PerformGetHitLogic(player);
                    }
{'fraction_non_alphanumeric': 0.0816727476845355, 'fraction_numerical': 0.011928150435026662, 'mean_word_length': 1.5086237240408307, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1998456', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1773, 'n_words': 331}