[A83] Re: Tilemap
[Prev][Next][Index][Thread]
[A83] Re: Tilemap
Well that really didn't help much. A tilemap may appear to be rectangle in
code, but it is really just a bunch of bytes in a row. For instance, a 12x8
tilemap isnt like a 12x8 matrix but 96 bytes in a row. So lets take the
simple tilemap of a room:
map:
.db 1,1,1,1,1,1,1,1,1,1,1,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,0,0,0,0,0,0,0,0,0,0,1
.db 1,1,1,1,1,1,1,1,1,1,1,1
when a tilemap is displayed, it starts at the label. In this case, map. It
will take each byte and multiply its value by 8. it will then add that
number of bytes to the sprite data location:
Sprites:
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
Therefore, if it reads a 1, it will multiply it by 8 and get 8. then it will
add 8 to Sprites to get the second sprite in the list. This is the sprite it
will display at the coordinates which should be kept in the routine.
If you want to get the value of a certain tile, use the algorith 12Y+X.
Since these are all just bytes in a row and there are 12 bytes per row, for
every row you need to go down you must add 12. Then you finally add X.
So if you want to get the data at (1,1), you would actually add 13 to the
tilemap location.
this little demo takes (X) and (Y) and gets the location and returns it in
the accumluator:
FindTile:
ld hl,(Y) ;ld h=(Y+1) and l = (Y)
ld h,0 ;make hl = Y
add hl,hl ;2hl
add hl,hl ;4hl
ld d,h ;make de = hl to add to 8hl
ld e,l
add hl,hl ;8hl
add hl,de ;12hl
ld de,(X) ;ld d=(X+1) and e = (X)
ld d,0 ;make de = X
add hl,de ;12y+x done...
ld de,Sprites ;data location of tiles
add hl,de ;add 12y+x to this location
ld a,(hl) ;load a with the value at our new location
ret
Anyway, I hope this helps... if you need more info or an actual compileable
demo, email me, ive made a few.
-Joel Seligstein
joel@basm.org
www.basm.org