Cat attacking me

Just want some advise/help. I’ve had my cat (16lbs male, he’s not fat he’s just a unit) for 6 years, and is a Velcro kitty who follows me around everywhere and is always laying with me. Well for the past 6 months he’s started randomly attacking me, to various degrees of aggression. It started with him pouncing on my legs when I’m walking and he just comes out and plays (which I’m fine with). Then it turned into him hiding under the bed and biting my legs/feet when I get into bed. Now most mornings while I’m sitting on the toilet he comes into the bathroom, rubs on my legs with his body and then will bite me multiple times. And I can’t lock him out because we have a sliding barn door that he can open. Sometimes when we’re laying in bed together he’ll get up and just bite the crap out of me. He doesn’t always draw blood but it’s painful. The reason I’m posting tonight is because he just attacked me worse than ever before. He was hiding under the bed and I walked into the bathroom, he chased me in there and jumped up and bit my arm and wrist, drawing blood, called my boyfriend to help me and he took him out of the bathroom. After that I closed the door and was sitting on the toilet, cat comes into the bathroom and is sitting there, I’m not looking at him or talking to him and all of a sudden he launches himself at me biting my leg so bad that it’s already bruised and drawing blood. I cleaned all my bites and they’re no longer bleeding. I don’t know what I’m doing wrong. This cat is not neglected, he’s fed good food, we don’t ignore him or are mean to him. My boyfriend has had cats his whole life and is confused as to the cause of this behavior. Please help, he’s my best buddy and I want to know how to correct this. Thank you.