Advertisement

Hmm im getting tired with file IO.

Started by November 13, 2002 03:51 AM
-1 comments, last by PerkanusRex 22 years ago
The file content looks like this. <--- CUT HERE ---> 0 0 3 1 0 1 2 0 1 3 0 4 0 1 2 1 1 0 2 1 0 3 1 2 0 2 7 1 2 1 2 2 1 3 2 8 <--- CUT HERE ---> 1st Column is X position on the grid. 2nd Column is Y position on the grid. 3rd Column is the bitmap to use from the RECT. The result would be a map looking like this. #### # # #### So far so good. I dont think the file IO is the problem but who knows. My file parsing looks like this. BOOL Init_SetupMap() { int nNodes[3]; int x = 0; int y = 0; FILE *fpMap; if ( ( fpMap = fopen( NODE_FILE, "r") ) == NULL ) { return false; } for (x = 0; x < NUM_OF_BLOCKS_X; x++) for (y = 0; y < NUM_OF_BLOCKS_Y; y++) { if ( fscanf( fpMap, "%d %d %d", &nNodes[0], &nNodes[1], &nNodes[2] ) == NULL ) { return false; } cNodeMap[x][y] = new Node(nNodes[0], nNodes[1],nNodes[2]); } if ( fclose( fpMap ) == EOF ) { return false; } return true; } The map appears in the game. No problems there, but if i check the cNodeMap by using for loops everything seems not to be there. Node Class class Node { public: bool mf_bReturnCurrentNode(int x, int y); bool mv_bOccupied; bool mf_bIsItMe(int, int); int mv_iBitmapRectangle; int mv_iPathFindingLevel; int mv_iPositionY; int mv_iPositionX; nodeBoundary mv_sBoundarySE; nodeBoundary mv_sBoundarySW; nodeBoundary mv_sBoundaryNE; nodeBoundary mv_sBoundaryNW; Node::Node(int, int, int); virtual ~Node(); }; Constructor. Node::Node(int x, int y, int p) { // Set the x and y position // this->mv_iPositionX = x; this->mv_iPositionY = y; this->mv_iBitmapRectangle = p; // Set boundaries // // NW (It is even the draw position of the node. this->mv_sBoundaryNW.iX = x * BLOCK_SIZE; this->mv_sBoundaryNW.iY = y * BLOCK_SIZE; // NE this->mv_sBoundaryNE.iX = (x + 1) * BLOCK_SIZE; this->mv_sBoundaryNE.iY = y * BLOCK_SIZE; // SW this->mv_sBoundarySW.iX = x * BLOCK_SIZE; this->mv_sBoundarySW.iY = (y + 1) * BLOCK_SIZE; // SE this->mv_sBoundarySE.iX = (x +1) * BLOCK_SIZE; this->mv_sBoundarySE.iY = (y +1) * BLOCK_SIZE; this->mv_bOccupied = false; if (p == 0) { this->mv_iPathFindingLevel = 1; } else { this->mv_iPathFindingLevel = 5; } } cNodeMap is an array of Nodes[NUM_OF_BLOCKS_X][NUM_OF_BLOCKS_Y]. My problem is that i implemented AStar algorithm to find my way around, thus the mv_iPathFindingLevel in the Node class. AStar is to be found at http://www.generation5.org. My Actor Class have an int Array of size [NUM_OF_BLOCKS_X][NUM_OF_BLOCKS_Y] where i store the mv_iPathFindingLevel for each individual node so i can get a path. Should i use a Node pointer and add a next - prev Node pointer instead of an array when i create my Node Map???? BR /PerkanusRex . P.S. If you wanna check the code itself i''ll send you my VC++ project. ( No secret code here )

This topic is closed to new replies.

Advertisement