コード例 #1
0
ファイル: map.c プロジェクト: thasmin/apocscientist
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");
}
コード例 #2
0
ファイル: actors.c プロジェクト: witheld9/Torch
void walkActorPath(character *actor) {
	int nx, ny;
	
	if (TCOD_path_size(actor->path)) {
		TCOD_path_walk(actor->path, &nx, &ny, true);
		
		moveActor(actor, nx - actor->x, ny - actor->y);
	}
}
コード例 #3
0
ファイル: path_c.c プロジェクト: Amarna/libtcod
bool TCOD_path_walk(TCOD_path_t p, int *x, int *y, bool recalculate_when_needed) {
	int newx,newy;
	float can_walk;
	int d;
	TCOD_path_data_t *path=(TCOD_path_data_t *)p;
	TCOD_IFNOT(p != NULL) return false;
	if ( TCOD_path_is_empty(path) ) return false;
	d=(int)(uintptr)TCOD_list_pop(path->path);
	newx=path->ox + dirx[d];
	newy=path->oy + diry[d];
	/* check if the path is still valid */
	can_walk = TCOD_path_walk_cost(path,path->ox,path->oy,newx,newy);
	if ( can_walk == 0.0f ) {
		if (! recalculate_when_needed ) return false; /* don't walk */
		/* calculate a new path */
		if (! TCOD_path_compute(path, path->ox,path->oy, path->dx,path->dy) ) return false ; /* cannot find a new path */
		return TCOD_path_walk(p,x,y,true); /* walk along the new path */
	}
	if ( x ) *x=newx;
	if ( y ) *y=newy;
	path->ox=newx;
	path->oy=newy;
	return true;
}
コード例 #4
0
ファイル: path.cpp プロジェクト: smarmy/HellRogue
bool TCODPath::walk(int *x, int *y, bool recalculateWhenNeeded) {
	return TCOD_path_walk(data,x,y,recalculateWhenNeeded) != 0;
}