Created a separate class for collision detection