|
libtcod
|
Static Public Member Functions | |
| static void | init (int xFrom, int yFrom, int xTo, int yTo) |
| First, you have to initialize the toolkit with your starting and ending coordinates. | |
| static bool | step (int *xCur, int *yCur) |
| You can then step through each cell with this function. | |
| static bool | line (int xFrom, int yFrom, int xTo, int yTo, TCODLineListener *listener) |
| The function returns false if the line has been interrupted by the callback (it returned false before the last point). | |
|
static |
First, you have to initialize the toolkit with your starting and ending coordinates.
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.
| xFrom,yFrom | Coordinates of the line's starting point. |
| xTo,yTo | Coordinates of the line's ending point. |
|
static |
The function returns false if the line has been interrupted by the callback (it returned false before the last point).
class TCODLIB_API TCODLineListener { virtual bool putPoint (int x, int y) = 0; }; static bool TCODLine::line (int xFrom, int yFrom, int xTo, int yTo, TCODLineListener * listener)
typedef bool (*TCOD_line_listener_t) (int x, int y); bool TCOD_line(int xFrom, int yFrom, int xTo, int yTo, TCOD_line_listener_t listener)
def line_listener(x,y) : # ... line(xFrom, yFrom, xTo, yTo, listener)
| xFrom,yFrom | Coordinates of the line's starting point. |
| xTo,yTo | Coordinates of the line's ending point. |
| listener | Callback called for each line's point. The function stops if the callback returns false. |
class MyLineListener : public TCODLineListener { public: bool putPoint (int x,int y) { printf ("%d %d\n",x,y); return true; } }; MyLineListener myListener; TCODLine::line(5,8,13,4,&myListener);
printf ("%d %d\n",x,y); return true; } TCOD_line_line(5,8,13,4,my_listener);
print x,y return True libtcod.line_line(5,8,13,4,my_listener)
|
static |
You can then step through each cell with this function.
It returns true when you reach the line's ending point.
| xCur,yCur | the coordinates of the next cell on the line are stored here when the function returns |
Going from point 5,8 to point 13,4 int x = 5, y = 8; TCODLine::init(x,y,13,4); do { update cell x,y } while (!TCODLine::step(&x,&y));
int x = 5, y = 8; TCOD_line_init(x,y,13,4); do { update cell x,y } while (!TCOD_line_step(&x,&y));
libtcod.line_init(5,8,13,4)
x,y=libtcod.line_step() while (not x is None) :
x,y=libtcod.line_step()
x=5 y=8 tcod.line.init(x,y,13,4) repeat – update cell x,y lineEnd,x,y = tcod.line.step(x,y) until lineEnd