public FieldPlayer(SoccerTeam homeTeam, int homeRegionIndex, State<FieldPlayer> startState, Vector2D heading, Vector2D velocity, double mass, double maxForce, double maxSpeed, double maxTurnRate, double scale, PlayerBase.PlayerRoles role) : base(homeTeam, homeRegionIndex, heading, velocity, mass, maxForce, maxSpeed, maxTurnRate, scale, role) { _stateMachine = new StateMachine<FieldPlayer>(this); if (startState != null) { _stateMachine.CurrentState = _stateMachine.PreviousState = startState; _stateMachine.GlobalState = GlobalPlayerState.Instance; _stateMachine.CurrentState.Enter(this); } _steeringBehaviors.Seperation = true; //set up the kick regulator _kickRegulator = new Regulator(ParameterManager.Instance.PlayerKickFrequency); }
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); }
public SupportSpotCalculator(int numX, int numY, SoccerTeam team) { Region PlayingField = team.Pitch.PlayingArea; //calculate the positions of each sweet spot, create them and //store them in m_Spots double HeightOfSSRegion = PlayingField.Height * 0.8; double WidthOfSSRegion = PlayingField.Width * 0.9; double SliceX = WidthOfSSRegion / numX; double SliceY = HeightOfSSRegion / numY; double left = PlayingField.Left + (PlayingField.Width - WidthOfSSRegion) / 2.0 + SliceX / 2.0; double right = PlayingField.Right - (PlayingField.Width - WidthOfSSRegion) / 2.0 - SliceX / 2.0; double top = PlayingField.Top + (PlayingField.Height - HeightOfSSRegion) / 2.0 + SliceY / 2.0; _team = team; for (int x = 0; x < (numX / 2) - 1; ++x) { for (int y = 0; y < numY; ++y) { if (_team.Color == SoccerTeam.SoccerTeamColor.Blue) { _supportSpots.Add(new SupportSpot(new Vector2D(left + x * SliceX, top + y * SliceY), 0.0)); } else { _supportSpots.Add(new SupportSpot(new Vector2D(right - x * SliceX, top + y * SliceY), 0.0)); } } } //create the regulator _regulator = new Regulator(ParameterManager.Instance.SupportSpotUpdateFreq); }
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); }
public FieldPlayer(SoccerTeam homeTeam, int homeRegionIndex, State <FieldPlayer> startState, Vector2D heading, Vector2D velocity, double mass, double maxForce, double maxSpeed, double maxTurnRate, double scale, PlayerBase.PlayerRoles role) : base(homeTeam, homeRegionIndex, heading, velocity, mass, maxForce, maxSpeed, maxTurnRate, scale, role) { _stateMachine = new StateMachine <FieldPlayer>(this); if (startState != null) { _stateMachine.CurrentState = _stateMachine.PreviousState = startState; _stateMachine.GlobalState = GlobalPlayerState.Instance; _stateMachine.CurrentState.Enter(this); } _steeringBehaviors.Seperation = true; //set up the kick regulator _kickRegulator = new Regulator(ParameterManager.Instance.PlayerKickFrequency); }
public GoalKeeper(SoccerTeam homeTeam, int homeRegionIndex, State<GoalKeeper> startState, Vector2D heading, Vector2D velocity, double mass, double maxForce, double maxSpeed, double maxTurnRate, double scale) : base(homeTeam, homeRegionIndex, heading, velocity, mass, maxForce, maxSpeed, maxTurnRate, scale, PlayerRoles.GoalKeeper) { _stateMachine = new StateMachine<GoalKeeper>(this); _stateMachine.CurrentState = _stateMachine.PreviousState = startState; _stateMachine.GlobalState = GlobalKeeperState.Instance; _stateMachine.CurrentState.Enter(this); }
public GoalKeeper(SoccerTeam homeTeam, int homeRegionIndex, State <GoalKeeper> startState, Vector2D heading, Vector2D velocity, double mass, double maxForce, double maxSpeed, double maxTurnRate, double scale) : base(homeTeam, homeRegionIndex, heading, velocity, mass, maxForce, maxSpeed, maxTurnRate, scale, PlayerRoles.GoalKeeper) { _stateMachine = new StateMachine <GoalKeeper>(this); _stateMachine.CurrentState = _stateMachine.PreviousState = startState; _stateMachine.GlobalState = GlobalKeeperState.Instance; _stateMachine.CurrentState.Enter(this); }
public PlayerBase(SoccerTeam homeTeam, int homeRegionIndex, Vector2D heading, Vector2D velocity, double mass, double maxForce, double maxSpeed, double maxTurnRate, double scale, PlayerRoles role) : base(homeTeam.Pitch.GetRegion(homeRegionIndex).VectorCenter, scale * 10.0, velocity, maxSpeed, heading, mass, new Vector2D(scale, scale), maxTurnRate, maxForce) { _playerRole = role; _team = homeTeam; _distanceToBallSquared = double.MaxValue; _homeRegionIndex = homeRegionIndex; _kickoffRegionIndex = homeRegionIndex; Vector2D[] player = new Vector2D[4] { new Vector2D(-3, 8), new Vector2D(3, 10), new Vector2D(3, -10), new Vector2D(-3, -8) }; for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++) { _vecPlayerVB.Add(player[vertexIndex]); //set the bounding radius to the length of the //greatest extent if (Math.Abs(player[vertexIndex].X) > BoundingRadius) { BoundingRadius = Math.Abs(player[vertexIndex].X); } if (Math.Abs(player[vertexIndex].Y) > BoundingRadius) { BoundingRadius = Math.Abs(player[vertexIndex].Y); } } //set up the steering behavior class _steeringBehaviors = new SteeringBehaviors(this, Ball); //a player's start target is its start position (because it's just waiting) _steeringBehaviors.Target = _team.Pitch.GetRegion(_homeRegionIndex).VectorCenter; AutoList <PlayerBase> .GetAllMembers().Add(this); _defaultHomeRegionIndex = _homeRegionIndex; }
public PlayerBase(SoccerTeam homeTeam, int homeRegionIndex, Vector2D heading, Vector2D velocity, double mass, double maxForce, double maxSpeed, double maxTurnRate, double scale, PlayerRoles role) : base(homeTeam.Pitch.GetRegion(homeRegionIndex).VectorCenter, scale * 10.0, velocity, maxSpeed, heading, mass, new Vector2D(scale, scale), maxTurnRate, maxForce) { _playerRole = role; _team = homeTeam; _distanceToBallSquared = double.MaxValue; _homeRegionIndex = homeRegionIndex; _kickoffRegionIndex = homeRegionIndex; Vector2D[] player = new Vector2D[4] { new Vector2D(-3, 8), new Vector2D(3, 10), new Vector2D(3, -10), new Vector2D(-3, -8) }; for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++) { _vecPlayerVB.Add(player[vertexIndex]); //set the bounding radius to the length of the //greatest extent if (Math.Abs(player[vertexIndex].X) > BoundingRadius) { BoundingRadius = Math.Abs(player[vertexIndex].X); } if (Math.Abs(player[vertexIndex].Y) > BoundingRadius) { BoundingRadius = Math.Abs(player[vertexIndex].Y); } } //set up the steering behavior class _steeringBehaviors = new SteeringBehaviors(this, Ball); //a player's start target is its start position (because it's just waiting) _steeringBehaviors.Target = _team.Pitch.GetRegion(_homeRegionIndex).VectorCenter; AutoList<PlayerBase>.GetAllMembers().Add(this); _defaultHomeRegionIndex = _homeRegionIndex; }
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)); }
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)); }