See inside and look at the code. You can use this if you wish, just give credit. You may tweak anything you wish to adjust to your game but if you have issues comment here so i can help. It's a huge chunk of code but this is probably the simplest way (I think at least).