Bresenham’s Line Algorithm in Flash Alchemy

We are currently working on a platform game that will feature an occasional gravity flip. In some levels the effect will be accompanied by flipping the entire screen but in others it may be too distracting. For those levels we have to come up with other ways to convey that the gravity switched direction. My idea is to have some kind of grass or hair on platforms that will be influenced by the direction of the gravity force.

A  quick demo showed that I would need a lot of line segments. It turned out that Graphics‘ moveTo and lineTo is too slow for that amount of lines. So I started looking for an Alchemy implementation of a line drawing algorithm, specifically Bresenham’s line algorithm. The search was not successful so I rolled up my sleeves and started coding it myself – with help of existing Alchemy demos and a C implementation of the algorithm. Here’s the result. Click it to switch between Alchemy rendering and Graphics rendering.

Source code here.

2 Comments to “Bresenham’s Line Algorithm in Flash Alchemy”
  1. makc says:

    or you just could use a sequence of ~5 grass tile images for different gravity vectors.

  2. Jan Kalis says:

    makc: Sure, I could do a couple of non-Flash 10 optimizations, but this was a good excuse to look into Alchemy :)

Leave a comment.

Google Analytics integration offered by Wordpress Google Analytics Plugin