you will have to prevent his x and y cordinates going past a certian point.
The easiest method of doing this would be to limit the x and y position for your player. insert this code somewhere.
if playerx>screen width() then playerx=screen width()
if playerx<0 then playerx=0
if playery>screen height() then playery=screen height()
if playery<0 then playery=0
For a larger level bigger than the screen you scroll the background instead of moving your player. This code will be useless for a game but hopefully demonstrates my point.
You will need a map/tile system to get any form of game working. It will handle collisions and scroll the tiles and colission objects as the player moves. Remember the map scrolls past the player not the other way round.
do
if leftkey()=1 then inc playerx
if rightkey()=1 then dec playerx
if upkey()=1 then inc playery
if downkey()=1 then inc playery
draw_map(playerx,playery)
draw_player()
loop
function draw_map(x,y)
` set the bitmap to one containing the full level
set current bitmap levelgraphics
` get the portion of the map sorrounding the player position
get image backimage,x-(screenwidth()/2),y-(screenheight()/2),x+(screenwidth()/2),y+(screenheight()/2),1
`set the bitmap back to 0 so drawing operations are done on the screen again
set current bitmap 0
`paste the image you just captured onto the screen
paste backimage,0,0
endfunction
function draw_player()
sprite player,(screenwidth()/2),(screenheight()/2),playerimage
endfunction