Beispiel #1
0
        public virtual void AI(Player ENEMY, SquareGrid GRID)
        {
            rePathTimer.UpdateTimer();

            if (pathNodes == null || (pathNodes.Count == 0 && pos.X == moveTo.X && pos.Y == moveTo.Y) || rePathTimer.Test())
            {
                if (!currentlyPathing)
                {
                    Task repathTask = new Task(() =>
                    {
                        currentlyPathing = true;

                        pathNodes = FindPath(GRID, GRID.GetSlotFromPixel(ENEMY.hero.pos, Vector2.Zero));
                        moveTo    = pathNodes[0];
                        pathNodes.RemoveAt(0);

                        rePathTimer.ResetToZero();

                        currentlyPathing = false;
                    });
                    repathTask.Start();
                }
            }
            else
            {
                MoveUnit();


                if (Globals.GetDistance(pos, ENEMY.hero.pos) < GRID.slotDims.X * 1.2f)
                {
                    ENEMY.hero.GetHit(this, 1);
                    dead = true;
                }
            }
        }
Beispiel #2
0
        public virtual List <Vector2> FindPath(SquareGrid GRID, Vector2 ENDSLOT)
        {
            pathNodes.Clear();


            Vector2 tempStartSlot = GRID.GetSlotFromPixel(pos, Vector2.Zero);


            List <Vector2> tempPath = GRID.GetPath(tempStartSlot, ENDSLOT, true);

            if (tempPath == null || tempPath.Count == 0)
            {
            }


            return(tempPath);
        }