Monday, March 24, 2008

Light Box: Tracing Lasers

The heart of Light Box is the following of light through the light box. This really can be considered to be a variation of ray tracing which I have discussed before, but due to the way the puzzle is built the light is limited to traveling in only the 4 compass directions. The twist is that special care has to be taken with traveling through the prisms, and prisms have the ability to split a beam into two separate beams which requires that both the beams need to be handled. Prisms are handled using recursion so to prevent the possibility of an infinite loop the light has an intensity factor that is reduced every time it travels through a prism. When the light intensity drops below a certain threshold, the beam is considered dead.

As everything in the game is placed on a tile map, traversing the map is very simple since the beams always travel horizontally or vertically. The beam is adjusted after every move with the beam segment being considered finished when it hits an exit or a prism. When a beam hits a prism, one or two new beam segments are created by calling the map traversal function again. The path(s) of the beam(s) are not calculated mathematically, though this certainly would be a way of doing this. Instead, I just use nested case statements as that was much faster to code and probably not that much less efficient than doing it mathematically.

No comments: