' Scrolling background demo ' Allan Crossman 2001 leftkey$ = "4" rightkey$ = "6" upkey$ = "8" downkey$ = "5" fullwidth = 640 fullheight = 320 sw = fullwidth / 2 sh = fullheight / 2 cls fullbackground = init screen (0, 0, fullwidth, fullheight) set screen to fullbackground cls for n = 1 to 1000 ' Make stars on background. x = rnd * fullwidth y = rnd * fullheight brightness = rnd * 65535 forecolor brightness, brightness, brightness plot x, y next n virtue = init screen (0, 0, sw, sh) set screen to virtue cls set sprite render port to virtue no sprite background set sprite mask color to 0, 0, 0 forecolor 65535, 65535, 0 fcircle 10, 10, 9 ship = grab sprite (0, 0, 20, 20) cls shipx = fullwidth / 2 shipy = fullheight / 2 speedx = 0 speedy = 0 cleft = (screen width / 2) - (sw / 2) ctop = (screen height / 2) - (sh / 2) cright = (screen width / 2) + (sw / 2) cbottom = (screen height / 2) + (sh / 2) resize console cleft, ctop, cright, cbottom controls$ = leftkey$ + ", " + rightkey$ + ", " + upkey$ + ", " + downkey$ set console title to "Move with " + controls$ MainLoop: starttime = timer keymap scan if keymap key (leftkey$) then speedx = speedx - 0.5 if keymap key (rightkey$) then speedx = speedx + 0.5 if keymap key (upkey$) then speedy = speedy - 0.5 if keymap key (downkey$) then speedy = speedy + 0.5 ' Speed limiter... if abs(speedx) > 5 then speedx = sgn(speedx) * 5 if abs(speedy) > 5 then speedy = sgn(speedy) * 5 ' Move the ship... shipx = shipx + speedx shipy = shipy + speedy ' Walls stop motion... if shipx < 10 then shipx = 10 speedx = 0 end if if shipy < 10 then shipy = 10 speedy = 0 end if if shipx > (fullwidth - 10) then shipx = (fullwidth - 10) speedx = 0 end if if shipy > (fullheight - 10) then shipy = (fullheight - 10) speedy = 0 end if ' Set what part of the full arena will actually be drawn... cameraleft = shipx - (sw / 2) cameratop = shipy - (sh / 2) if cameraleft < 0 then cameraleft = 0 if cameratop < 0 then cameratop = 0 if cameraleft + sw > fullwidth then cameraleft = fullwidth - sw if cameratop + sh > fullheight then cameratop = fullheight - sh ' Copy that part of the background to the render screen... x1 = cameraleft y1 = cameratop x2 = cameraleft + sw y2 = cameratop + sh copyrect x1, y1, x2, y2, 0, 0, sw, sh, 0, fullbackground, virtue ' Render the ship... set sprite ship, shipx - 10 - cameraleft, shipy - 10 - cameratop render sprite ship ' Copy the render screen to the console... copyrect 0, 0, sw, sh, 0, 0, sw, sh, 0, virtue, 0 if keymap key (chr$(27)) then ' Press escape to end disable done end end if WaitLoop: if abs(timer - starttime) < 0.02 then goto WaitLoop goto MainLoop