One simple way is to use the DATA statement. Funny I just threw this code into one of the DBPro thread but I guess I can pop it here too for your convenience.
REM Program Name: 2D Array Collision Example
REM Author: Ashingda27
REM Date: 5/01/2010
REM ========================================
`Setup
gosub Initialize
`Main Loop
do
`The Game Routine
gosub Game
`Screen Update
sync
loop
Game:
`Draw the Terrain
for lpy = 0 to MapY
for lpx = 0 to MapX
`Map Data 0 is Sky
`Map Data 1 is Brick
if Map(lpx,lpy) = 0 then ink rgb(200,230,255),0
if Map(lpx,lpy) = 1 then ink rgb(255,55,35),0
`Draw the Tile Colors
box lpx*32,lpy*32,lpx*32+32,lpy*32+32
next lpx
next lpy
`Draw the Char
ink rgb(50,155,80),0
circle CharX,CharY-16,16
dot CharX,CharY,rgb(255,255,255)
`Jumping
if upkey() and Ground = 0
Jump = 10
endif
if Jump
if Map(CharX/32,(CharY-Jump)/32) = 0 `CollisionCheck with Map CharY-Jump
dec CharY,Jump
else
Jump = 0
endif
if Jump > 0 then dec Jump
endif
`Moveing Left & Right
if leftkey()
if Map((CharX-1)/32,CharY/32) = 0 `CollisionCheck with Map CharX-1
dec CharX
endif
endif
if rightkey()
if Map((CharX+1)/32,CharY/32) = 0 `CollisionCheck with Map CharX+1
inc CharX
endif
endif
`Gravity
if Map(CharX/32,(CharY+1)/32) = 0 `CollisionCheck with Map CharY+1
inc CharY
Ground = 1
else
Ground = 0
endif
return
Initialize:
sync on
sync rate 30
`Terrain Data
data 1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,1
data 1,1,1,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,1,1,1,0,0,0,0,1,1
data 0,0,0,1,1,1,1,1,0,0
`Terrain Size
MapX = 9
MapY = 5
`Terrain Array
dim Map(MapX,MapY)
`Reading Terrain Data
for lpy = 0 to MapY
for lpx = 0 to MapX
read Map(lpx,lpy)
next lpx
next lpy
`Character start posision
CharX = 32
CharY = 32
return
You can clearly see in the data list how it looks like in the program. There are 10 across and 6 down and the MapX and MapY are variables that matches those value.
There are 10 across but MapX=9, that is because 0 is also counted and is considered 1 thus 9 is 10.
In this example I only have 2 different terrains, 0=Sky and 1=Brick. You can easily add more by adjusting here and there...
I not sure exactly what type of game you are making but you now have 2 types of examples.
I recommend you to store your terrain data with it's Image ID.
`So if you load your image as:
load image "cat.png",100,1
`Then you but it into the array as 100.