Take any till Gadag or Hubali if there are any. or better option take train to Guntakal jn. from Guntakal there are few trains run to Hospet (Guntakal - Gadag passenger / exp )
Far as I'm aware the nearest railway station is at Hospet. Nearly an hour's drive and on a local bus, and you'll be in Hampi. The railway line is not a very active one so make sure the trains are available on your given date of journey.
From bangalore you can go by road or train...train though you will have go book early since holiday season not easy to get tickets reserved...it is well connected by road bus would be good option roads are in good shape...I visited hampi two months ago...hope this helps
Mumbai-hospete-hampi this is the train route you can follow, or else you can directly go by sleeper bus. If you are planning to visit i would say not a good idea as i was there during holi weekend and it was terribly hot.