What a lot of people do for simple tile-based games is they store levels as images where each pixel corresponds to one tile.
Colors are stores in images as integers, with a component for the red, green, and blue values of the colors (more here
http://en.wikipedia.org/wiki/RGB_color_model)
You can make these images in something simple like MS Paint or GIMP or Paint.NET. For example, a floor tile could be represented as a white pixel, while a wall tile could be a black pixel. A health pickup could be red, an enemy could be green, and so on. You can load this image into your game and have the computer make an array of ints, where you then say, "Okay, if this pixel here is white, put a floor tile in the game world at these coordinates. If it's black, make a wall" and so on.
What's nice about this is that you can pretty easily edit levels on the fly by just opening up the paint program.
Here's a method I made for one of my games to get the int[][] of colors out of the original image:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public int[][] loadRGBMap(String directory){ int[][] map; BufferedImage img = ResourceLoader.loadImage(directory);
int w = img.getWidth(); int h = img.getHeight(); int[] pixels = new int[w * h]; img.getRGB(0, 0, w, h, pixels, 0, w); map = new int[w][h]; levelMap = new boolean[w][h]; for(int row = 0; row < h; row++){ for(int col = 0; col < w; col++){ map[col][row] = pixels[row*w+col]; } } return map; } |
"directory" is just where the map is stored, ie "levels/level1.png"
"ResourceLoader" happens to be my own class, but all it does it load a BufferedImage
Hopefully that should get you started