Programming => General Java Game Development => Topic started by: liamsdomain on August 15, 2011, 21:20:10

Title: 2D Map Loading
Post by: liamsdomain on August 15, 2011, 21:20:10
I am making my first game in java and I was wondering if someone could help me with map loading. I'm making a 2D game (similar to the style of the pokemon games, but with a different goal in the game) that has random generated worlds, I want to store the worlds in a text file with some sort of format like...


With the 8's being non-passable objects like walls and the 0's being passable objects like the ground.

I am drawing a blank on how I could load and save these files easily in JAVA and then store them in an Array of some kind.

Thanks in advance.
Title: Re: 2D Map Loading
Post by: Fool Running on August 16, 2011, 12:37:56
Read in the text file line-by-line and then look at each character in the string. If the character is an '8', then put a value (easiest would be an 8 ) into the array at the same location (i.e. line number/character number).

To save back to the file, just reverse the above logic.

This is basic programming stuff. You might want to brush up on programming basics before you attempt a game.

EIDT: Google is also your friend (quick search for "java reading text file": http://www.roseindia.net/java/beginners/java-read-file-line-by-line.shtml)