Hi Phaelax,
You were right about the map data not being formatted properly, I had the X value being read first rather than the Y
Phaelax's function:
function loadTileMap(filename as string , imgOffset as integer , tileSize as integer)
//can be changed if these numbers are already used elsewhere
local memNoMap = 1
local memNoTile = 2
local imgNoMap = 1
local color as dword
//load the tilemap image
load image filename, imgNoMap
//create the memblock to store the individual tiles
make memblock memNoTile, 12 + tileSize * tileSize * 4
write memblock dword memNoTile, 0, tileSize
write memblock dword memNoTile, 4, tileSize
write memblock dword memNoTile, 8, 32
//create memblock from the tilemap image
make memblock from image memNoMap, imgNoMap
imgWidth = memblock dword (memNoMap, 0)
imgHeight = memblock dword (memNoMap, 4)
//determine how many tile rows and columns there are in the image
tileCols = imgWidth / tileSize
tileRows = imgHeight / tileSize
//tile offset calculations
colTileOffset = tileSize * 4
rowTileOffset = imgWidth * 4 * tileSize
//loop through the tiles in the image
for y = 0 to tileRows - 1
for x = 0 to tileCols - 1
col = x * colTileOffset
row = y * rowTileOffset
//tile offset within image
tileOffset = row + col + 12
//extract pixel data from tilemap and store
//a "tileSize by tileSize" image tile into the other memblock
for iy = 0 to tileSize - 1
for ix = 0 to tileSize * 4 - 1 step 4
ty = iy * imgWidth * 4
pos = tileOffset + ty + ix
//extra pixel colour from larger tilemap
color = memblock dword (memNoMap, pos)
tilePos = iy * tileSize * 4 + ix + 12
//write pixel colour to smaller tile image
write memblock dword memNoTile, tilePos, color
next ix
next iy
//create an image from tile memblock then repeat process
make image from memblock imgOffset, memNoTile
inc imgOffset, 1
next x
next y
//free up memory
delete memblock memNoMap
delete memblock memNoTile
//since DB can't handle expressions in the endfunction
dec imgOffset, 1
endfunction
Now I've found another headache, here's what I mean:
//Place each tile where the map is read from.
for mapX = 0 to screen width() / ts
for mapY = 0 to screen height() / ts
mapAssets = mapAssets + 1
read map(mapX, mapY)
makeWorld()
next mapY
next mapX
my makeWorld function:
function makeWorld()
select map(mapX, mapY)
case 0: sprite mapAssets, mapX * ts, mapY * ts, 381 :endcase
case 1: sprite mapAssets, mapX * ts, mapY * ts, 1 :endcase
case 2: sprite mapAssets, mapX * ts, mapY * ts, 2 :endcase
case 3: sprite mapAssets, mapX * ts, mapY * ts, 3 :endcase
case 4: sprite mapAssets, mapX * ts, mapY * ts, 4 :endcase
case 5: sprite mapAssets, mapX * ts, mapY * ts, 5 :endcase
case 6: sprite mapAssets, mapX * ts, mapY * ts, 6 :endcase
case 7: sprite mapAssets, mapX * ts, mapY * ts, 7 :endcase
case 8: sprite mapAssets, mapX * ts, mapY * ts, 8 :endcase
case 9: sprite mapAssets, mapX * ts, mapY * ts, 9 :endcase
case 10: sprite mapAssets, mapX * ts, mapY * ts, 10 :endcase
case 11: sprite mapAssets, mapX * ts, mapY * ts, 12 :endcase
case 12: sprite mapAssets, mapX * ts, mapY * ts, 12 :endcase
case 13: sprite mapAssets, mapX * ts, mapY * ts, 13 :endcase
case 14: sprite mapAssets, mapX * ts, mapY * ts, 14 :endcase
case 15: sprite mapAssets, mapX * ts, mapY * ts, 15 :endcase
case 16: sprite mapAssets, mapX * ts, mapY * ts, 16 :endcase
case 17: sprite mapAssets, mapX * ts, mapY * ts, 17 :endcase
case 18: sprite mapAssets, mapX * ts, mapY * ts, 18 :endcase
case 19: sprite mapAssets, mapX * ts, mapY * ts, 19 :endcase
case 20: sprite mapAssets, mapX * ts, mapY * ts, 20 :endcase
case 21: sprite mapAssets, mapX * ts, mapY * ts, 21 :endcase
case 22: sprite mapAssets, mapX * ts, mapY * ts, 22 :endcase
case 23: sprite mapAssets, mapX * ts, mapY * ts, 23 :endcase
case 24: sprite mapAssets, mapX * ts, mapY * ts, 24 :endcase
case 25: sprite mapAssets, mapX * ts, mapY * ts, 25 :endcase
case 26: sprite mapAssets, mapX * ts, mapY * ts, 26 :endcase
case 27: sprite mapAssets, mapX * ts, mapY * ts, 27 :endcase
case 28: sprite mapAssets, mapX * ts, mapY * ts, 28 :endcase
case 29: sprite mapAssets, mapX * ts, mapY * ts, 29 :endcase
case 30: sprite mapAssets, mapX * ts, mapY * ts, 30 :endcase
case 31: sprite mapAssets, mapX * ts, mapY * ts, 31 :endcase
case 32: sprite mapAssets, mapX * ts, mapY * ts, 32 :endcase
case 33: sprite mapAssets, mapX * ts, mapY * ts, 33 :endcase
case 34: sprite mapAssets, mapX * ts, mapY * ts, 34 :endcase
case 35: sprite mapAssets, mapX * ts, mapY * ts, 35 :endcase
case 36: sprite mapAssets, mapX * ts, mapY * ts, 36 :endcase
case 37: sprite mapAssets, mapX * ts, mapY * ts, 37 :endcase
case 38: sprite mapAssets, mapX * ts, mapY * ts, 38 :endcase
case 39: sprite mapAssets, mapX * ts, mapY * ts, 39 :endcase
case 40: sprite mapAssets, mapX * ts, mapY * ts, 40 :endcase
case 41: sprite mapAssets, mapX * ts, mapY * ts, 41 :endcase
case 42: sprite mapAssets, mapX * ts, mapY * ts, 42 :endcase
case 43: sprite mapAssets, mapX * ts, mapY * ts, 43 :endcase
case 44: sprite mapAssets, mapX * ts, mapY * ts, 44 :endcase
case 45: sprite mapAssets, mapX * ts, mapY * ts, 45 :endcase
case 46: sprite mapAssets, mapX * ts, mapY * ts, 46 :endcase
case 47: sprite mapAssets, mapX * ts, mapY * ts, 47 :endcase
case 48: sprite mapAssets, mapX * ts, mapY * ts, 48 :endcase
case 49: sprite mapAssets, mapX * ts, mapY * ts, 49 :endcase
case 50: sprite mapAssets, mapX * ts, mapY * ts, 50 :endcase
case 51: sprite mapAssets, mapX * ts, mapY * ts, 51 :endcase
case 52: sprite mapAssets, mapX * ts, mapY * ts, 52 :endcase
case 53: sprite mapAssets, mapX * ts, mapY * ts, 53 :endcase
case 54: sprite mapAssets, mapX * ts, mapY * ts, 54 :endcase
case 55: sprite mapAssets, mapX * ts, mapY * ts, 55 :endcase
case 56: sprite mapAssets, mapX * ts, mapY * ts, 56 :endcase
case 57: sprite mapAssets, mapX * ts, mapY * ts, 57 :endcase
case 58: sprite mapAssets, mapX * ts, mapY * ts, 58 :endcase
case 59: sprite mapAssets, mapX * ts, mapY * ts, 59 :endcase
case 60: sprite mapAssets, mapX * ts, mapY * ts, 60 :endcase
case 61: sprite mapAssets, mapX * ts, mapY * ts, 61 :endcase
case 62: sprite mapAssets, mapX * ts, mapY * ts, 62 :endcase
case 63: sprite mapAssets, mapX * ts, mapY * ts, 63 :endcase
case 64: sprite mapAssets, mapX * ts, mapY * ts, 64 :endcase
case 65: sprite mapAssets, mapX * ts, mapY * ts, 65 :endcase
case 66: sprite mapAssets, mapX * ts, mapY * ts, 66 :endcase
case 67: sprite mapAssets, mapX * ts, mapY * ts, 67 :endcase
case 68: sprite mapAssets, mapX * ts, mapY * ts, 68 :endcase
case 69: sprite mapAssets, mapX * ts, mapY * ts, 69 :endcase
case 70: sprite mapAssets, mapX * ts, mapY * ts, 70 :endcase
case 71: sprite mapAssets, mapX * ts, mapY * ts, 71 :endcase
case 72: sprite mapAssets, mapX * ts, mapY * ts, 72 :endcase
case 73: sprite mapAssets, mapX * ts, mapY * ts, 73 :endcase
case 74: sprite mapAssets, mapX * ts, mapY * ts, 74 :endcase
case 75: sprite mapAssets, mapX * ts, mapY * ts, 75 :endcase
case 76: sprite mapAssets, mapX * ts, mapY * ts, 76 :endcase
case 77: sprite mapAssets, mapX * ts, mapY * ts, 77 :endcase
case 78: sprite mapAssets, mapX * ts, mapY * ts, 78 :endcase
case 79: sprite mapAssets, mapX * ts, mapY * ts, 79 :endcase
case 80: sprite mapAssets, mapX * ts, mapY * ts, 80 :endcase
case 162: sprite mapAssets, mapX * ts, mapY * ts, 162 :endcase
case 380: sprite mapAssets, mapX * ts, mapY * ts, 380 :endcase
case default: sprite mapAssets, mapX * ts, mapY * ts, 381 :endcase
endselect
endfunction
My function has a rather large select -> case statement. Which for 381 tiles isn't fun to write out.
Is there a better way of doing this? (please give code examples) I've tried using for-next but that just gives me a load of trees or crashes completely.
I guess a tweak or so to Phaelax's function might be the answer but I get lost with some of the maths.
Thanks in advance.
Your skills are no match for the Power of DarkBASIC Pro!