Jump to content
  • Advertisement
Sign in to follow this  
FireNuke

Making a map file?

This topic is 5050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!