#constant TILESIZEX 50
#constant TILESIZEY 50
#constant MAPSIZEX 50
#constant MAPSIZEY 50
#constant RENDERLISTSIZE 1000
#constant MOVESPEEDX 1
#constant MOVESPEEDY 1
sync on
sync rate 60
load image "tile.bmp",1,1
load image "tile2.bmp",2,1
type map_data
img as word
tipe as byte
endtype
type render_list
img as word
x as integer
y as integer
tipe as byte
endtype
dim mapData(MAPSIZEX, MAPSIZEY) as map_data
dim renderList(RENDERLISTSIZE) as render_list
global mapPosX as word
global mapPosY as word
global mapScrollX as integer
global mapScrollY as integer
global mapScroll as byte
FillMap(1,1)
for x=0 to 20
randX = rnd(20)
randY = rnd(20)
mapData(randX,randY).img=2
mapData(randX,randY).tipe=1
next x
do
if upkey()
if mapScroll=0 and mapPosY>1 then MoveMap(0, -1)
endif
if downkey()
if mapScroll=0 and mapPosY+10<MAPSIZEY then MoveMap(0, 1)
endif
if leftkey()
if mapScroll=0 and mapPosX>1 then MoveMap(-1, 0)
endif
if rightkey()
if mapScroll=0 and mapPosX+13<MAPSIZEX then MoveMap(1, 0)
endif
Scroll()
ResetRenderList()
MapDraw()
Render()
sync
loop
FUNCTION Scroll()
if mapScroll=1
if mapScrollY<0 then inc mapScrollY,1
if mapScrollY>0 then dec mapScrollY,1
if mapScrollX<0 then inc mapScrollX,1
if mapScrollX>0 then dec mapScrollX,1
if mapScrollY=0 and mapScrollX=0 then mapScroll=0
endif
ENDFUNCTION
FUNCTION MoveMap(xAmount, yAmount)
mapScroll = 1
mapScrollX = xAmount * TILESIZEX
mapScrollY = yAmount * TILESIZEY
mapPosX = mapPosX+xAmount
mapPosY = mapPosY+yAmount
ENDFUNCTION
FUNCTION FillMap(image, tipe)
for x = 0 to MAPSIZEX
for y = 0 to MAPSIZEY
mapData(x,y).img = image
mapData(x,y).tipe = tipe
next y
next x
ENDFUNCTION
FUNCTION MapDraw()
for x = mapPosX-1 to mapPosX+13
for y = mapPosY-1 to mapPosY+10
if x>-1 and y>-1
if mapData(x,y).tipe>0
xPixel = (x-mapPosX) * TILESIZEX
yPixel = (y-mapPosY) * TILESIZEY
if xPixel>-51 and yPixel>-51 and xPixel<691 and yPixel<531
AddToRenderList(mapData(x,y).img, xPixel+mapScrollX, yPixel+mapScrollY, 1)
endif
endif
endif
next y
next x
ENDFUNCTION
FUNCTION AddToRenderList(image, xPos, yPos, tipe)
for x = 0 to RENDERLISTSIZE
if renderList(x).img=0 then index = x : exit
next x
renderList(index).img = image
renderList(index).x = xPos
renderList(index).y = yPos
renderList(index).tipe = tipe
ENDFUNCTION
FUNCTION ResetRenderList()
for x = 0 to RENDERLISTSIZE
renderList(x).img = 0
renderList(x).x = 0
renderList(x).y = 0
renderList(x).tipe = 0
next x
ENDFUNCTION
FUNCTION Render()
cls
for x = 0 to RENDERLISTSIZE
if renderList(x).tipe>0
paste image renderList(x).img,renderList(x).x,renderList(x).y
endif
next x
ENDFUNCTION
Taken from a tutorial I was making..
"Lets migrate like bricks" - Me