I think there's two main ways or reasons that someone distances themselve, the first being because they genuinely want to be alone, they're just happiest on their own and don't really get lonely or otherwise feel negative when they distance themself. The other when someone distances themselve from others because they "want to be alone" but feel lonely and down when they do. If you're the first then it makes sense and distancing yourself is probably okay, but to me it sounds more like you're the second as you mentioned lonliness.
It's hard though, you want to be alone, so you distance yourself, then you're lonely, but at the same time, don't want to surround yourself with people. I think the fact that you have two close friends is a good thing, it's hard but try not to avoid or distance yourself from them, you don't have to speak to them all the time or anything, but just making sure that they're there for you would be good. You mentioned being angry too, if you have other things going on or other issues, that would explain why you're distancing yourself.
This mentions tips for dealing with loneliness, I think it's written for a person who who has other mental health issues, but it might help regardless. If the lonliness is really starting to bother you and you keep distancing yourself, there might be someone you can talk to about dealing with / overcoming lonliness, either a specialist, or confide in one of your close friends if you can trust them?