Try this approach it is very versatile
Gosub Setup
MakeBoard()
Player(1).x = 2 : Player(2).y = 3 : rem set initial position
MakePlayer()
do
MovePlayer() : Rem Checks to see if move Available
SetSpeed() : Rem Allows user to control speed of program
Text Gridsize * 15, 20, Str$(Screen FPS()) : Rem Prints Frames Per second
Sync
loop
Function SetSpeed()
IF upkey() THEN Inc Speed
If DownKey() Then Dec Speed
Sync Rate Speed
EndFunction
Function MakeBoard()
Rem Simply Draws a Grid
ink RGB(255,255,255),0
Box 0,0,12*GridSize,12*GridSize
Ink RGB(255,0,0),0
For y = 0 to 11
For x = 0 to 11
Left = x*GridSize : Top = y * GridSize : Right = (x+1)*GridSize : Bottom = (y+1)*GridSize
IF Grid(x,y) = 1 then ink RGB(255,0,0),0: Box Left,Top,Right,Bottom:
ink RGB(255,0,0),0: Line left, top, right, top : Line Right, Top, Right,Bottom : Line Right,Bottom,Left,Bottom, : Line Left,Bottom, Left,Top
Next x
Next y
Get Image 1,0,0,12*GridSize,12*GridSize
Sprite 1,0,0,1
EndFunction
Function MakePlayer()
Rem Draws a Circle Same dia as Grid
Cls
ink RGB(0,255,0),RGB(0,0,0)
circle Gridsize/2,Gridsize/2,Gridsize/2
get image 2 ,0,0,GridSize,GridSize
Sprite 2,Player(1).x*Gridsize,Player(1).y*Gridsize,2
EndFunction
Function MovePlayer()
Repeat
Moved = 0
NewX = Rnd(2)-1 : NewY = Rnd(2)-1 : Rem Returns a value between -1 and 1
If Grid(Player(1).Y + NewY, Player(1).X + NewX)= 0
Player(1).Y = Player(1).Y + NewY : Player(1).X = Player(1).X+ NewX
Sprite 2,Player(1).Y*GridSize,Player(1).X*Gridsize,2
Moved = 1
endif
Until Moved = 1
EndFunction
Setup:
Randomize timer()
GLOBAL Speed = 60
Sync On
Sync Rate 20
#Constant GridSize = 30
Type Player1
x as integer
y as integer
endtype
Dim Player(1) as Player1
Dim Grid (11,11)
restore Grid1
For Y = 0 to 11
For X = 0 to 11
Read Grid(x,y)
Next X
Next Y
Return
Grid1:
data 1,1,1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,1,1,0,0,0,1
data 1,0,0,0,0,0,1,1,0,0,0,1
data 1,0,0,0,0,0,0,1,0,0,0,1
data 1,0,0,1,1,1,0,0,0,0,0,1
data 1,0,0,1,0,1,0,0,0,0,0,1
data 1,0,0,1,0,1,0,0,0,0,0,1
data 1,0,0,1,0,1,0,0,0,1,1,1
data 1,0,0,1,0,0,0,0,1,0,0,1
data 1,0,0,1,0,0,0,0,1,0,0,1
data 1,1,1,1,1,1,1,1,1,1,1,1
System
PIII 650 MZ H.P. Pavillion
394 Mem GeForce 4 400MX