예제 #1
0
 public Boid(Vector2 startPosition, Vector2 startVelocity, LBI informationGrid)
 {
     position             = startPosition;
     velocity             = startVelocity;
     this.informationGrid = informationGrid;
     localNeighbours      = new List <Boid>();
 }
예제 #2
0
        public BoidAlgorithmManager()
        {
            allBoids  = new List <Boid>();
            deathGrid = new LBI(Globals.xScreen / Globals.lbiSpaceBetween, Globals.yScreen / Globals.lbiSpaceBetween);
            blockList = new List <Block>();

            viewBlocks = true;

            int offset = 50;

            for (int i = 0; i < 10; i++)
            {
                Block newBlock = new Block(new Rectangle(Globals.rand.Next(offset, Globals.xScreen - offset), Globals.rand.Next(offset, Globals.yScreen - offset),
                                                         Globals.rand.Next(offset, 300), Globals.rand.Next(offset, 300)));

                bool removed = false;

                if (newBlock.position.Contains(new Point(Globals.xScreen / 2, Globals.yScreen / 2)))
                {
                    removed = true;
                }

                if (newBlock.position.Contains(new Point(Globals.xScreen / 2 - offset, Globals.yScreen / 2 - offset)))
                {
                    removed = true;
                }

                if (newBlock.position.Contains(new Point(Globals.xScreen / 2 + offset, Globals.yScreen / 2 - offset)))
                {
                    removed = true;
                }

                if (newBlock.position.Contains(new Point(Globals.xScreen / 2 - offset, Globals.yScreen / 2 + offset)))
                {
                    removed = true;
                }

                if (newBlock.position.Contains(new Point(Globals.xScreen / 2 + offset, Globals.yScreen / 2 + offset)))
                {
                    removed = true;
                }

                if (newBlock.position.Right > Globals.xScreen)
                {
                    removed = true;
                }

                if (newBlock.position.Bottom > Globals.yScreen)
                {
                    removed = true;
                }

                if (!removed)
                {
                    blockList.Add(newBlock);
                }
            }


            blockList.Add(new Block(new Rectangle(300, 300, 100, 100)));
            //allBoids.Add(new Boid(new Vector2(400, 400), new Vector2(0.5f, -0.5f)));
            //allBoids.Add(new Boid(new Vector2(700, 400), new Vector2(-0.5f, -0.5f)));
            //allBoids.Add(new Boid(new Vector2(500, 200), new Vector2(0.5f, 0.4f)));

            //for (int i = 0; i < 100; i++)
            //{
            //    Vector2 randPos = new Vector2(Globals.rand.Next(100, 1100), Globals.rand.Next(100, 600));
            //    Vector2 vel = Vector2.Subtract(new Vector2(Globals.xScreen/2, Globals.yScreen/2), randPos);
            //    vel.Normalize();
            //    Vector2 randVel = Vector2.Multiply(vel, new Vector2((float)(Globals.rand.NextDouble() * 2.0f), (float)(Globals.rand.NextDouble() * 2.0f)));
            //    allBoids.Add(new Boid(randPos, randVel));
            //}

            for (int i = 0; i < 100; i++)
            {
                Vector2 staticPos = new Vector2(Globals.xScreen / 2, Globals.yScreen / 2);
                Vector2 randVel   = new Vector2((float)(Globals.rand.NextDouble() * 2.0f) - 1.0f, (float)(Globals.rand.NextDouble() * 2.0f) - 1.0f);
                allBoids.Add(new Boid(staticPos, randVel, deathGrid));
            }
        }