Evil Science A whole load of stuff

9Jul/070

Bresenham’s line algorithm

Bresenham's line algorithm is the corner stone of any Roguelike game that uses raycasting as a means of determining what the player can see. It is used to draw an approximation of a straight line between two points. Wikipedia has a more detailed article.

You can download my simple app (bres) demonstrating this algorithm here. Bres contains a form representing a 25 by 25 grid, in which a Bresenham's line is drawn between two points. To run it you'll need to get hold of C# Express and compile the programme. I just don't think having executables to download is a reassuring thing to have 🙂

Using the application

Compile and run the application using C# express.

Move the mouse around on the form and a line will be drawn between the start point (a blue square) and the current mouse position (a red square). Left click to place a new start point. Right click to place a barrier (a black block). To remove it, right click again. A barrier placed between the start and end point will stop a line being drawn between them; the line will begin at the start point and stop at the barrier (pictured below).

bres1.PNG

Filed under: Roguelike Leave a comment
Comments (0) Trackbacks (1)

Leave a comment