Posted: 17th Sep 2011 0:22
path finding agk modified version of patrick lesters. Modified for agk. I think this is right might be some bugs if you find them please fix them, and repost.
+ Code Snippet
/*
;===================================================================
;A* Pathfinder (Version 1.71a) by Patrick Lester. Used by permission.
;===================================================================
;Last updated 06/16/03 -- Visual C++ version
 */
#include "Main.h"
#include "global.h"

	//Declare constants
	const int mapWidth = 22, mapHeight = 18, tileSize = 25, numberPeople = 3;
	int onClosedList = 10;
	const int notfinished = 0, notStarted = 0;// path-related constants
	const int found = 1, nonexistent = 2; 
	const int walkable = 0, unwalkable = 1;// walkability array constants
//	extern int walkability [mapWidth][mapHeight];
	//Create needed arrays
	//extern int *walkability;
	int openList[mapWidth*mapHeight+2]; //1 dimensional array holding ID# of open list items
	int whichList[mapWidth+1][mapHeight+1];  //2 dimensional array used to record 
// 		whether a cell is on the open list or on the closed list.
	int openX[mapWidth*mapHeight+2]; //1d array stores the x location of an item on the open list
	int openY[mapWidth*mapHeight+2]; //1d array stores the y location of an item on the open list
	int parentX[mapWidth+1][mapHeight+1]; //2d array to store parent of each cell (x)
	int parentY[mapWidth+1][mapHeight+1]; //2d array to store parent of each cell (y)
	int Fcost[mapWidth*mapHeight+2];	//1d array to store F cost of a cell on the open list
	int Gcost[mapWidth+1][mapHeight+1]; 	//2d array to store G cost for each cell.
	int Hcost[mapWidth*mapHeight+2];	//1d array to store H cost of a cell on the open list
	int pathLength[numberPeople+1];     //stores length of the found path for critter
	int pathLocation[numberPeople+1];   //stores current position along the chosen path for critter		
	int* pathBank [numberPeople+1];

	//Path reading variables
	
	int xPath[numberPeople+1];
	int yPath[numberPeople+1];

//-----------------------------------------------------------------------------
// Function Prototypes: where needed
//-----------------------------------------------------------------------------
void ReadPath(int pathfinderID,int currentX,int currentY, int pixelsPerFrame);
int ReadPathX(int pathfinderID,int pathLocation);
int ReadPathY(int pathfinderID,int pathLocation);


//-----------------------------------------------------------------------------
// Name: InitializePathfinder
// Desc: Allocates memory for the pathfinder.
//-----------------------------------------------------------------------------
void InitializePathfinder (void)
{
	for (int x = 0; x < numberPeople+1; x++)
		pathBank [x] = (int*) malloc(4);
}


//-----------------------------------------------------------------------------
// Name: EndPathfinder
// Desc: Frees memory used by the pathfinder.
//-----------------------------------------------------------------------------
void EndPathfinder (void)
{
	for (int x = 0; x < numberPeople+1; x++)
	{
		free (pathBank [x]);
	}
}


