public override void DidMoveToView(SpriteKit.SKView view) { base.DidMoveToView(view); Player = new AgentNode(this, DefaultAgentRadius, new CGPoint(Frame.GetMidX(), Frame.GetMidY())); Player.Agent.Behavior = new GKBehavior(); AgentSystem.AddComponent(Player.Agent); SeekGoal = GKGoal.GetGoalToSeekAgent(TrackingAgent); }
public override void DidMoveToView(SpriteKit.SKView view) { base.DidMoveToView (view); Player = new AgentNode (this, DefaultAgentRadius, new CGPoint (Frame.GetMidX (), Frame.GetMidY ())); Player.Agent.Behavior = new GKBehavior (); AgentSystem.AddComponent (Player.Agent); SeekGoal = GKGoal.GetGoalToSeekAgent (TrackingAgent); }
public override void DidMoveToView(SpriteKit.SKView view) { base.DidMoveToView (view); var wanderer = new AgentNode (this, DefaultAgentRadius, new CGPoint (Frame.GetMidX (), Frame.GetMidY ())) { Color = SKColor.Cyan }; wanderer.Agent.Behavior = GKBehavior.FromGoal (GKGoal.GetGoalToWander(10), 100f); AgentSystem.AddComponent (wanderer.Agent); }
AgentNode AddFriend(CGPoint point) { var friend = new AgentNode(this, DefaultAgentRadius, point) { Color = SKColor.Cyan }; AgentSystem.AddComponent(friend.Agent); return(friend); }
public override void DidMoveToView(SpriteKit.SKView view) { base.DidMoveToView(view); var wanderer = new AgentNode(this, DefaultAgentRadius, new CGPoint(Frame.GetMidX(), Frame.GetMidY())) { Color = SKColor.Cyan }; wanderer.Agent.Behavior = GKBehavior.FromGoal(GKGoal.GetGoalToWander(10), 100f); AgentSystem.AddComponent(wanderer.Agent); }
public override void DidMoveToView(SKView view) { base.DidMoveToView(view); var obstacles = new [] { AddObstacle(new CGPoint(Frame.GetMidX(), Frame.GetMidY() + 150f)), AddObstacle(new CGPoint(Frame.GetMidX() - 200f, Frame.GetMidY() - 150f)), AddObstacle(new CGPoint(Frame.GetMidX() + 200f, Frame.GetMidY() - 150f)) }; Player = new AgentNode(this, DefaultAgentRadius, new CGPoint(Frame.GetMidX(), Frame.GetMidY())); Player.Agent.Behavior = new GKBehavior(); AgentSystem.AddComponent(Player.Agent); SeekGoal = GKGoal.GetGoalToSeekAgent(TrackingAgent); Player.Agent.Behavior.SetWeight(100, GKGoal.GetGoalToAvoidObstacles(obstacles, 1)); }
public override void DidMoveToView(SKView view) { base.DidMoveToView (view); var obstacles = new [] { AddObstacle (new CGPoint (Frame.GetMidX (), Frame.GetMidY () + 150f)), AddObstacle (new CGPoint (Frame.GetMidX () - 200f, Frame.GetMidY () - 150f)), AddObstacle (new CGPoint (Frame.GetMidX () + 200f, Frame.GetMidY () - 150f)) }; Player = new AgentNode (this, DefaultAgentRadius, new CGPoint (Frame.GetMidX (), Frame.GetMidY ())); Player.Agent.Behavior = new GKBehavior (); AgentSystem.AddComponent (Player.Agent); SeekGoal = GKGoal.GetGoalToSeekAgent (TrackingAgent); Player.Agent.Behavior.SetWeight (100, GKGoal.GetGoalToAvoidObstacles (obstacles, 1)); }
public override void DidMoveToView(SKView view) { base.DidMoveToView(view); var agents = new List <GKAgent2D> (20); const int agentsPerRow = 4; for (int i = 0; i < agentsPerRow * agentsPerRow; i++) { var x = Frame.GetMidX() + i % agentsPerRow * 20; var y = Frame.GetMidY() + i / agentsPerRow * 20; var boid = new AgentNode(this, 10, new CGPoint(x, y)); AgentSystem.AddComponent(boid.Agent); agents.Add(boid.Agent); boid.DrawsTail = false; } const float separationRadius = 0.553f * 50; const float separationAngle = (float)(3 * Math.PI / 4.0f); const float separationWeight = 10.0f; const float alignmentRadius = 0.83333f * 50; const float alignmentAngle = (float)(Math.PI / 4.0f); const float alignmentWeight = 12.66f; const float cohesionRadius = 1.0f * 100; const float cohesionAngle = (float)(Math.PI / 2.0f); const float cohesionWeight = 8.66f; // Separation, alignment, and cohesion goals combined cause the flock to move as a group. var behavior = new GKBehavior(); behavior.SetWeight(separationWeight, GKGoal.GetGoalToSeparate(agents.ToArray(), separationRadius, separationAngle)); behavior.SetWeight(alignmentWeight, GKGoal.GetGoalToAlign(agents.ToArray(), alignmentRadius, alignmentAngle)); behavior.SetWeight(cohesionWeight, GKGoal.GetGoalToCohere(agents.ToArray(), cohesionRadius, cohesionAngle)); foreach (GKAgent2D agent in agents) { agent.Behavior = behavior; } SeekGoal = GKGoal.GetGoalToSeekAgent(TrackingAgent); }
public override void DidMoveToView(SKView view) { base.DidMoveToView(view); var follower = new AgentNode(this, DefaultAgentRadius, new CGPoint(Frame.GetMidX(), Frame.GetMidY())) { Color = SKColor.Cyan }; var center = new Vector2((float)Frame.GetMidX(), (float)Frame.GetMidY()); var points = new [] { new Vector2(center.X, center.Y + 50), new Vector2(center.X + 50, center.Y + 150), new Vector2(center.X + 100, center.Y + 150), new Vector2(center.X + 200, center.Y + 200), new Vector2(center.X + 350, center.Y + 150), new Vector2(center.X + 300, center.Y), new Vector2(center.X, center.Y - 200), new Vector2(center.X - 200, center.Y - 100), new Vector2(center.X - 200, center.Y), new Vector2(center.X - 100, center.Y + 50), }; var path = GKPath.FromPoints(points, DefaultAgentRadius, true); follower.Agent.Behavior = GKBehavior.FromGoal(GKGoal.GetGoalToFollowPath(path, 1.5, true), 1); AgentSystem.AddComponent(follower.Agent); var cgPoints = new CGPoint[11]; for (var i = 0; i < 10; i++) { cgPoints [i] = new CGPoint(points [i].X, points [i].Y); } cgPoints [10] = cgPoints [0]; var pathShape = SKShapeNode.FromPoints(ref cgPoints [0], 11); pathShape.LineWidth = 2; pathShape.StrokeColor = SKColor.Magenta; AddChild(pathShape); }
public override void DidMoveToView(SpriteKit.SKView view) { base.DidMoveToView (view); Player = new AgentNode (this, DefaultAgentRadius, new CGPoint (Frame.GetMidX (), Frame.GetMidY ())); Player.Agent.Behavior = new GKBehavior (); AgentSystem.AddComponent (Player.Agent); Player.Agent.MaxSpeed *= 1.2f; SeekGoal = GKGoal.GetGoalToSeekAgent (TrackingAgent); Friends = new [] { AddFriend (new CGPoint (Frame.GetMidX () - 150f, Frame.GetMidY ())), AddFriend (new CGPoint (Frame.GetMidX () + 150f, Frame.GetMidY ())) }; SeparateGoal = GKGoal.GetGoalToSeparate (new [] { Player.Agent }, 100f, (float)(Math.PI * 2)); var behavior = GKBehavior.FromGoal (SeparateGoal, 100f); foreach (var friend in Friends) friend.Agent.Behavior = behavior; }
public override void DidMoveToView(SpriteKit.SKView view) { base.DidMoveToView(view); Player = new AgentNode(this, DefaultAgentRadius, new CGPoint(Frame.GetMidX(), Frame.GetMidY())); Player.Agent.Behavior = new GKBehavior(); AgentSystem.AddComponent(Player.Agent); Player.Agent.MaxSpeed *= 1.2f; SeekGoal = GKGoal.GetGoalToSeekAgent(TrackingAgent); Friends = new [] { AddFriend(new CGPoint(Frame.GetMidX() - 150f, Frame.GetMidY())), AddFriend(new CGPoint(Frame.GetMidX() + 150f, Frame.GetMidY())) }; SeparateGoal = GKGoal.GetGoalToSeparate(new [] { Player.Agent }, 100f, (float)(Math.PI * 2)); var behavior = GKBehavior.FromGoal(SeparateGoal, 100f); foreach (var friend in Friends) { friend.Agent.Behavior = behavior; } }
public override void DidMoveToView(SKView view) { base.DidMoveToView (view); var agents = new List<GKAgent2D> (20); const int agentsPerRow = 4; for (int i = 0; i < agentsPerRow * agentsPerRow; i++) { var x = Frame.GetMidX () + i % agentsPerRow * 20; var y = Frame.GetMidY () + i / agentsPerRow * 20; var boid = new AgentNode (this, 10, new CGPoint (x, y)); AgentSystem.AddComponent (boid.Agent); agents.Add (boid.Agent); boid.DrawsTail = false; } const float separationRadius = 0.553f * 50; const float separationAngle = (float)(3 * Math.PI / 4.0f); const float separationWeight = 10.0f; const float alignmentRadius = 0.83333f * 50; const float alignmentAngle = (float)(Math.PI / 4.0f); const float alignmentWeight = 12.66f; const float cohesionRadius = 1.0f * 100; const float cohesionAngle = (float)(Math.PI / 2.0f); const float cohesionWeight = 8.66f; // Separation, alignment, and cohesion goals combined cause the flock to move as a group. var behavior = new GKBehavior (); behavior.SetWeight (separationWeight, GKGoal.GetGoalToSeparate (agents.ToArray (), separationRadius, separationAngle)); behavior.SetWeight (alignmentWeight, GKGoal.GetGoalToAlign (agents.ToArray (), alignmentRadius, alignmentAngle)); behavior.SetWeight (cohesionWeight, GKGoal.GetGoalToCohere (agents.ToArray (), cohesionRadius, cohesionAngle)); foreach (GKAgent2D agent in agents) agent.Behavior = behavior; SeekGoal = GKGoal.GetGoalToSeekAgent (TrackingAgent); }
public override void DidMoveToView(SKView view) { base.DidMoveToView (view); var follower = new AgentNode (this, DefaultAgentRadius, new CGPoint (Frame.GetMidX (), Frame.GetMidY ())) { Color = SKColor.Cyan }; var center = new Vector2 ((float)Frame.GetMidX (), (float)Frame.GetMidY ()); var points = new [] { new Vector2 (center.X, center.Y + 50), new Vector2 (center.X + 50, center.Y + 150), new Vector2 (center.X + 100, center.Y + 150), new Vector2 (center.X + 200, center.Y + 200), new Vector2 (center.X + 350, center.Y + 150), new Vector2 (center.X + 300, center.Y), new Vector2 (center.X, center.Y - 200), new Vector2 (center.X - 200, center.Y - 100), new Vector2 (center.X - 200, center.Y), new Vector2 (center.X - 100, center.Y + 50), }; var path = GKPath.FromPoints (points, DefaultAgentRadius, true); follower.Agent.Behavior = GKBehavior.FromGoal (GKGoal.GetGoalToFollowPath (path, 1.5, true), 1); AgentSystem.AddComponent (follower.Agent); var cgPoints = new CGPoint[11]; for (var i = 0; i < 10; i++) cgPoints [i] = new CGPoint (points [i].X, points [i].Y); cgPoints [10] = cgPoints [0]; var pathShape = SKShapeNode.FromPoints (ref cgPoints [0], 11); pathShape.LineWidth = 2; pathShape.StrokeColor = SKColor.Magenta; AddChild (pathShape); }
AgentNode AddFriend(CGPoint point) { var friend = new AgentNode (this, DefaultAgentRadius, point) { Color = SKColor.Cyan }; AgentSystem.AddComponent (friend.Agent); return friend; }
public void SetAgent(AgentNode node) { currentAgent = node; }
public void ResetTyper() { currentAgent = null; effectNode = null; }