sync on
sync rate 60
rem First, define the size of the map in tiles
x_tiles = 100
y_tiles = 100
dim tiles(x_tiles,y_tiles)
rem Second, init the variables
screen_x = 0
screen_y = 0
player_x = 320
player_y = 240
rem Make the player image or load an existing one
sync : cls : sync
circle 5,5,4
get image 1,0,0,10,10,1
cls
rem Draw a tile or load an existing one
ink rgb(0,200,0),0
box 0,0,64,64
sync
get image 2,0,0,64,64,1
ink rgb(255,255,255),0
cls
rem Place some random "grass" tiles
for a=1 to 100
for b=1 to 100
if rnd(5)=1 then tiles(a,b)=2
next b
next a
do
rem Move the player
player_x = player_x - leftkey() + rightkey()
player_y = player_y - upkey() + downkey()
rem Lock the screen at the players position, but keep it inside the map
screen_x = player_x - 320
screen_y = player_y - 240
if screen_x < 0 then screen_x = 0
if screen_x > (x_tiles*64)-640 then screen_x = (x_tiles*64)-640
if screen_y < 0 then screen_y = 0
if screen_y > (y_tiles*64)-480 then screen_y = (y_tiles*64)-480
rem Draw the tiles
draw_tiles(screen_x,screen_y)
rem Draw the player
sprite 1,player_x-screen_x,player_y-screen_y,1
text 5,5,"FPS: "+str$(screen fps())
sync
loop
function draw_tiles(x,y)
rem I think I dont need to explain this, it basicly creates smooth scrolling
xr = x MOD 64
yr = y MOD 64
t = 30000
for a=1 to 11
for b=1 to 9
tile = tiles((a-1)+int(x/64),(b-1)+int(y/64))
if tile >0
sprite t, ((a-1)*64) - xr, ((b-1)*64) - yr, tile
t = t + 1
endif
next b
next a
for a=t to 30100 : if sprite exist(a)=1 : delete sprite a : endif : next a
endfunction
Still needs collision though