Please check the prev post: Some guidance for beginners
At the end, they mention some good links for collision algorithms that you should review. Good you have divided your problem in mini-problems. Work of each of them separately and, if possible, in that order.
Lastly, please edit your post and format your code. Highlight your code and press the </>
button and your code will be formatted.
Kf