Exemplo n.º 1
0
        private void createExploreTargets()
        {
            List <string> keys     = graph.keys;
            int           maxIndex = keys.Count - 1;

            for (int i = 0; i < ammounOfTargets; i++)
            {
                string        key      = keys[random.Next(0, maxIndex)];
                Vector2D      location = graph.vertexMap[key].position;
                ExploreTarget target   = new ExploreTarget(location.X, location.Y);
                if (exploreTargets.Contains(target))
                {
                    i--;
                    continue;
                }
                exploreTargets.Add(target);
            }

            bool created = false;

            while (!created)
            {
                string        key    = keys[random.Next(0, maxIndex)];
                Vector2D      loc    = graph.vertexMap[key].position;
                ExploreTarget target = new ExploreTarget(loc.X, loc.Y);
                if (exploreTargets.Contains(target))
                {
                    continue;
                }
                home    = target;
                created = true;
            }
        }
Exemplo n.º 2
0
        private void populate()
        {
            path = new Path(this);

            //Hunter
            hunter = new Hunter(new Vector2D(50, 50), this, 75f);
            hunter.SteeringBehaviors = new List <SteeringBehaviour>();
            hunter.SteeringBehaviors.Add(new CollisionAvoidanceBehaviour(hunter, 1, Objects, 5));
            movingEntities.Add(hunter);

            //Player
            player                   = new Player(new Vector2D(100, 60), this);
            player.VColor            = Color.DarkRed;
            player.Scale             = 15;
            player.Pos               = new Vector2D(200, 100);
            player.SteeringBehaviors = new List <SteeringBehaviour>();
            player.SteeringBehaviors.Add(new CollisionAvoidanceBehaviour(player, 20, Objects, 25));



            //Add imps
            for (int i = 0; i < amountOfImps; i++)
            {
                int X   = random.Next(0, Width - 100);
                int Y   = random.Next(0, Height - 100);
                int R   = random.Next(0, 255);
                int G   = random.Next(0, 255);
                int B   = random.Next(0, 255);
                Imp imp = new Imp(new Vector2D(X, Y), this);
                imp.color             = Color.FromArgb(255, R, G, B);
                imp.SteeringBehaviors = new List <SteeringBehaviour>();
                imp.SteeringBehaviors.Add(new WanderBehaviour(imp, random));
                imp.SteeringBehaviors.Add(new HideBehaviour(imp, hunter, Objects, 250));
                imp.SteeringBehaviors.Add(new CollisionAvoidanceBehaviour(imp, 20, Objects, 50));
                imp.SteeringBehaviors.Add(new EntityAvoidanceBehaviour(imp, movingEntities));
                movingEntities.Add(imp);
            }

            movingEntities.Add(player);

            home         = new ExploreTarget(Width / 2, Height / 2);
            home.visited = false;
        }
Exemplo n.º 3
0
        private void getNextExploreTarget()
        {
            float oldDist = float.MaxValue;
            List <ExploreTarget> targets = movingEntity.MyWorld.exploreTargets;

            foreach (ExploreTarget target in targets)
            {
                if (target.visited)
                {
                    continue;
                }

                float distance = (float)movingEntity.Pos.Distance(target.position);

                if (distance < oldDist)
                {
                    exploreTarget = target;
                    oldDist       = distance;
                }
            }

            Path   path      = pfBehaviour.path;
            string beginning = path.getNearestVertex(movingEntity.Pos);
            string destination;

            if (exploreTarget != null)
            {
                destination = path.getNearestVertex(exploreTarget.position);
            }
            else
            {
                exploreTarget = movingEntity.MyWorld.home;
                destination   = path.getNearestVertex(exploreTarget.position);
            }

            if (beginning != "notfound" && destination != "notfound")
            {
                path.bestPath = path.FindBestPath(beginning, destination);
                findXT        = true;
            }
        }
Exemplo n.º 4
0
        private void getForce(ref Vector2D force)
        {
            force = pfBehaviour.Calculate();
            if (pfBehaviour.arrived)
            {
                pfBehaviour.arrived   = false;
                exploreTarget.visited = true;

                if (!movingEntity.MyWorld.home.visited)
                {
                    findXT = false;
                }
                else
                {
                    force = new Vector2D();
                    movingEntity.Velocity          = new Vector2D();
                    movingEntity.SteeringBehaviors = new List <SteeringBehaviour>();
                }

                exploreTarget             = null;
                pfBehaviour.path.bestPath = null;
            }
        }