Ejemplo n.º 1
0
        public static bool TargetBasedMove(NPC npc, Player target, bool playerRange = false)
        {
            int     width  = Main.screenWidth - 100;
            int     height = Main.screenHeight - 100;
            Vector2 old    = npc.position;
            Vector2 vector;

            if (target == null)
            {
                return(false);
            }
            vector = FindGround(npc, new Rectangle((int)target.position.X - width / 2, (int)target.position.Y - height / 2, width, height));
            if (!MagnoDen.Inbounds((int)vector.X / 16, (int)vector.Y / 16))
            {
                return(false);
            }
            if (vector != Vector2.Zero)
            {
                npc.position = vector;
            }
            if (old != npc.position)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public static Vector2 FindGround(Player player, Rectangle bounds)
        {
            var vector = FindEmptyRegion(player, bounds);

            for (int k = 0; k < 5; k++)
            {
                int i = (int)vector.X / 16;
                int j = (int)(vector.Y + player.height + 8) / 16;
                if (!MagnoDen.Inbounds(i, j))
                {
                    continue;
                }
                int count = 0;
                int max   = player.width / 16;
                for (int l = 0; l < player.width / 16; l++)
                {
                    Tile ground = Main.tile[i + l, j + 1];
                    if (ground.active() && Main.tileSolid[ground.type])
                    {
                        count++;
                    }
                }
                while (vector.Y + player.height < j * 16)
                {
                    vector.Y++;
                }
                if (Collision.SolidCollision(vector, player.width - 4, player.height - 4))
                {
                    return(Vector2.Zero);
                }
                if (count == max)
                {
                    return(vector);
                }
            }
            return(Vector2.Zero);
        }