Sign in to follow this  
ballerplaya

[java] Create Maps from Array

Recommended Posts

Ok, so I am working on a 2d-tile based rpg. I am stuck at the map part. I can draw maps using tiles if I specify where they go. For Example, if I wanted to do a 10x10 grid of various tiles, I would enter: map.tiles[0][0] = grassTile; . . . map.tiles[9][9] = treeTile; I would have to enter 100 tiles manually to get the effect that I want. I want to be able to create text array maps. In this example, t = tree, r = road, and w = water. http://i46.tinypic.com/9acy0o.png It would load a tile based on the letter/number/character I use and put it where its location is in the array on the map. Can someone link me to a resource on what I would need to look into? Thanks in advanced. David. [Edited by - ballerplaya on February 21, 2010 3:48:47 PM]

Share this post


Link to post
Share on other sites
Something like...
String s = null;
BufferedReader br = new BufferedReader(new FileReader("map.txt"));
int row = 0;

while ((s = br.readLine()) != null)
{
for (int col = 0; col < s.length(); col++)
{
char c = s.charAt(col);
if (c == 't')
map.tiles[row][col] = treeTile;
else if (c == 'g')
map.tiles[row][col] = grassTile;
}
row++;
}

Regards
elFarto

Share this post


Link to post
Share on other sites
Thank you very much. It works perfectly now. Now my other issue is what if I wanted to load a certain group of tiles until a character moved into a new area. How would I go about doing that?

Would i have to do separate maps then when character reaches bounds of one, change to the other(s)?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this