//-----------------------------------------------------------------------------
// Name: FindPath
// Desc: Finds a path using A*
//-----------------------------------------------------------------------------
int FindPath (int pathfinderID,int startingX, int startingY,
			  int targetX, int targetY)
{
	agk::Print("in");
	int onOpenList=0, parentXval=0, parentYval=0,
	a=0, b=0, m=0, u=0, v=0, temp=0, corner=0, numberOfOpenListItems=0,
	addedGCost=0, tempGcost = 0, path = 0,
	tempx, pathX, pathY, cellPosition,
	newOpenListItemID=0;

//1. Convert location data (in pixels) to coordinates in the walkability array.
	int startX = startingX/tileSize;
	int startY = startingY/tileSize;	
	targetX = targetX/tileSize;
	targetY = targetY/tileSize;

//2.Quick Path Checks: Under the some circumstances no path needs to
//	be generated ...

//	If starting location and target are in the same location...
	if (startX == targetX && startY == targetY && pathLocation[pathfinderID] > 0)
		return found;
	if (startX == targetX && startY == targetY && pathLocation[pathfinderID] == 0)
		return nonexistent;

//	If target square is unwalkable, return that it's a nonexistent path.
	if (walkability[targetX][targetY] == unwalkable)
		goto noPath;

//3.Reset some variables that need to be cleared
	if (onClosedList > 1000000) //reset whichList occasionally
	{
		for (int x = 0; x < mapWidth;x++) {
			for (int y = 0; y < mapHeight;y++)
				whichList [x][y] = 0;
		}
		onClosedList = 10;	
	}
	onClosedList = onClosedList+2; //changing the values of onOpenList and onClosed list is faster than redimming whichList() array
	onOpenList = onClosedList-1;
	pathLength [pathfinderID] = notStarted;//i.e, = 0
	pathLocation [pathfinderID] = notStarted;//i.e, = 0
	Gcost[startX][startY] = 0; //reset starting square's G value to 0

//4.Add the starting location to the open list of squares to be checked.
	numberOfOpenListItems = 1;
	openList[1] = 1;//assign it as the top (and currently only) item in the open list, which is maintained as a binary heap (explained below)
	openX[1] = startX ; openY[1] = startY;

//5.Do the following until a path is found or deemed nonexistent.
	do
	{
		agk::Print(parentXval);
//6.If the open list is not empty, take the first cell off of the list.
//	This is the lowest F cost cell on the open list.
	if (numberOfOpenListItems != 0)
	{

//7. Pop the first item off the open list.
	parentXval = openX[openList[1]];
	parentYval = openY[openList[1]]; //record cell coordinates of the item
	whichList[parentXval][parentYval] = onClosedList;//add the item to the closed list

//	Open List = Binary Heap: Delete this item from the open list, which
//  is maintained as a binary heap. For more information on binary heaps, see:
//	http://www.policyalmanac.org/games/binaryHeaps.htm
	numberOfOpenListItems = numberOfOpenListItems - 1;//reduce number of open list items by 1	
		
//	Delete the top item in binary heap and reorder the heap, with the lowest F cost item rising to the top.
	openList[1] = openList[numberOfOpenListItems+1];//move the last item in the heap up to slot #1
	v = 1;

//	Repeat the following until the new item in slot #1 sinks to its proper spot in the heap.
	do
	{
	u = v;		
	if (2*u+1 <= numberOfOpenListItems) //if both children exist
	{
	 	//Check if the F cost of the parent is greater than each child.
		//Select the lowest of the two children.
		if (Fcost[openList[u]] >= Fcost[openList[2*u]]) 
			v = 2*u;
		if (Fcost[openList[v]] >= Fcost[openList[2*u+1]]) 
			v = 2*u+1;		
	}
	else
	{
		if (2*u <= numberOfOpenListItems) //if only child #1 exists
		{
	 	//Check if the F cost of the parent is greater than child #1	
			if (Fcost[openList[u]] >= Fcost[openList[2*u]]) 
				v = 2*u;
		}
	}

	if (u != v) //if parent's F is > one of its children, swap them
	{
		temp = openList[u];
		openList[u] = openList[v];
		openList[v] = temp;			
	}
	else
		break; //otherwise, exit loop
		
	}
	while (agk::GetRawKeyState(27)!=0);//reorder the binary heap


//7.Check the adjacent squares. (Its "children" -- these path children
//	are similar, conceptually, to the binary heap children mentioned
//	above, but don't confuse them. They are different. Path children
//	are portrayed in Demo 1 with grey pointers pointing toward
//	their parents.) Add these adjacent child squares to the open list
//	for later consideration if appropriate (see various if statements
//	below).
	for (b = parentYval-1; b <= parentYval+1; b++)
	{
	for (a = parentXval-1; a <= parentXval+1; a++)
	{

//	If not off the map (do this first to avoid array out-of-bounds errors)
	if (a != -1 && b != -1 && a != mapWidth && b != mapHeight){

//	If not already on the closed list (items on the closed list have
//	already been considered and can now be ignored).			
	if (whichList[a][b] != onClosedList) { 
	
//	If not a wall/obstacle square.
	if (walkability [a][b] != unwalkable) { 
		
//	Don't cut across corners
	corner = walkable;	
	if (a == parentXval-1) 
	{
		if (b == parentYval-1)
		{
			if (walkability[parentXval-1][parentYval] == unwalkable
				|| walkability[parentXval][parentYval-1] == unwalkable) \
				corner = unwalkable;
		}
		else if (b == parentYval+1)
		{
			if (walkability[parentXval][parentYval+1] == unwalkable
				|| walkability[parentXval-1][parentYval] == unwalkable) 
				corner = unwalkable; 
		}
	}
	else if (a == parentXval+1)
	{
		if (b == parentYval-1)
		{
			if (walkability[parentXval][parentYval-1] == unwalkable 
				|| walkability[parentXval+1][parentYval] == unwalkable) 
				corner = unwalkable;
		}
		else if (b == parentYval+1)
		{
			if (walkability[parentXval+1][parentYval] == unwalkable 
				|| walkability[parentXval][parentYval+1] == unwalkable)
				corner = unwalkable; 
		}
	}	
	if (corner == walkable) {
	
//	If not already on the open list, add it to the open list.			
	if (whichList[a][b] != onOpenList) 
	{	

		//Create a new open list item in the binary heap.
		newOpenListItemID = newOpenListItemID + 1; //each new item has a unique ID #
		m = numberOfOpenListItems+1;
		openList[m] = newOpenListItemID;//place the new open list item (actually, its ID#) at the bottom of the heap
		openX[newOpenListItemID] = a;
		openY[newOpenListItemID] = b;//record the x and y coordinates of the new item

		//Figure out its G cost
		if (abs(a-parentXval) == 1 && abs(b-parentYval) == 1)
			addedGCost = 14;//cost of going to diagonal squares	
		else	
			addedGCost = 10;//cost of going to non-diagonal squares				
		Gcost[a][b] = Gcost[parentXval][parentYval] + addedGCost;

		//Figure out its H and F costs and parent
		Hcost[openList[m]] = 10*(abs(a - targetX) + abs(b - targetY));
		Fcost[openList[m]] = Gcost[a][b] + Hcost[openList[m]];
		parentX[a][b] = parentXval ; parentY[a][b] = parentYval;	

		//Move the new open list item to the proper place in the binary heap.
		//Starting at the bottom, successively compare to parent items,
		//swapping as needed until the item finds its place in the heap
		//or bubbles all the way to the top (if it has the lowest F cost).
		while (m != 1) //While item hasn't bubbled to the top (m=1)	
		{
			//Check if child's F cost is < parent's F cost. If so, swap them.	
			if (Fcost[openList[m]] <= Fcost[openList[m/2]])
			{
				temp = openList[m/2];
				openList[m/2] = openList[m];
				openList[m] = temp;
				m = m/2;
			}
			else
				break;
		}
		numberOfOpenListItems = numberOfOpenListItems+1;//add one to the number of items in the heap

		//Change whichList to show that the new item is on the open list.
		whichList[a][b] = onOpenList;
	}

//8.If adjacent cell is already on the open list, check to see if this 
//	path to that cell from the starting location is a better one. 
//	If so, change the parent of the cell and its G and F costs.	
	else //If whichList(a,b) = onOpenList
	{
	
		//Figure out the G cost of this possible new path
		if (abs(a-parentXval) == 1 && abs(b-parentYval) == 1)
			addedGCost = 14;//cost of going to diagonal tiles	
		else	
			addedGCost = 10;//cost of going to non-diagonal tiles				
		tempGcost = Gcost[parentXval][parentYval] + addedGCost;
		
		//If this path is shorter (G cost is lower) then change
		//the parent cell, G cost and F cost. 		
		if (tempGcost < Gcost[a][b]) //if G cost is less,
		{
			parentX[a][b] = parentXval; //change the square's parent
			parentY[a][b] = parentYval;
			Gcost[a][b] = tempGcost;//change the G cost			

			//Because changing the G cost also changes the F cost, if
			//the item is on the open list we need to change the item's
			//recorded F cost and its position on the open list to make
			//sure that we maintain a properly ordered open list.
			for (int x = 1; x <= numberOfOpenListItems; x++) //look for the item in the heap
			{
			if (openX[openList[x]] == a && openY[openList[x]] == b) //item found
			{
				Fcost[openList[x]] = Gcost[a][b] + Hcost[openList[x]];//change the F cost
				
				//See if changing the F score bubbles the item up from it's current location in the heap
				m = x;
				while (m != 1) //While item hasn't bubbled to the top (m=1)	
				{
					//Check if child is < parent. If so, swap them.	
					if (Fcost[openList[m]] < Fcost[openList[m/2]])
					{
						temp = openList[m/2];
						openList[m/2] = openList[m];
						openList[m] = temp;
						m = m/2;
					}
					else
						break;
				} 
				break; //exit for x = loop
			} //If openX(openList(x)) = a
			} //For x = 1 To numberOfOpenListItems
		}//If tempGcost < Gcost(a,b)

	}//else If whichList(a,b) = onOpenList	
	}//If not cutting a corner
	}//If not a wall/obstacle square.
	}//If not already on the closed list 
	}//If not off the map
	}//for (a = parentXval-1; a <= parentXval+1; a++){
	}//for (b = parentYval-1; b <= parentYval+1; b++){

	}//if (numberOfOpenListItems != 0)

//9.If open list is empty then there is no path.	
	else
	{
		path = nonexistent; break;
	}  

	//If target is added to open list then path has been found.
	if (whichList[targetX][targetY] == onOpenList)
	{
		path = found; break;
	}

	}
	while (1);//Do until path is found or deemed nonexistent

//10.Save the path if it exists.
	if (path == found)
	{

//a.Working backwards from the target to the starting location by checking
//	each cell's parent, figure out the length of the path.
	pathX = targetX; pathY = targetY;
	do
	{
		//Look up the parent of the current cell.	
		tempx = parentX[pathX][pathY];		
		pathY = parentY[pathX][pathY];
		pathX = tempx;

		//Figure out the path length
		pathLength[pathfinderID] = pathLength[pathfinderID] + 1;
	}
	while (pathX != startX || pathY != startY);

//b.Resize the data bank to the right size in bytes
	pathBank[pathfinderID] = (int*) realloc (pathBank[pathfinderID],
		pathLength[pathfinderID]*8);

//c. Now copy the path information over to the databank. Since we are
//	working backwards from the target to the start location, we copy
//	the information to the data bank in reverse order. The result is
//	a properly ordered set of path data, from the first step to the
//	last.
	pathX = targetX ; pathY = targetY;
	cellPosition = pathLength[pathfinderID]*2;//start at the end	
	do
	{
	cellPosition = cellPosition - 2;//work backwards 2 integers
	pathBank[pathfinderID] [cellPosition] = pathX;
	pathBank[pathfinderID] [cellPosition+1] = pathY;

//d.Look up the parent of the current cell.	
	tempx = parentX[pathX][pathY];		
	pathY = parentY[pathX][pathY];
	pathX = tempx;

//e.If we have reached the starting square, exit the loop.	
	}
	while (pathX != startX || pathY != startY);	

//11.Read the first path step into xPath/yPath arrays
	ReadPath(pathfinderID,startingX,startingY,1);

	}
	return path;


//13.If there is no path to the selected target, set the pathfinder's
//	xPath and yPath equal to its current location and return that the
//	path is nonexistent.
noPath:
	xPath[pathfinderID] = startingX;
	yPath[pathfinderID] = startingY;
	return nonexistent;
}




