This is my second attempt at creating 2D level walls or borders. This time I am using sprites. The movement is very primitive, but I hope to add animation in my next attempt. You need the images below copied into your Liberty BASIC folder. Also added the bas file just in case you don't feel like copying or pasting.



'basic
 <span style="font-size: 1.1em;">'basic 2d game level wall/border example 2 
'using sprites
'programmed by Ben Jimenez
'8=up 6=right 2=down 4=left 7=up/left
'9=up/right 1=down/left 3=down/right
'July 22,2011


nomainwin noMainWin

WindowWidth = 470
WindowHeight = 500
CPU=100

open "Cave dude eat food" for graphics_nsb_nf as #main
#main,"trapclose [endOfProgram]; down"

print #main, "font ms_sans_serif 0 16"

loadbmp "sprite1","cave1.bmp"
loadbmp "tree","tree.bmp"
loadbmp "food","food.bmp"

print #main, "addsprite sprite1 sprite1"; sprite1"

dim pxy$(22,22)

'start postion of first wall piece
x=10
y=20

for r=1 to 22 'current 'first row
for c=1 to 22 'current row column loop
read d$
pxy$(r,c)=d$
if d$="t" then 'draw tree
tcnt=tcnt+1
#main,"addsprite tree";tcnt;" tree"
#main,"spritexy tree";tcnt;" ";x;" ";y
end if


if d$="f" then 'draw food
fcnt=fcnt+1
#main,"addsprite food";fcnt;" food"
#main,"spritexy food";fcnt;" ";x+5;" ";y+10
food=food+1
end if

if d$="s" then 'draw player
#main,"spritexy sprite1 ";x;" ";y
#main,"spritescale sprite1 40"
px=x 'set current pen x position to player start x
py=y ' set current pen y position to player start y
ar=r 'remember current row location
ac=c 'remember current column locaton
end if

x=x+20 'increase column x location by 20
next c
x=10
y=y+20 'increase row y location by 20
next r

#main,"when characterInput [checkkey]" [checkKey]"
#main,"setfocus"
goto [checkKey]


[main.inputLoop] 'wait here for input event #main,"setfocus"
#main,"drawsprites"

if pxy$(ar,ac)="e" and food=0 then
notice "You collected all the food and escaped!"
end if

if pxy$(ar,ac)="e" and food>0 then
notice "You need to collect more food!"
end if

wait

[checkkey] [checkKey]

'player move loop
'player can move as long as his path
'is not blocked by tree
key$ = Inkey$

if len(key$) < 2 then

#main,"drawsprites; segment segNum"
#main,"getbmp bg 0 0 ";WindowWidth;" ";WindowHeight;";place 0 0; drawbmp bg; flush bg"
#main,"delsegment ";segNum-1

if key$="2" then 'down


if pxy$(ar+1,ac)<>"t" then 'if next space is not a tree
py=py+20
#main,"spritexy sprite1 ";px;" ";py
ar=ar+1

end if

end if

if key$="6" then 'right
if pxy$(ar,ac+1)<>"t" then 'if next space is not a tree

px=px+20

#main,"spritexy sprite1 ";px;" ";py
ac=ac+1

end if
end if

if key$="4" then 'left
if pxy$(ar,ac-1)<>"t" then 'if next space is not a tree

px=px-20

#main,"spritexy sprite1 ";px;" ";py
ac=ac-1

end if

end if

if key$="8" then 'up
if pxy$(ar-1,ac)<>"t" then 'if next space is not a tree

py=py-20

#main,"spritexy sprite1 ";px;" ";py
ar=ar-1

end if
end if


if key$="3" then 'down,right
if pxy$(ar+1,ac+1)<>"t" then 'if next space is not a tree

px=px+20
py=py+20

#main,"spritexy sprite1 ";px;" ";py
ac=ac+1
ar=ar+1
end if
end if

if key$="1" then 'down,left
if pxy$(ar+1,ac-1)<>"t" then 'if next space is not a tree

px=px-20
py=py+20

#main,"spritexy sprite1 ";px;" ";py
ac=ac-1
ar=ar+1
end if
end if

if key$="9" then 'up,right
if pxy$(ar-1,ac+1)<>"t" then 'if next space is not a tree

px=px+20
py=py-20

#main,"spritexy sprite1 ";px;" ";py
ac=ac+1
ar=ar-1
end if
end if

if key$="7" then 'up,left
if pxy$(ar-1,ac-1)<>"t" then 'if next space is not a tree

px=px-20
py=py-20

#main,"spritexy sprite1 ";px;" ";py
ac=ac-1
ar=ar-1
end if
end if



end if

if pxy$(ar,ac)="f" then
#main,"spritecollides sprite1";
input #main,list$
#main,"spritevisible ";word$(list$,1);" off";
pxy$(ar,ac)="x"
food=food-1
end if




goto [main.inputLoop]




[endOfProgram]
unloadbmp "sprite1"
unloadbmp "tree"
unloadbmp "food"
close #main












'map data
data t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t
data t,x,x,x,x,x,x,x,t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