Erm...how about a double linked list?
type tile
field image
field x
field y
field next.tile
field previous.tile
end type
Then your layers only need to function as "pointers" into individual groupings of tiles...and each tile "points" to both the next and previous tile with in the group.
sorta like this (trying to sorta diagram it out):
first these are the layers:
Layer.tile(1) -> tile 707
Layer.tile(2) -> tile 53
now for the tiles:
tile 707.previous -> Null
tile 707.next -> tile 811
tile 811.previous -> tile 707
tile 811.next -> tile 12
tile 12.previous -> tile 811
tile 12.next -> Null
tile 53.previous -> Null
tile 53.Next -> Null
(the numbers 707,811,12 are just there it identify specific tiles in the diagram, showing that the tile order is specificly controlled by the next/previous links)...notice that the first tile...the one that the layer points to...the 'previous' link value is null...and the last tile in the grouping, the 'next' link value is null...in this way you can easily check if you have reached the top or bottom of a layer grouping (and if both 'previous' and 'next' links are Null...then there it only one tile in grouping)
So useing the above...say you wanted to move tile 811 from the first to the second layer grouping...a function like this could work (assumeing that layer() is a global array )
Function movetile( me.tile, laynumber%)
;temp variables used to store the previous/next pointers
tempprevious.tile = me.previous
tempnext.tile = me.next
;swap out the previous/next pointers with the linked tiles
;effectively this removes the "me" tile from the layer group
if tempprevious then tempprevious.next = tempnext
if tempnext then tempnext.previous = tempprevious
;now set "me" previous to null (indicateing it is the first tile in a layer grouping)
me.previous = null
;then set "me" next to the first tile in the layer grouping
me.next = layer(laynumber)
;then set that tile (the first tile in the laynumber grouping)
;'previous' value to "me"
if layer(layernumber) then layer(laynumber).previous = me
;and finaly set "me" at the top of the leyer grouping
layer(laynumber) = me
end function
It's kinda hard to explain linked lists (and I likely screwed up the blitz programing syntax for types up there..which won't help)...but I hope that helps
type tile
field image
field x
field y
field next.tile
field previous.tile
end type
Then your layers only need to function as "pointers" into individual groupings of tiles...and each tile "points" to both the next and previous tile with in the group.
sorta like this (trying to sorta diagram it out):
first these are the layers:
Layer.tile(1) -> tile 707
Layer.tile(2) -> tile 53
now for the tiles:
tile 707.previous -> Null
tile 707.next -> tile 811
tile 811.previous -> tile 707
tile 811.next -> tile 12
tile 12.previous -> tile 811
tile 12.next -> Null
tile 53.previous -> Null
tile 53.Next -> Null
(the numbers 707,811,12 are just there it identify specific tiles in the diagram, showing that the tile order is specificly controlled by the next/previous links)...notice that the first tile...the one that the layer points to...the 'previous' link value is null...and the last tile in the grouping, the 'next' link value is null...in this way you can easily check if you have reached the top or bottom of a layer grouping (and if both 'previous' and 'next' links are Null...then there it only one tile in grouping)
So useing the above...say you wanted to move tile 811 from the first to the second layer grouping...a function like this could work (assumeing that layer() is a global array )
Function movetile( me.tile, laynumber%)
;temp variables used to store the previous/next pointers
tempprevious.tile = me.previous
tempnext.tile = me.next
;swap out the previous/next pointers with the linked tiles
;effectively this removes the "me" tile from the layer group
if tempprevious then tempprevious.next = tempnext
if tempnext then tempnext.previous = tempprevious
;now set "me" previous to null (indicateing it is the first tile in a layer grouping)
me.previous = null
;then set "me" next to the first tile in the layer grouping
me.next = layer(laynumber)
;then set that tile (the first tile in the laynumber grouping)
;'previous' value to "me"
if layer(layernumber) then layer(laynumber).previous = me
;and finaly set "me" at the top of the leyer grouping
layer(laynumber) = me
end function
It's kinda hard to explain linked lists (and I likely screwed up the blitz programing syntax for types up there..which won't help)...but I hope that helps