SimpleSoccer.Net.SoccerBall.Update C# (CSharp) Method

Update() public method

updates the ball physics, tests for any collisions and adjusts the ball's velocity accordingly
public Update ( ) : void
return void
        public override void Update()
        {
            //keep a record of the old position so the goal::scored method
            //can utilize it for goal testing
            _oldPosition = Position;

            //Test for collisions
            TestCollisionWithWalls(_pitchBoundary);

            //Simulate Prm.Friction. Make sure the speed is positive 
            //first though
            if (Velocity.LengthSquared > ParameterManager.Instance.Friction * ParameterManager.Instance.Friction)
            {
                Velocity += Vector2D.Vec2DNormalize(Velocity) * ParameterManager.Instance.Friction;

                Position += Velocity;



                //update heading
                Heading = Vector2D.Vec2DNormalize(Velocity);
            }
        }
        /// <summary>

Usage Example

Example #1
0
        public void Update()
        {
            if (_paused)
            {
                return;
            }

            //update the balls
            _ball.Update();

            //update the teams
            _redTeam.Update();
            _blueTeam.Update();

            //if a goal has been detected reset the pitch ready for kickoff
            if (_blueGoal.CheckIfGoalScored(_ball) || _redGoal.CheckIfGoalScored(_ball))
            {
                _gameInPlay = false;

                //reset the ball
                _ball.PlaceAtPosition(new Vector2D((double)_clientWidth / 2.0, (double)_clientHeight / 2.0));

                //get the teams ready for kickoff
                _redTeam.FSM.ChangeState(PrepareForKickoffState.Instance);
                _blueTeam.FSM.ChangeState(PrepareForKickoffState.Instance);
            }
        }