Lightning

Lightning

I've just realised after uploading three of these demos that I'm supposed to delete this --> Alternative content

Get Adobe Flash player

Click to move the source of the lightning to another tile. The lightning is set to be blocked by the grey squares.

I've been trying to get generative lightning into Red Rogue. It had to be aware of the game map and also be blocked by walls.

I was inspired by this Java applet on how to tackle it. I just basically went with a simple path finder and randomly deviated to the left or right normal as the path finder walked. Then I sent out decaying recursive branches that also randomly steered. The effect is, not quite perfect, but rather lightning like. It gets a lot better at higher resolution, but of course I'm going to keep things at a respectable level whilst I'm running a game engine at the same time.

I've also noticed I'm jumping over some tiles at some points. Probably just need to make sure that the deviation doesn't allow a jump of two squares. I could also improve it by adding some hill climbing in the search for the target, so we can get the lightning to flow around obstacles. Not sure how to approach that, but I can easily experiment.

Source code.