Skip to main content
GameDev.net gamedev.net
🔒 Locked

Making a map file?

Started by FireNuke Nov 26, 2004 at 11:23 AM 1 replies 550+ views
Original Post
FireNuke
FireNuke
Okay, so I want to make a simple (very simple) map file. How would I go about doing that? Legend: 0 = Tile 0 (water loc: 0x32) 1 = Tile 1 (grass loc: 0x64) 2 = Tile 2 (gravel loc: 0x96) Mapfile: 20,15 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,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,1,1,1 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 How would assign tild ids? How would I read lines? etc...
Doggan
Doggan
Well, the first step is to read the values of the file into an array in your application. Where input_file is an ifstream, and temp is an integer.

	for ( all the rows in your file ) {		for ( all the columns in your file ) {			input_file >> temp;			YourMap[ y ][ x ] = temp;		}	}


Now you have everything you need. Hardcoded in your game, you should have each of the tiles you use in some texture[] array, so that you can reference them as such (texture[0] is grass, texture[1] is water, etc..)

In you drawing routine, then, you loop through each element of your 2d YourMap array, and draw the corresponding tile.

	for ( all the rows y ) {		for ( all the columns x ) {			int tile = YourMap[ y ][ x ];			glBindTexture(GL_TEXTURE_2D, texture[ tile ] ); // OpenGL example.			// draw it here.		}	}


That's the general idea. If you need more help reading lines and such from a file, do a forum search as there are tons of posts.
unfinished
unfinished
Sound like your doing it same way as me

read map section into its storage area (LevelData)

My Textures start at 1 just modify the -48 to your needs

glBindTexture(GL_TEXTURE_2D, texture[LevelData[n++]-48]); // Select Our Texture

int LevelBoxDraw(){	int	n=0;		glTranslatef(-42.0f,-28.0f,-74.0f);					// Move Left 1.5 Units And Into The Screen 6.0	glColor3f(1.0f,1.0f,1.0f);							// Set The Color To Blue One Time Only	glBindTexture(GL_TEXTURE_2D, texture[0]);			// Select Our Texture		for (float y = 0; y <= 14; y++)				//   Add one to take into account the loop	{		for (float x = 0; x <= 19; x++)		{//			glBindTexture(GL_TEXTURE_2D, texture[0]);			// Select Our Texture			glBindTexture(GL_TEXTURE_2D, texture[LevelData[n++]-48]);			// Select Our Texture			glTranslatef(4.0f,0.0f,0.0f);						// Move Right 3 Units			glBegin(GL_QUADS);									// Draw A Quad			glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.0f, -2.0f,  1.0f);	// Bottom Left Of The Texture and Quad			glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.0f, -2.0f,  1.0f);	// Bottom Right Of The Texture and Quad			glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.0f,  2.0f,  1.0f);	// Top Right Of The Texture and Quad			glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.0f,  2.0f,  1.0f);	// Top Left Of The Texture and Quad			glEnd();											// Done Drawing The Quad		}		glTranslatef(-x*4,4.0,0.0f);						// Move Right x Units		glColor3f(1.0f,1.0f,1.0f);							// Set The Color To Time Only	}	return	TRUE;}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.