This toolkit is a very simple and lightweight implementation of the bresenham line drawing algorithm.
It allows you to follow straight paths on your map very easily.
First, you have to initialize the toolkit with your starting and ending coordinates :
C++ : static void TCODLine::init(int xFrom, int yFrom, int xTo, int yTo)
C : void TCOD_line_init(int xFrom, int yFrom, int xTo, int yTo)
Parameter | Description |
xFrom,yFrom | Coordinates of the line's starting point. |
xTo, yTo | Coordinates of the line's ending point. |
You can then step through each cell with this function. It returns true when you reach the line's ending point.
C++ : static bool TCODLine::step(int *xCur, int *yCur)
C : bool TCOD_line_step(int *xCur, int *yCur)
Parameter | Description |
xCur,yCur | Coordinates of the next cell on the line. |
Example :
Going from point 5,8 to point 13,4 :
C++ : int x=5,y=8;
TCODLine::init(x,y,13,4);
do {
.. update cell x,y
} while (! TCODLine::step(&x,&y) );
C : int x=5,y=8;
TCOD_line_init(x,y,13,4);
do {
.. update cell x,y
} while (! TCOD_line_step(&x,&y) );