Ejemplo n.º 1
0
        // ----------------------------------
        /// <summary>
        /// Safe walk logic- keeps NPC's from stepping to their DOOM
        /// decision making
        /// </summary>
        /// <param name="direction">The direction to walk</param>
        public bool Safe_Walk(Shared.Direction direction)
        {
            host.Direction = direction;

            if (CollisionManager.Safe_Step(host))
            {
                if (CollisionManager.Wall_Collision(host, direction))
                {
                    if (CollisionManager.Jumpable_Terrain(host))
                    {
                        host.Try_Jump();
                    }
                    else if (!host.Airborne)
                    {
                        Turn_Around();
                    }
                }

                host.Try_Walk(direction);
                return(true);
            }
            else if (CollisionManager.Safe_Drop(host))
            {
                host.Try_Walk(direction);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        // ----------------------------------
        /// <summary>
        /// Chase is similar to Smart Movement, but much more reckless.
        /// </summary>
        /// <param name="destination">The destination our host wants to move to</param>
        public void Chase(Vector2 destination, string movement = "walk")
        {
            // ----------------------------------
            bool horizontal_tracking = false;

            Vector2 source_pos = host.Grid_Position;

            Shared.Direction dest_direction = Shared.Direction.NONE;

            // ----------------------------------
            // If the destination X is greater, it's too the right
            if (destination.X > source_pos.X)
            {
                host.Direction      = Shared.Direction.RIGHT;
                dest_direction      = Shared.Direction.RIGHT;
                horizontal_tracking = true;
            }
            // ----------------------------------
            // Less than, it's too the left.
            else if (destination.X < source_pos.X)
            {
                host.Direction      = Shared.Direction.LEFT;
                dest_direction      = Shared.Direction.LEFT;
                horizontal_tracking = true;
            }

            // ----------------------------------
            // Begin tracking toward horizontal destination
            if (horizontal_tracking)
            {
                if (!CollisionManager.Safe_Step(host) && destination.Y <= host.Grid_Position.Y)
                {
                    host.Try_Jump();
                }

                if (movement == "run")
                {
                    host.Try_Run(dest_direction);
                }
                else
                {
                    host.Try_Walk(dest_direction);
                }
                // ----------------------------------
                // We've hit a wall. Jump to see if that resolves our oh so
                // complicated dilemma
                if (CollisionManager.Wall_Collision(host, dest_direction))
                {
                    if (Shared.Active_World.Get_Terrain_At((int)destination.X, (int)destination.Y) == null)
                    {
                        if (CollisionManager.Jumpable_Terrain(host))
                        {
                            host.Try_Jump();
                        }
                    }
                }
            }
        }