Calculating dynamic light and shadows in tile based roguelike games – part 4: a first real world example

I wanted to try a real world example of my dynamic light and shadows in tile based roguelike games, so let’s make a small recap then I am diving into the code:

In first step I introduced Bresenham algorithm to draw a line between two points in a tile based environment.

In step 2 with the same concept I showed you how to draw a circle in a tile based environment.

In step 3 I connected all tiles along the circumference with the player using Bresenham line, stopping the line if it hits a wall.

Today I am showing you a little example in a randomly generated dungeon. The code to generate the dungeon is taken from here and although it does not generate the best dungeons ever, it works so why not?

Drag the player – the green dot – inside the maze and see the light effect. To optimize a bit the code I added a visited array to keep track of tiles I already visited to avoid placing unnecessary tiles. More optimization and some performance statistics will be available next week, meanwhile have a look at the source code:

Remember roguelike games are turn based games so performance is not a top feature, anyway I will show you some full stats next week, meanwhile download the source code of this experiment.

  • Oh yes! Finally! I’m so glad you posted this – It’s a real xmas present, you know? I’ve been working on dynamic shadows on and off for months with huge performance hits.

    I’m buying some of your books. Your blog is literally what I recommend to newbies and veteran Flash devs alike.

    Thanks for your years of progress, you inspired me to start documenting my own Flash work in a blog (not going to advertise it here). You. Are. Awesome.