libtcod
Loading...
Searching...
No Matches
TCODLine Class Reference

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).

Member Function Documentation

◆ init()

void TCODLine::init ( int xFrom,
int yFrom,
int xTo,
int yTo )
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.

Parameters
xFrom,yFromCoordinates of the line's starting point.
xTo,yToCoordinates of the line's ending point.

◆ line()

bool TCODLine::line ( int xFrom,
int yFrom,
int xTo,
int yTo,
TCODLineListener * listener )
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)

Parameters
xFrom,yFromCoordinates of the line's starting point.
xTo,yToCoordinates of the line's ending point.
listenerCallback 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)

◆ step()

bool TCODLine::step ( int * xCur,
int * yCur )
static

You can then step through each cell with this function.

It returns true when you reach the line's ending point.

Parameters
xCur,yCurthe 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)

update cell 5,8

x,y=libtcod.line_step() while (not x is None) :

update cell x,y

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


The documentation for this class was generated from the following file: