コード例 #1
0
        private void CheckPath()
        {
            Character character = Game1.objectHandler.SearchFirst <Character>();

            if (PathFinding.FindPath(PathFinding.ConvertToTile(parent.slave.bounds.Center), PathFinding.ConvertToTile(character.bounds.Center)) != null)
            {
                parent.Push(new MeleeAttack());
            }
        }
コード例 #2
0
        public override void Update(GameTime gt)
        {
            Character character = Game1.objectHandler.SearchFirst <Character>();

            if (PathFinding.ConvertToTile(character.bounds.Center) != CurrentTargetTile)
            {
                CurrentTargetTile = PathFinding.ConvertToTile(character.bounds.Center);
                Point boundLocationTile = PathFinding.ConvertToTile(parent.slave.bounds.Center);
                path = PathFinding.FindPath(boundLocationTile, CurrentTargetTile);
            }
            else
            {
                parent.Pop();
            }

            if (path != null)
            {
                if (path.Count > 0)
                {
                    Point movingTo = path[path.Count - 1];
                    path.RemoveAt(path.Count - 1);
                    PreviousTile = parent.slave.bounds.Location;


                    int offsetSize = (Walls.wallSize - parent.slave.bounds.Width) / 2;


                    NextTile = (movingTo.ToVector2() * Walls.wallSize).ToPoint() + new Point(RoomShower.roomOffset) + new Point(offsetSize);

                    parent.Push(new TileMovingAI(PreviousTile, NextTile));
                }
            }


            //float temp = vector.X;
            //vector.X = vector.Y;
            //vector.Y = -temp;



            if (parent.slave.vector != Vector2.Zero)
            {
                parent.slave.vector.Normalize();
                parent.slave.vector          *= speed;
                parent.slave.bounds.Location += parent.slave.vector.ToPoint();
            }
        }