Minimap using tilemap!

this is how i get the tiles

i have an image with different colors in it then i run this code to check what the colors are then add blocks on different colors

		for(int x = 0; x < 100;x++){
			for(int y = 0; y < 100; y++){
				
				int col = map.getRGB(x, y);
				
				switch(col & 0xFFFFFF){
					case 0x808080:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.STONE_1));
					break;
					case 0x404040:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.WALL_1).isSolid(true));
					break;
					//////////////////////////////////////////////////////////////////////////////////////////////
					case 0x664A36:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.WOOD_DOWN_MID_MID));
					break;
					case 0xFFBB87:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.WOOD_DOWN_MID_TOP));
					break;
					case 0xE5A879:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.WOOD_DOWN_MID_BOTTOM));
					break;
					
					
					case 0xD89F72:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.WOOD_DOWN_RIGHT_TOP));
					break;
					case 0x997051:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.WOOD_DOWN_RIGHT_MID));
					break;
					case 0xBF8C65:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.WOOD_DOWN_RIGHT_BOTTOM));
					break;
					
					case 0xCC956C:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.WOOD_DOWN_LEFT_TOP));
					break;
					case 0x7F5D43:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.WOOD_DOWN_LEFT_MID));
					break;
					case 0xB2825E:
						tiles.blocks.add(new Block(new Vector2F(x*48, y*48), BlockType.WOOD_DOWN_LEFT_BOTTOM));
					break;
					///////////////////////////////////////////////////////////////////////////////////////////////
				}
				
			}
		}

now how do i create a minimap? i have never done one so would be cool to know how to create one =D

You do the same thing, but instead draw to the minimap. Many people create a new view that hosts the minimap. So like a second game window inside your window.
But dunno if you are using a library or something and i haven’t worked in java for a while so can’t give any tips on how that is done.

i use normal java 2d

Just create a buffered image and change the pixel colour values to to that of your tiles and draw the image in the corner or something.

If that makes sense. Or stop using Java2D and move onto LWJGL/LibGDX and experience the awesomeness that is hardware accelerated graphics.

could you make an example?

Try it yourself , here ill give you some pseudo code.

forever x = minimap.x , x < width , x += 1){
forever y = minimap.y , y < height , y +=1){
pixels[x + (y * width)] = get_color()
}
}
Just change get color() to your method and figure out how to select the tiles.

You literally just do the same thing you’re doing now. Create a new BufferedImage and scale it down and place it where ever you want on screen.

what if i want to move it so it follows where i’am on in the big map?

You do the same thing you’d do when drawing your full map. Determine where the character is, and render x amount of “tiles” around him on the mini-map. The only difference between a mini-map and your regular map is that your regular map renders tiles at full size, but your mini-map renders the tiles at a scaled down size or representation. Beyond that, the logic and underlying data sources are the same. :wink:


A very old version of my game but it has a map and a mini map, feel free to have a look and get some ideas