It is so easy to go into a negative spiral and so hard to prevent it. Pain, of course and other medical problems contribute. I find that it is a lot easier when you grow a little older (I'm 60) and see that life has both its up and downs and experience a few of the good things along with the bad. Then you can see that, because you feel horrible today, does not mean that you will feel bad forever. I guess it is called perspective.
I have had problems with depression ever since I can remember. Even as a child, my report cards say that I was very "high strung" because I would cry easily.
It does get better. Being a teenager is the hardest thing you will ever do. And you are almost done!!! So it can only get better.