Extra special thanks to Dan Shiffman. His tutorial all about 2D ray casting is available here.