//==========================================================
//READ PATH DATA: These functions read the path data and convert
//it to screen pixel coordinates.
void ReadPath(int pathfinderID,int currentX,int currentY,
			  int pixelsPerFrame)
{
/*
;	Note on PixelsPerFrame: The need for this parameter probably isn't
;	that obvious, so a little explanation is in order. This
;	parameter is used to determine if the pathfinder has gotten close
;	enough to the center of a given path square to warrant looking up
;	the next step on the path.
;	 
;	This is needed because the speed of certain sprites can
;	make reaching the exact center of a path square impossible.
;	In Demo #2, the chaser has a velocity of 3 pixels per frame. Our
;	tile size is 50 pixels, so the center of a tile will be at location
;	25, 75, 125, etc. Some of these are not evenly divisible by 3, so
;	our pathfinder has to know how close is close enough to the center.
;	It calculates this by seeing if the pathfinder is less than 
;	pixelsPerFrame # of pixels from the center of the square. 

;	This could conceivably cause problems if you have a *really* fast
;	sprite and/or really small tiles, in which case you may need to
;	adjust the formula a bit. But this should almost never be a problem
;	for games with standard sized tiles and normal speeds. Our smiley
;	in Demo #4 moves at a pretty fast clip and it isn't even close
;	to being a problem.
*/

	int ID = pathfinderID; //redundant, but makes the following easier to read

	//If a path has been found for the pathfinder	...
	if (pathStatus[ID] == found)
	{

		//If path finder is just starting a new path or has reached the 
		//center of the current path square (and the end of the path
		//hasn't been reached), look up the next path square.
		if (pathLocation[ID] < pathLength[ID])
		{
			//if just starting or if close enough to center of square
			if (pathLocation[ID] == 0 || 
				(abs(currentX - xPath[ID]) < pixelsPerFrame && abs(currentY - yPath[ID]) < pixelsPerFrame))
					pathLocation[ID] = pathLocation[ID] + 1;
		}

		//Read the path data.		
		xPath[ID] = ReadPathX(ID,pathLocation[ID]);
		yPath[ID] = ReadPathY(ID,pathLocation[ID]);

		//If the center of the last path square on the path has been 
		//reached then reset.
		if (pathLocation[ID] == pathLength[ID]) 
		{
			if (abs(currentX - xPath[ID]) < pixelsPerFrame 
				&& abs(currentY - yPath[ID]) < pixelsPerFrame) //if close enough to center of square
					pathStatus[ID] = notStarted; 
		}
	}

	//If there is no path for this pathfinder, simply stay in the current
 	//location.
	else
	{	
		xPath[ID] = currentX;
		yPath[ID] = currentY;
	}
}


