A - Thanks for the question. No, it is not a sin to use a gun to protect yourself from an intruder. I am happy that this is a concern for you though, because it means that you value human life.
The principles that would guide the Church's thinking in this matter are as follows:
Each of us has a right to life and an inherent dignity as humans, even the intruder. So, if possible, we should use non-deadly force to stop the intruder. So, if you could do so, you should use a non-lethal means of stopping them. This may mean threatening to shoot first and then, if necessary to stop them, shooting to wound, not kill.
We also have a right to protect our own life, property and family. Just as the intruder's life is valuable, so is our own and the lives of our families. Therefore, we have an obligation to protect our own lives as well. Each of us should follow our consciences in determining what level of force would be necessary to defend our lives and other lives, but this could mean taking the life of another in order to do so.
Here is what the Catechism of the Catholic Church says about our legitimate right to defense:
2263 The legitimate defense of persons and societies is not an exception to the prohibition against the murder of the innocent that constitutes intentional killing. "The act of self-defense can have a double effect: the preservation of one's own life; and the killing of the aggressor.... The one is intended, the other is not."
2264 Love toward oneself remains a fundamental principle of morality. Therefore it is legitimate to insist on respect for one's own right to life. Someone who defends his life is not guilty of murder even if he is forced to deal his aggressor a lethal blow:
If a man in self-defense uses more than necessary violence, it will be unlawful: whereas if he repels force with moderation, his defense will be lawful.... Nor is it necessary for salvation that a man omit the act of moderate self-defense to avoid killing the other man, since one is bound to take more care of one's own life than of another's.
A good hypothetical situation might be that an intruder with a knife enters your home. You wake up, get your gun, and then threaten them. They come at you with the knife so you shoot them in the leg to stop them. If on the other hand they had a gun, you might shoot at any place you can, because they might very well shoot you, if you don't stop them with the first shot.
2265 Legitimate defense can be not only a right but a grave duty for someone responsible for another's life. Preserving the common good requires rendering the unjust aggressor unable to inflict harm. To this end, those holding legitimate authority have the right to repel by armed force aggressors against the civil community entrusted to their charge.
I hope this helps.