Rendering a Map?

BlitzPlus Forums/BlitzPlus Tutorials/Rendering a Map?

Mrock(Posted 2013) [#1]
I'm in the process of making a large strategy game, The type where the map is divided into a grid and units can be moved from square to square. The Wizard vs. Wizard Game example pretty much, but with much more detail. The problem is the Wizard vs. Wizard example doesn't have much explanation to how the map render functions, and since the global files are shortened and don't make much sense, I can't really understand anything that's going on. First off, how do I make a map of evenly spaced tiles? Then how do I render rivers that look like rivers? Same with forests and other terrain features. Thanks to anyone that can help!

misth(Posted 2013) [#2]
Well, firstly you have to have your map data stored, for example in an 2D array.
Then have some variables that tells you the width and height of your map and tiles.

Here's a "quick" example:
Graphics 640,480,0,2

Const MAP_WIDTH = 20
Const MAP_HEIGHT = 20

Const TILE_WIDTH = 10
Const TILE_HEIGHT = 10

; Our tilemap data is stored in this 2D array
Dim TilemapData(MAP_WIDTH, MAP_HEIGHT) ; You can also have 3rd dimension for different layers (background, overlay, hit-tiles etc...)

; Generate random map
For j = 0 To MAP_HEIGHT -1
	For i = 0 To MAP_WIDTH -1
		; Let's say that we have tile indexes from 0 to 4
		TilemapData(i, j) = Rand(0,4)

While Not KeyDown(1)

	RenderMap() ; Render our map


; The function where the magic happens!
Function RenderMap()
	For j = 0 To MAP_HEIGHT -1
		For i = 0 To MAP_WIDTH - 1
			; Get our tile's ID from the array
			tileID = TilemapData(i, j)
			; Select the right color for the ID
			Select tileID
				Case 0 ; Empty/Black tile
					Color 0,0,0
				Case 1 ; Green tile
					Color 0,255,0
				Case 2 ; Red tile
					Color 255,0,0
				Case 3 ; Blue tile
					Color 0,0,255
				Case 4 ; Magenta tile
					Color 255,0,255
			End Select
			; Calculate tile coordinates with our tile size constants
			tileX = i * TILE_WIDTH
			tileY = j * TILE_HEIGHT
			; Draw tile
			Rect tileX, tileY, TILE_WIDTH, TILE_HEIGHT
End Function

Not sure what you were looking for, but hope this helps!


P.S. My first post! Wooh! \o/

SecondaryBackup(Posted 2013) [#3]
Thanks for the post Misth.

Daza(Posted 2015) [#4]
I am going to dredge up this old post. This is a neat example of rendering a map. I am new to BlitzPlus and somewhat a beginner and i want to know how to alter this example to have a predefined tilemap.

Lets say its a 5 x 5 map just to make things easier. The example below is represent any real syntax but have used something similar before in another program. Which is visually easier to see the layout than if it were one very long array.

Map1(0) = (0,4,2,4,3)
Map1(1) = (1,3,0,4,3)
Map1(2) = (3,4,2,4,3)
Map1(3) = (1,4,2,1,2)

I was wondering how i would incorporate something like that into the example code above?


Doggie(Posted 2015) [#5]
Have you seen Mappy? Might work for what you need