Calculating dynamic light and shadows in tile based roguelike games – part 2: drawing circles in a tile based environment

We are getting closer to the final algorithm to calculate dynamic light and shadow in tile based roguelike games, and we are going to cover another important feature: drawing circles in a tile based environment.

While in previous step I showed you the Bresenhams line algorithm although you probably still do not know why, this time it’s quite easy to understand how we are going to use circles in a tile based environment: to simulate the radius of a point light, which could be a torch on the wall or the light halo around your character.

A web page which clearly explains how to create any kind of line, circle, ellipse and B├ęzier curve is The Beauty of Bresenham’s Algorithm and that’s the code I translated from C to JavaScript to draw circles in a tile based environment.

Look at the example:

Drag the white tiles to move both the grey line and the red circles.

We are now very close to the solution of our problem and soon we will be able to create light and shadows in a tile map environment.

Here is the code I used, you can save for future use drawBresenham and drawCircle functions, the other lines have just been written to make the demo work.

How would you turn this into a tile based game dynamic light casting? The answer in next posts, meanwhile download the source code.