//The following two functions read the raw path data from the pathBank.
//You can call these functions directly and skip the readPath function
//above if you want. Make sure you know what your current pathLocation
//is.

//-----------------------------------------------------------------------------
// Name: ReadPathX
// Desc: Reads the x coordinate of the next path step
//-----------------------------------------------------------------------------
int ReadPathX(int pathfinderID,int pathLocation)
{
	int x;
	if (pathLocation <= pathLength[pathfinderID])
	{

	//Read coordinate from bank
	x = pathBank[pathfinderID] [pathLocation*2-2];

	//Adjust the coordinates so they align with the center
	//of the path square (optional). This assumes that you are using
	//sprites that are centered -- i.e., with the midHandle command.
	//Otherwise you will want to adjust this.
	x = tileSize*x ;
	
	}
	return x;
}	


//-----------------------------------------------------------------------------
// Name: ReadPathY
// Desc: Reads the y coordinate of the next path step
//-----------------------------------------------------------------------------
int ReadPathY(int pathfinderID,int pathLocation)
{
	int y;
	if (pathLocation <= pathLength[pathfinderID])
	{

	//Read coordinate from bank
	y = pathBank[pathfinderID] [pathLocation*2-1];

	//Adjust the coordinates so they align with the center
	//of the path square (optional). This assumes that you are using
	//sprites that are centered -- i.e., with the midHandle command.
	//Otherwise you will want to adjust this.
	y = tileSize*y ;
	
	}
	return y;
}

	



