Someone I can’t get rid of.

There’s a guy that has liked me since middle school & we’ve always been close friends. We are juniors & I’ve made it clear that I don’t feel the same way he does. He is becoming very annoying. However, I can’t block him, I can’t tell him we’re not friends, I can’t ignore his messages because he’ll blow up my phone or follow me around school asking why I’m mad. Worst thing is that I have a class with him (also the longest one of all) & we sit at the same table. Our teacher said she won’t move anyone, so to not ask. I’ve already unfriended him before for times he’s got me mad but he’ll literally walk next to me bombarding me with questions about why I’m mad & etc. I would tell him to leave me alone but he wouldn’t. What can I do?? He’s sooo annoying & he’s trying to take classes that I want to take. For example, I was going to take AP Seminar & he didn’t even know what it was but signed up for it. Fortunately/unfortunately, I didn’t get put in the class but was told to request it. However, I don’t want to anymore because I don’t want to end up with him. Other times, he’s asked if he could come over to my house, I told him no & he came anyway. My ex (then bf) had seen him & got mad at me. Btw, he knows where I live cause in 9th grade he’d “walk” me to my house even though I wouldn’t ask him to. I’d speed walk out of school so that he wouldn’t catch up with me. I don’t want to get the law involved, what’s something I can do?