Defines a goal in the soccer game simulation
Esempio n. 1
0
        public SoccerTeam(SoccerGoal homeGoal, SoccerGoal opponentsGoal, SoccerPitch pitch, SoccerTeamColor color)
        {
            _homeGoal      = homeGoal;
            _opponentsGoal = opponentsGoal;
            _pitch         = pitch;
            _color         = color;

            _opposingTeam = null;
            _distSqToBallOfClosestPlayer = 0.0;
            _supportingPlayer            = null;
            _controllingPlayer           = null;
            _playerClosestToBall         = null;

            _stateMachine = new StateMachine <SoccerTeam>(this);

            _stateMachine.CurrentState  = DefendingState.Instance;
            _stateMachine.PreviousState = DefendingState.Instance;
            _stateMachine.GlobalState   = null;

            //create the players and goalkeeper
            CreatePlayers();

            //set default steering behaviors
            foreach (PlayerBase player in _players)
            {
                player.SteeringBehaviors.Seperation = true;
            }

            _supportSpotCalculator = new SupportSpotCalculator(ParameterManager.Instance.NumSupportSpotsX, ParameterManager.Instance.NumSupportSpotsY, this);
        }
Esempio n. 2
0
        public SoccerTeam(SoccerGoal homeGoal, SoccerGoal opponentsGoal, SoccerPitch pitch, SoccerTeamColor color)
        {
            _homeGoal = homeGoal;
            _opponentsGoal = opponentsGoal;
            _pitch = pitch;
            _color = color;

            _opposingTeam = null;
            _distSqToBallOfClosestPlayer = 0.0;
            _supportingPlayer = null;
            _controllingPlayer = null;
            _playerClosestToBall = null;

            _stateMachine = new StateMachine<SoccerTeam>(this);

            _stateMachine.CurrentState = DefendingState.Instance;
            _stateMachine.PreviousState = DefendingState.Instance;
            _stateMachine.GlobalState = null;

            //create the players and goalkeeper
            CreatePlayers();

            //set default steering behaviors
            foreach (PlayerBase player in _players)
            {
                player.SteeringBehaviors.Seperation = true;
            }

            _supportSpotCalculator = new SupportSpotCalculator(ParameterManager.Instance.NumSupportSpotsX, ParameterManager.Instance.NumSupportSpotsY, this);
        }
Esempio n. 3
0
        public SoccerPitch(double width, double height)
        {
            //int GOAL_WIDTH = 2;
            //double ballSize = .5;
            //double ballMass = 1.0;
            _walls = new List <Wall2D>();

            _clientWidth  = (int)width;
            _clientHeight = (int)height;

            _paused            = false;
            _goalKeeperHasBall = false;
            _gameInPlay        = true;

            //define the playing area
            _playingArea = new Region(20, _clientHeight - 20, 20, _clientWidth - 20);

            //create the regions
            createRegions(_playingArea.Width / (double)NumRegionsHorizontal,
                          _playingArea.Height / (double)NumRegionsVertical);

            //create the goals
            _redGoal = new SoccerGoal(new Vector2D(_playingArea.Left, (_clientHeight - ParameterManager.Instance.GoalWidth) / 2),
                                      new Vector2D(_playingArea.Left, _clientHeight - (_clientHeight - ParameterManager.Instance.GoalWidth) / 2),
                                      new Vector2D(1.0, 0.0));



            _blueGoal = new SoccerGoal(new Vector2D(_playingArea.Right, (_clientHeight - ParameterManager.Instance.GoalWidth) / 2),
                                       new Vector2D(_playingArea.Right, _clientHeight - (_clientHeight - ParameterManager.Instance.GoalWidth) / 2),
                                       new Vector2D(-1, 0));


            //create the soccer ball
            _ball = new SoccerBall(new Vector2D(_clientWidth / 2.0, _clientHeight / 2.0),
                                   ParameterManager.Instance.BallSize,
                                   ParameterManager.Instance.BallMass,
                                   _walls);


            //create the teams
            _redTeam  = new SoccerTeam(_redGoal, _blueGoal, this, SoccerTeam.SoccerTeamColor.Red);
            _blueTeam = new SoccerTeam(_blueGoal, _redGoal, this, SoccerTeam.SoccerTeamColor.Blue);

            //make sure each team knows who their opponents are
            _redTeam.OpposingTeam  = _blueTeam;
            _blueTeam.OpposingTeam = _redTeam;

            //create the walls
            Vector2D TopLeft     = new Vector2D(_playingArea.Left, _playingArea.Top);
            Vector2D TopRight    = new Vector2D(_playingArea.Right, _playingArea.Top);
            Vector2D BottomRight = new Vector2D(_playingArea.Right, _playingArea.Bottom);
            Vector2D BottomLeft  = new Vector2D(_playingArea.Left, _playingArea.Bottom);

            _walls.Add(new Wall2D(BottomLeft, _redGoal.RightPost));
            _walls.Add(new Wall2D(_redGoal.LeftPost, TopLeft));
            _walls.Add(new Wall2D(TopLeft, TopRight));
            _walls.Add(new Wall2D(TopRight, _blueGoal.LeftPost));
            _walls.Add(new Wall2D(_blueGoal.RightPost, BottomRight));
            _walls.Add(new Wall2D(BottomRight, BottomLeft));
        }