+ Code Snippet
/*
	Name:			Example 27
	Description:	Box2D Walls
*/

// include our main header file
#include "Main.h"
#include "aStarlibrary.h"
#include <fstream>
using namespace AGK;
using namespace std;

int xLoc [4]; int yLoc [4]; int speed [4];
int searchTime;


void CreateWallImage (void);
void DrawMap (void);
void EditMap (void);
void LoadGraphics (void);
void LoadMapData (void);
void LoadUnitData (void);
void MoveChaser (int ID);
void MoveSmiley (void);
void MoveSprite(int ID,int id2);
void RenderScreen (void);
//void SaveMapData (void);
//void ShowDirections (void);
int player;
int spriteidmonsters;
int wall;

//player=agk::CreateSprite(agk::LoadImage("corners.jpg");
// let the compiler know we're using the AGK namespace
//extern int mapWidth = 22, mapHeight = 18;

// declare our app
app App;
void LoadGraphics ()
{
	player=agk::CreateSprite(agk::LoadImage("ship.png"));
	agk::SetSpritePosition(player,25,25);
	spriteidmonsters=agk::CreateSprite(agk::LoadImage("shape6.png"));
	agk::SetSpritePosition(spriteidmonsters,125,325);
	int clone=agk::CloneSprite(spriteidmonsters);
	agk::SetSpritePosition(clone,325,125);
	wall=agk::CreateSprite(agk::LoadImage("corners.jpg"));
	agk::SetSpritePosition(wall,-100,-100);
	//CreateWallImage();
//	int clone;
	for(int y=0; y<9;y++)
	{
		for(int x=0;x<12;x++)
		{
			if(floorplan[x][y]==1)
			{
				clone=agk::CloneSprite(wall);
				agk::SetSpritePosition(wall,50*x+25,50*y+25);

			}
		}
	}
}
void LoadUnitData ()
{
	xLoc[1] = 25 ; yLoc[1] = 25; //initial smiley location
	xLoc[2] = 125 ; yLoc[2] = 375; //initial chaser location
	xLoc[3] = 325 ; yLoc[3] = 145; //initial chaser location	
	speed[1] = 5;//smiley speed
	speed[2] = 1;//chaser
	speed[3] = 2;//chaser
}
void MoveChaser(int ID,int id2)
{
	//agk::SetSpritePosition(ID,-xLoc[2],-yLoc[2]);
	int targetID = player; //ID of target (the smiley)

//1. Find Path: If smiley and chaser are not at the same location on the 
//	screen and no path is currently active, find a new path.
	if (xLoc[id2] != xLoc[1] || yLoc[id2] != yLoc[1]) 
	{
		//agk::Print("in");
	//If no path has been generated, generate one. Update it when
	//the chaser reaches its fifth step on the current path.	
		agk::Print(pathStatus[id2]);
agk::Print(notStarted);
	if (pathStatus[id2] == notStarted || pathLocation[id2] == 5)
	{
		agk::Print("in");
	//	system("pause");
		//Generate a new path. Enter coordinates of smiley sprite (xLoc(1)/
		//yLoc(1)) as the target.
		pathStatus[id2] = FindPath(id2,xLoc[id2],yLoc[id2],xLoc[1],yLoc[1]);
		
	}} 

//2.Move chaser.
	if (pathStatus[id2] == found) MoveSprite(ID,id2);
}
void MoveSprite(int ID,int id2)
{
	agk::Print("found");
	//1.Read path information
	ReadPath(id2,xLoc[id2],yLoc[id2],speed[id2]);

//2.Move sprite. xLoc/yLoc = current location of sprite. xPath and
//	yPath = coordinates of next step on the path that were/are
//	read using the readPath function.
	if (xLoc[id2] > xPath[id2]) xLoc[id2] = xLoc[id2] - speed[id2];
	if (xLoc[id2] < xPath[id2]) xLoc[id2] = xLoc[id2] + speed[id2];
	if (yLoc[id2] > yPath[id2]) yLoc[id2] = yLoc[id2] - speed[id2];		
	if (yLoc[id2] < yPath[id2]) yLoc[id2] = yLoc[id2] + speed[id2];
	
	
//3.When sprite reaches the end location square	(end of its current
//	path) ...		
	if (pathLocation[id2] == pathLength[id2]) 
	{
//		Center the chaser in the square (not really necessary, but 
//		it looks a little better for the chaser, which moves in 3 pixel
//		increments and thus isn't always centered when it reaches its
//		target).
		if (abs(xLoc[id2] - xPath[id2]) < speed[id2]) xLoc[id2] = xPath[id2];
		if (abs(yLoc[id2] - yPath[id2]) < speed[id2]) yLoc[id2] = yPath[id2];
	}
	agk::SetSpritePosition(ID,xLoc[id2],yLoc[id2]);
	
}
void RenderScreen()
{
}
void LoadMapData()
{
}
void MoveSmiley()
{
	
	
}

