Why would he give me the cold shoulder?

i had feelings for this guy and I was pretty sure he had feelings for me. although, I was never completely sure. he would text me for hw, but then he would always get really flirty with the convo. then, we had an amazing time together at Homecoming:holding hands, togetherness, cuddling,etc. so I figured he was into me for sure especially because a week later he wanted to hangout with me outside of school, which we did. but after that, I was always so confused because when I'd see him at school, he'd act uninterested, kinda giving me the cold shoulder. but I noticed that if it was just us two and he'd see me or through texting, he'd be flirty and be happy to see/talk to me. but when we are in a big group of friends, he'd act not happy to see me, sometimes not even acknowledge me,like nothing was happening between us.

after a few months of that, I called him out and told him that he likes to lead me on (this was during a text msg convo) and he never texted me back.so I gave him the cold shoulder and then he acted overly nice to me.it was surprising.

since then, we don't talk as much. but if he does see me its still the same thing: flirty and outgoing when its just me and him, but when other people are around, it's like I don't matter to him.

only a few people know that we were "talking". and from what I've heard, he is really shy.

but I don't know what to think...he sure wasn't shy on homecoming or when he'd ask me to hangout.

but I still like him.i just don't understand why he acts the way he does.