FIrst as you discovered, game programming is difficult. If this is really the type of programming you want to pursue, it would be best to go back to school and get your degree in CS. Or at least take the appropriate CS courses you are missing like algorithms or any math courses that relate to the kind of math in game prgramming as opposed to the math in Electrical Engineering. You may even be able to do a lot of them for no credit through Coursera if you want.
Now the other thing about game programming is that the pressure is unrelenting. It really is a young person's game. If you want a life outside of work, consider if this is really what you want to do.
To gain your confidence back, I personally would go back to business programming. Once you have some success there again, you will feel more confident. And now you know what you need to know to be successful at games programming if that is what you still want to do. So gain some comfidence by getting the additional training you need and working on some personal game projects.
In the meantime, don't let a setback keep you from trying. Throughout your life, there will be times when you need to pick yourself back up and try again. you need to work on resilience because everyone fails at times. Giving up or losing confidence is not what you need. Making a new plan and getting up and trying again is. You found out you weren't prepared for the type of work you were doing. So now go out there and get prepared and try again. Or make a new plan because you tried this, found out that it wasn't the exciting fun thing you imagined it to be so try something else.
One of the benefits of learning to ride horses as a child was that I learned to get back up and try again when I fell off. This is one of the most important life skills you can possess and it is far more imporatnt than talent or training. You fall off, you figure out what you did wrong and then you try again. Just make certain to make some changes when you fall off. Consider it a learning experience. It is OK to come to the comnclusion that a dream is not what you want when you see it up close and personal and come up with a new goal. It is ok to try repeatedly and fail to make a dream work out until you succeed. What isn't ok is to use a failure as a reason to stop trying to do anything.