Detecting collisions can be done by going through each object for each object, but that'd be fairly slow. A beautiful and efficient way is using quadtrees.
Sound at the end: Noah Barger – Piano Tune.mp3 Demonstration link on GitHub: kulsudo/quadtrees