void app::Begin ( void )
{
agk::SetVirtualResolution ( 550, 400 );
	LoadMapData();
	LoadUnitData();
	LoadGraphics();
	InitializePathfinder();


	
}

void app::Loop ( void )
{

MoveSmiley();
MoveChaser(spriteidmonsters,2);
agk::Print(xLoc[2]);
agk::Print(yLoc[2]);
//yLoc[2]=yLoc[2]--;

//for (int ID = 2; ID <= 3; ID++) 
	//MoveChaser(ID);

RenderScreen(); 
//CheckWinMessages();

	// this function gets called on a continual basis, use this to update your
	// game logic and deal with input and other events

	

	// we call agk::Sync to update the screen, when this happens our sprite
	// will get drawn on screen
	agk::Sync ( );
}

void app::End ( void )
{
	// this function gets called when the game ends, in here you can clean up
	// all resources and deal with things like saving game data
}

+ Code Snippet
#ifndef _GLOBALS_H_
#define _GLOBALS_H_
int walkability [22][16]={
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},//0
	{1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1},//1
	{1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1},//2
	{1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1},//3
	{1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1},//4
	{1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1},//5
	{1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1},//6
	{1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1},//7
	{1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1},//8
	{1,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1},//9
	{1,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1},//0
	{1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1},//1
	{1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1},//2
	{1,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1},//3
	{1,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1},//4
	{1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1},//5
	{1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1},//6
	{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},//7
	{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},//8
	{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
	{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
	};

int floorplan[10][7]={
	{0,1,0,0,0,0,0},
	{0,1,0,0,0,0,0},
	{0,0,0,0,1,0,0},
	{0,0,0,0,1,0,0},
	{0,1,0,0,1,0,0},
	{0,1,0,0,0,0,0},
	{0,1,0,0,1,0,0},
	{1,1,1,1,1,1,0},
	{0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0}
};

int pathStatus[4]={0,0,0,0};
#endif
Posted: 17th Sep 2011 5:09
change tyleSize

tileSize = 50.
and walkability to a 10 x7.

make the data the same data as floorplan. works better
Posted: 17th Sep 2011 11:21
Great piece of code

I think you will get alot more feedback if you convert it to tier 1 the basic version?

People with the skills to use c++ can mostly do this them self?

But i have seen alotof posts from tier 1 users on how to do path finding

I have planned to convert my simple version from dbp when i get the time?

But yours look better
Posted: 18th Sep 2011 0:06
@Cliff Aaw I thought this was for tier1, why did you have to ruin this moment for me buy saying it isn't?
Posted: 18th Sep 2011 3:26
Sorry it is tier two code, but I am more use too c++.
Posted: 18th Sep 2011 4:13
i updated main.h so the monster follows the player, and you can move the player accordingly to the sceanery using a joystick.
+ Code Snippet

// include our main header file
#include "Main.h"
#include "aStarlibrary.h"
#include <fstream>
using namespace AGK;
using namespace std;

float xLoc [4]; float yLoc [4]; float speed [4];
int searchTime;


void CreateWallImage (void);
void DrawMap (void);
void EditMap (void);
void LoadGraphics (void);
void LoadMapData (void);
void LoadUnitData (void);
void MoveChaser (int ID);
void MoveSmiley (void);
void MoveSprite(int ID,int id2);
void RenderScreen (void);
//void SaveMapData (void);
//void ShowDirections (void);
int player;
int spriteidmonsters;
int wall;

//player=agk::CreateSprite(agk::LoadImage("corners.jpg");
// let the compiler know we're using the AGK namespace
//extern int mapWidth = 22, mapHeight = 18;

// declare our app
app App;
void LoadGraphics ()
{
	player=agk::CreateSprite(agk::LoadImage("ship.png"));
	agk::SetSpritePosition(player,25,25);
	spriteidmonsters=agk::CreateSprite(agk::LoadImage("shape6.png"));
	agk::SetSpriteAngle (spriteidmonsters,180.0f);
	agk::SetSpritePosition(spriteidmonsters,125,325);
	int clone=agk::CloneSprite(spriteidmonsters);
	agk::SetSpritePosition(clone,325,125);
	wall=agk::CreateSprite(agk::LoadImage("corners.jpg"));
	agk::SetSpritePosition(wall,-100,-100);
	//CreateWallImage();
//	int clone;
	for(int y=0; y<7;y++)
	{
		for(int x=0;x<10;x++)
		{
			if(floorplan[x][y]==1)
			{
				clone=agk::CloneSprite(wall);
				agk::SetSpritePosition(wall,50*x+25,50*y+25);

			}
		}
	}
}
void LoadUnitData ()
{
	xLoc[1] = 25 ; yLoc[1] = 25; //initial smiley location
	xLoc[2] = 125 ; yLoc[2] = 325; //initial chaser location
	xLoc[3] = 325 ; yLoc[3] = 145; //initial chaser location	
	speed[1] = 5;//smiley speed
	speed[2] = .5;//chaser
	speed[3] = 2;//chaser
}
void MoveChaser(int ID,int id2)
{
	//agk::SetSpritePosition(ID,-xLoc[2],-yLoc[2]);
	int targetID = player; //ID of target (the smiley)

//1. Find Path: If smiley and chaser are not at the same location on the 
//	screen and no path is currently active, find a new path.
	if (xLoc[id2] != xLoc[1] || yLoc[id2] != yLoc[1]) 
	{
		//agk::Print("in");
	//If no path has been generated, generate one. Update it when
	//the chaser reaches its fifth step on the current path.	
		agk::Print(pathStatus[id2]);
agk::Print(notStarted);
	if (pathStatus[id2] == notStarted || pathLocation[id2] == 5)
	{
		agk::Print("in");
	//	system("pause");
		//Generate a new path. Enter coordinates of smiley sprite (xLoc(1)/
		//yLoc(1)) as the target.
		pathStatus[id2] = FindPath(id2,xLoc[id2],yLoc[id2],xLoc[1],yLoc[1]);
		
	}} 

//2/.Move chaser.
	if (pathStatus[id2] == found) MoveSprite(ID,id2);
}
void MoveSprite(int ID,int id2)
{
	agk::Print("found");
	//1.Read path information
	ReadPath(id2,xLoc[id2],yLoc[id2],speed[id2]);
	float xloctemp=xLoc[id2];
	float yloctemp=yLoc[id2];

//2.Move sprite. xLoc/yLoc = current location of sprite. xPath and
//	yPath = coordinates of next step on the path that were/are
//	read using the readPath function.
	if (xLoc[id2] > xPath[id2])
	{
		//if[
		
		xLoc[id2] =xLoc[id2] - speed[id2];
	}
	if (xLoc[id2] < xPath[id2]) xLoc[id2] = xLoc[id2] + speed[id2];
	if (yLoc[id2] > yPath[id2]) yLoc[id2] = yLoc[id2] - speed[id2];		
	if (yLoc[id2] < yPath[id2]) yLoc[id2] = yLoc[id2] + speed[id2];
	
	
//3.When sprite reaches the end location square	(end of its current
//	path) ...		
	if (pathLocation[id2] == pathLength[id2]) 
	{
//		Center the chaser in the square (not really necessary, but 
//		it looks a little better for the chaser, which moves in 3 pixel
//		increments and thus isn't always centered when it reaches its
//		target).
		if (abs(xLoc[id2] - xPath[id2]) < speed[id2]) xLoc[id2] = xPath[id2];
		if (abs(yLoc[id2] - yPath[id2]) < speed[id2]) yLoc[id2] = yPath[id2];
	}

	float angle = agk::ATanFull ( xLoc[id2] - xloctemp, yLoc[id2]- yloctemp);
	agk::SetSpriteAngle ( ID, angle+180.0f );
	agk::SetSpritePosition(ID,xLoc[id2],yLoc[id2]);
	
}
void RenderScreen()
{
}
void LoadMapData()
{
}
void MoveSmiley()
{
	float accx=0,accy=0;
			float x         = agk::GetSpriteX (  player);
			float y         = agk::GetSpriteY (  player );
			float y1;
			float x1;
			
			float joystickX = agk::GetVirtualJoystickX ( 1 );
	        float joystickY = agk::GetVirtualJoystickY ( 1 );
			accx=joystickX;
			accy=joystickY;
			//if(walkabilit
			//int temp=accy;
			if (accx!=0||accy!=0)
			{
				xLoc[1]=agk::GetSpriteX (  player ) + accx;
				yLoc[1]=agk::GetSpriteY(player)+accy;
				FindPath(2,xLoc[2],yLoc[2],xLoc[1],yLoc[1]);
				
				//pathStatus[2]=0;
			}
			else if(accx==0 &&accy==0&&agk::GetSpriteX(player)!=agk::GetSpriteX(spriteidmonsters)&&
				agk::GetSpriteY(player)!=agk::GetSpriteX(spriteidmonsters));
			{
				xLoc[1]=agk::GetSpriteX (  player ) + accx;
				yLoc[1]=agk::GetSpriteY(player)+accy;
				FindPath(2,xLoc[2],yLoc[2],xLoc[1],yLoc[1]);
			}
			int xconst=(agk::GetSpriteX (  player )-24+accx)/50;
			int yconst=(agk::GetSpriteY (  player )-13+accy)/50;
				int xconst2=(agk::GetSpriteX (  player )+24+accx)/50;
			int yconst2=(agk::GetSpriteY (  player )+18+accy)/50;
			//if(accx>0)
			//	 xconst=(agk::GetSpriteX (  player) -50+accx)/50;
			//if (yconst>0)
			//	yconst=(agk::GetSpriteY(  player) -50+accx)/50;
			//
			if(walkability[xconst][yconst]!=1&&walkability[xconst2][yconst2]!=1&&walkability[xconst][yconst2]!=1&&
				walkability[xconst2][yconst]!=1)
			{
			//if(agk::GetSpriteX(2)!=agk::GetSpriteX(1),agk::GetSpriteY(2)!=agk::GetSpriteX(2)
			//MoveSprite(spriteidmonsters,1);
			agk::SetSpritePosition ( player, agk::GetSpriteX (  player ) + accx, agk::GetSpriteY (  player) + accy );
			}
			else if (accy!=0)
			{
				//int temp=accy;
				accy=0;
				
				 xconst=(agk::GetSpriteX (  player )-24+accx)/50;
			 yconst=(agk::GetSpriteY (  player )-13+accy)/50;
				 xconst2=(agk::GetSpriteX (  player )+24+accx)/50;
			 yconst2=(agk::GetSpriteY (  player )+18+accy)/50;
			if(walkability[xconst][yconst]!=1&&walkability[xconst2][yconst2]!=1&&walkability[xconst][yconst2]!=1&&
				walkability[xconst2][yconst]!=1)
				{
				//if(agk::GetSpriteX(2)!=agk::GetSpriteX(1),agk::GetSpriteY(2)!=agk::GetSpriteX(2)
				//MoveSprite(spriteidmonsters,1);
				agk::SetSpritePosition ( player, agk::GetSpriteX (  player ) + accx, agk::GetSpriteY (  player) + accy );
				}
				else if (accx!=0)
				{
					accy=agk::GetVirtualJoystickY ( 1 );
						agk::Print("found");
					accx=0;
				
				 xconst=(agk::GetSpriteX (  player )-24+accx)/50;
				yconst=(agk::GetSpriteY (  player )-13+accy)/50;
				 xconst2=(agk::GetSpriteX (  player )+24+accx)/50;
				yconst2=(agk::GetSpriteY (  player )+18+accy)/50;
				if(walkability[xconst][yconst]!=1&&walkability[xconst2][yconst2]!=1&&walkability[xconst][yconst2]!=1&&
				walkability[xconst2][yconst]!=1)
				{
				//if(agk::GetSpriteX(2)!=agk::GetSpriteX(1),agk::GetSpriteY(2)!=agk::GetSpriteX(2)
				//MoveSprite(spriteidmonsters,1);
				agk::SetSpritePosition ( player, agk::GetSpriteX (  player ) + accx, agk::GetSpriteY (  player) + accy );
				}
				}
			}
			
	//agk::SetSpriteAngle ( spottype, angle );
}

void app::Begin ( void )
{
agk::SetVirtualResolution ( 550, 400 );
	LoadMapData();
	LoadUnitData();
	LoadGraphics();
	InitializePathfinder();
	agk::AddVirtualJoystick(1,50,agk::GetVirtualHeight()-50.0f,100.0f);

	agk::AddVirtualJoystick(2,500,agk::GetVirtualHeight()-50.0f,100.0f);

	
}

void app::Loop ( void )
{

MoveSmiley();
MoveChaser(spriteidmonsters,2);
agk::Print(xLoc[2]);
agk::Print(yLoc[2]);
//yLoc[2]=yLoc[2]--;

//for (int ID = 2; ID <= 3; ID++) 
	//MoveChaser(ID);

RenderScreen(); 
//CheckWinMessages();

	// this function gets called on a continual basis, use this to update your
	// game logic and deal with input and other events

	

	// we call agk::Sync to update the screen, when this happens our sprite
	// will get drawn on screen
	agk::Sync ( );
}

void app::End ( void )
{
}