Example #1
0
 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);
 }
Example #2
0
 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);
 }
Example #3
0
 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);
 }
Example #4
0
        AgentNode AddFriend(CGPoint point)
        {
            var friend = new AgentNode(this, DefaultAgentRadius, point)
            {
                Color = SKColor.Cyan
            };

            AgentSystem.AddComponent(friend.Agent);
            return(friend);
        }
Example #5
0
        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);
        }
Example #6
0
        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));
        }
Example #7
0
        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));
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
        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;
        }
Example #11
0
        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;
            }
        }
Example #12
0
        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);
        }
Example #13
0
        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);
        }
Example #14
0
 AgentNode AddFriend(CGPoint point)
 {
     var friend = new AgentNode (this, DefaultAgentRadius, point) {
         Color = SKColor.Cyan
     };
     AgentSystem.AddComponent (friend.Agent);
     return friend;
 }
Example #15
0
 public void SetAgent(AgentNode node)
 {
     currentAgent = node;
 }
Example #16
0
 public void ResetTyper()
 {
     currentAgent = null;
     effectNode   = null;
 }