God doesn't punish you when you sin. If you are a born-again Christian to begin with he will forgive you. Just ask. Claim first John 1:9. Confess you sins to him and ask his forgiveness. He will restore that relationship. You were not lost before you confessed if you are saved. You still need to confess and get right with God.
He does allow natural consequences of sin. He will still help us and be with us thorugh them.
For example, don't sleep with someone who may have AIDS and then blame God if you catch a terrible disease. However, if one were to catch a terrible disease from a mistake we have repented of and Christ has put in our past He wil help us to live with it!
Romans 8:28 still applies! "God works everything together for good to those who love God and are called according to His purpose." Your sin was not in His will but he can still bring good out of it!
Do not let the devil get you down when you mess up! Come back to God, repent, confess to Him. Let Him (God) love you and go one!! Do not believe the lies the devil will try to get you to believe!