public bool CheckIfGoalScored(SoccerBall ball) { bool scored = Geometry.LineIntersection2D(ball.Position, ball.OldPosition, _leftPost, _rightPost); if( scored ) { _goalsScored++; } return scored; }
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); } }