Example #1
0
void map_walk(TCOD_path_t path, point *p, float dist)
{
	int x, y;
	TCOD_path_get_origin(path, &x, &y);
	//printf("origin: %d, %d\n", x, y);
	//printf("curr  : %f, %f\n", p->x, p->y);
	TCOD_path_get(path, 0, &x, &y);
	//printf("step 0: %d, %d\n", x, y);

	// if the next step is closer than dist, move to it
	// then subtract how far was moved from dist and repeat
	float mx = x - p->x;
	float my = y - p->y;
	//printf("m     : %f, %f\ndist : %f\n", mx, my, dist);
	while (mx * mx + my * my < dist * dist) {
		p->x = x;
		p->y = y;
		dist -= sqrt(mx * mx + my * my);

		TCOD_path_walk(path, &x, &y, true);
		//printf("next step: %d, %d\n", x, y);
		mx = x - p->x;
		my = y - p->y;
		if (mx == 0.0f && my == 0.0f)
			return;
		//printf("m     : %f, %f\ndist : %f\n", mx, my, dist);
	}

	float pctm = dist / sqrt(mx * mx + my * my);
	p->x += pctm * mx;
	p->y += pctm * my;
	//printf("dist  : %f\n", dist);
	//printf("final : %f, %f\n", p->x, p->y);
	//printf("\n");
}
Example #2
0
void TCODPath::getOrigin(int *x,int *y) const {
	TCOD_path_get_origin(data,x,y);
}