Can I Improve this level loader?

I am in the process of practising loading from files, using 2D arrays and such and decided to make a project off it. It will basically be a top down 2D shooter with predefined “puzzle” levels.

At first I tried to create these levels in a text file using certain values for certain tile types, that was just shit to look at.

So decided to, instead draw my levels in Photoshop and read the pixel color data and determine what should be created at that location. I am using Box2D and each of my tiles is 1x1 at the moment, I might make them smaller but anyway, enough talking.

I am looking for ways to improve this, as it stands it can read an image file easy enough, it knows that a pixel of pure black = a wall and white = empty etc etc.

Here it is:

This is my LevelLoader class, it reads an image file (hard coded atm) and reads the pixel data which is then converted to a binary string and stored in 2D array. The Level class calls both methods in here, obviously it calls Load() first then Generate().



public class LevelLoader {

	/** How many cells along the x axis the level has */
	public int width;
	/** How many cells along the y axis the level has */
	public int height;
	/** Pixel information for each cell */
	public String[][] cells;

	/** Image to read the file from */
	Pixmap levelInfo;
	
	// Constructor omitted, it's default


/**
	 * Load an image from file and store it in memory, read the information and
	 * store it in the array for generation
	 */
	public void load() {

		try {
			levelInfo = new Pixmap(
					Gdx.files.internal("data/levels/leveltest.png"));
			width = levelInfo.getWidth();
			height = levelInfo.getHeight();
			cells = new String[width][height];
			for (int x = 0; x < levelInfo.getWidth(); x++) {
				for (int y = 0; y < levelInfo.getHeight(); y++) {
					String val = Integer.toBinaryString(levelInfo
							.getPixel(x, y));
					cells[x][y] = val;
					// System.out.print(" " + cells[x][y]);
				}
				// System.out.println("");
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			levelInfo.dispose();
		}

	}

/**
	 * Generate the level
	 * 
	 * @param level
	 *            give reference to level in order to add the tiles to an array
	 */
	public void generate(Level level) {
		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++) {
				TileType type = TileType.getType(cells[x][y]);
				if (type == null)
					continue;
				switch (type) {
				case WALL:
					level.tiles.add(new Wall(x + 1, y + 1));
					break;
				case PLAYER_SPAWN:
					level.player = new Player(x + 1, y + 1);
					break;
				case EMPTY:
					level.tiles.add(new Empty(x + 1, y + 1));
				default:
					break;
				}
			}
		}

	}



The Generate() method is what I am not sure of, it works but is it ideal/efficient? It basically reads the data in the array (which is a bunch of binary data) and then compares to to an enum using a hashmap here:



public enum TileType {
		PLAYER_SPAWN("111111110000000011111111"),
		WALL("11111111"),
		EMPTY("11111111111111111111111111111111");

		/** Used to search through the ID's of the cell enums */
		private static final HashMap<String, TileType> search = new HashMap<String, TileType>();

		/** Binary ID of the cell */
		String binary;

		private TileType(String binary) {
			this.binary = binary;
		}

		public String getBinary() {
			return binary;
		}

		/** Iterate through enum and assign values to map */
		static {
			for (TileType type : EnumSet.allOf(TileType.class)) {
				search.put(type.getBinary(), type);
			}
		}

		/** Get the type of this cell given its binary data */
		public static TileType getType(String id) {
			return search.get(id);
		}

	}


Is there any improvements you can see on this? At first I used text files, then I used buffered image and read the RBG formats and converted to Hex, that was just horrible. I can easily draw my levels in an image editor this way and any time I want to add a new object to the generation, all I need to do is take the hex value of the colour from the editing program and convert it to binary and add it to the enum.

At the moment all it will be generating is walls, the player and empty cells.

Just to clarify why I am creating empty cells, it just makes it easier to spawn enemies/drops during the game without them landing inside any walls and stuff.