Esempio n. 4
0
        public SoccerPitch(double width, double height)
        {
            //int GOAL_WIDTH = 2;
            //double ballSize = .5;
            //double ballMass = 1.0;
            _walls = new List<Wall2D>();

            _clientWidth = (int)width;
            _clientHeight = (int)height;

            _paused = false;
            _goalKeeperHasBall = false;
            _gameInPlay = true;

            //define the playing area
            _playingArea = new Region(20, _clientHeight - 20, 20, _clientWidth - 20);

            //create the regions  
            createRegions(_playingArea.Width / (double)NumRegionsHorizontal,
                          _playingArea.Height / (double)NumRegionsVertical);

            //create the goals
            _redGoal = new SoccerGoal(new Vector2D(_playingArea.Left, (_clientHeight - ParameterManager.Instance.GoalWidth) / 2),
                                   new Vector2D(_playingArea.Left, _clientHeight - (_clientHeight - ParameterManager.Instance.GoalWidth) / 2),
                                   new Vector2D(1.0, 0.0));



            _blueGoal = new SoccerGoal(new Vector2D(_playingArea.Right, (_clientHeight - ParameterManager.Instance.GoalWidth) / 2),
                                    new Vector2D(_playingArea.Right, _clientHeight - (_clientHeight - ParameterManager.Instance.GoalWidth) / 2),
                                    new Vector2D(-1, 0));


            //create the soccer ball
            _ball = new SoccerBall(new Vector2D(_clientWidth / 2.0, _clientHeight / 2.0),
                                     ParameterManager.Instance.BallSize,
                                     ParameterManager.Instance.BallMass,
                                     _walls);


            //create the teams 
            _redTeam = new SoccerTeam(_redGoal, _blueGoal, this, SoccerTeam.SoccerTeamColor.Red);
            _blueTeam = new SoccerTeam(_blueGoal, _redGoal, this, SoccerTeam.SoccerTeamColor.Blue);

            //make sure each team knows who their opponents are
            _redTeam.OpposingTeam = _blueTeam;
            _blueTeam.OpposingTeam = _redTeam;

            //create the walls
            Vector2D TopLeft = new Vector2D(_playingArea.Left, _playingArea.Top);
            Vector2D TopRight = new Vector2D(_playingArea.Right, _playingArea.Top);
            Vector2D BottomRight = new Vector2D(_playingArea.Right, _playingArea.Bottom);
            Vector2D BottomLeft = new Vector2D(_playingArea.Left, _playingArea.Bottom);

            _walls.Add(new Wall2D(BottomLeft, _redGoal.RightPost));
            _walls.Add(new Wall2D(_redGoal.LeftPost, TopLeft));
            _walls.Add(new Wall2D(TopLeft, TopRight));
            _walls.Add(new Wall2D(TopRight, _blueGoal.LeftPost));
            _walls.Add(new Wall2D(_blueGoal.RightPost, BottomRight));
            _walls.Add(new Wall2D(BottomRight, BottomLeft));

        }