rem by TheComet
 
rem setup screen
set camera view 0,0,screen width(),screen height()
sync on
sync rate 0
backdrop on
color backdrop 0
show mouse
 
rem dimensions
dim dotx(10000)
dim doty(10000)
dim dont_draw(10000)
dim cx(1000)
dim cy(1000)
dim cs(1000)
dim pixel(screen width(),screen height())
dim pushed(3)
 
rem create user bar
create bitmap 1,screen width(),26
ink rgb(128,128,128),0
box 0,0,screen width()-1,25
ink rgb(200,200,200),0
line 0,0,screen width()-1,0
line screen width(),0,screen width()-1,26
ink rgb(90,90,90),0
line 0,0,0,26
line 0,25,screen width(),25
get image 1,0,0,screen width(),26
delete bitmap 1
 
rem create play button
create bitmap 1,80,22
ink rgb(128,128,128),0
box 0,0,79,21
ink rgb(200,200,200),0
line 0,0,79,0
line 79,0,79,22
ink rgb(90,90,90),0
line 0,0,0,22
line 0,21,79,21
ink rgb(10,10,10),0
set text size 10
center text 40,1,"Play"
get image 2,0,0,80,22
delete bitmap 1
 
rem create stop button
create bitmap 1,80,22
ink rgb(128,128,128),0
box 0,0,79,21
ink rgb(200,200,200),0
line 0,0,79,0
line 79,0,79,22
ink rgb(90,90,90),0
line 0,0,0,22
line 0,21,79,21
ink rgb(10,10,10),0
set text size 10
center text 40,1,"Stop"
get image 3,0,0,80,22
delete bitmap 1
 
rem create reset button
create bitmap 1,80,22
ink rgb(128,128,128),0
box 0,0,79,21
ink rgb(200,200,200),0
line 0,0,79,0
line 79,0,79,22
ink rgb(90,90,90),0
line 0,0,0,22
line 0,21,79,21
ink rgb(10,10,10),0
set text size 10
center text 40,1,"Reset"
get image 4,0,0,80,22
delete bitmap 1
 
rem create exit button
create bitmap 1,80,22
ink rgb(128,128,128),0
box 0,0,79,21
ink rgb(200,200,200),0
line 0,0,79,0
line 79,0,79,22
ink rgb(90,90,90),0
line 0,0,0,22
line 0,21,79,21
ink rgb(10,10,10),0
set text size 10
center text 40,1,"Exit"
get image 5,0,0,80,22
delete bitmap 1
 
rem create play button pushed
create bitmap 1,80,22
ink rgb(128,128,128),0
box 0,0,79,21
ink rgb(90,90,90),0
line 0,0,79,0
line 79,0,79,22
ink rgb(200,200,200),0
line 0,0,0,22
line 0,21,79,21
ink rgb(10,10,10),0
set text size 10
center text 41,0,"Play"
get image 6,0,0,80,22
delete bitmap 1
 
rem create stop button pushed
create bitmap 1,80,22
ink rgb(128,128,128),0
box 0,0,79,21
ink rgb(90,90,90),0
line 0,0,79,0
line 79,0,79,22
ink rgb(200,200,200),0
line 0,0,0,22
line 0,21,79,21
ink rgb(10,10,10),0
set text size 10
center text 41,0,"Stop"
get image 7,0,0,80,22
delete bitmap 1
 
rem create reset button pushed
create bitmap 1,80,22
ink rgb(128,128,128),0
box 0,0,79,21
ink rgb(90,90,90),0
line 0,0,79,0
line 79,0,79,22
ink rgb(200,200,200),0
line 0,0,0,22
line 0,21,79,21
ink rgb(10,10,10),0
set text size 10
center text 41,0,"Reset"
get image 8,0,0,80,22
delete bitmap 1
 
rem create exit button pushed
create bitmap 1,80,22
ink rgb(128,128,128),0
box 0,0,79,21
ink rgb(90,90,90),0
line 0,0,79,0
line 79,0,79,22
ink rgb(200,200,200),0
line 0,0,0,22
line 0,21,79,21
ink rgb(10,10,10),0
set text size 10
center text 41,0,"Exit"
get image 9,0,0,80,22
delete bitmap 1
 
rem player sprite
create bitmap 1,10,20
ink rgb(255,0,0),0
circle 5,5,4
line 5,10,5,15
line 0,11,10,11
line 5,15,10,20
line 5,15,0,20
get image 11,0,0,10,20
delete bitmap 1
 
rem goal
create bitmap 1,10,10
ink rgb(0,255,0),0
circle 5,5,4
dot 5,5
get image 12,0,0,10,10
delete bitmap 1
 
rem main loop
pushed=0
waypoint=0
px=20
py=60
gx=20
gy=100
circles=0
do
 
rem what mode?
ink rgb(255,255,0),0
center text screen width()/2,25,"Edit Mode"
 
rem print menu
paste image 1,0,0
sprite 2,50,2,2
sprite 3,200,2,3
sprite 4,350,2,4
sprite 5,500,2,5
 
rem control buttons pushed
for t=0 to 3
   if mousex()>sprite x(t+2) and mousex()<sprite x(t+2)+sprite width(t+2) and mousey()>sprite y(t+2) and mousey()<sprite y(t+2)+sprite height(t+2) and mouseclick()=1 then pushed(t)=1 else pushed(t)=0
   if pushed(t)=1 then sprite t+2,sprite x(t+2),sprite y(t+2),t+6
next t
 
rem play
if pushed(0)=1 then gosub play_game
 
rem reset
if pushed(2)=1
   for t=0 to 10000
      dotx(t)=0
      doty(t)=0
      dont_draw(t)=0
   next t
   waypoint=0
   circles=0
endif
 
rem exit
if pushed(3)=1 then end
 
rem position player
ink rgb(255,0,0),0
center text px,py-20,"Player"
sprite 11,px,py,11
if mousex()>sprite x(11) and mousex()<sprite x(11)+sprite width(11) and mousey()>sprite y(11) and mousey()<sprite y(11)+sprite height(11)
   if mouseclick()=1
      if player_select=0
         offx=mousex()-sprite x(11)
         offy=mousey()-sprite y(11)
         player_select=1
      endif
      repeat
         paste image 1,0,0
         sprite 11,mousex()-offx,mousey()-offy,11
         px=sprite x(11)
         py=sprite y(11)
         if py<22 then sprite 11,px,22,11
         ink rgb(255,0,0),0
         center text px,py-20,"Player"
         ink rgb(255,255,255),0
         for t=2 to waypoint
            if dont_draw(t)=0 then line dotx(t),doty(t),dotx(t-1),doty(t-1)
         next t
         for t=1 to circles
            circle cx(t),cy(t),cs(t)
         next t
         sync
      until mouseclick()=0
   endif
endif
if mouseclick()=0 then player_select=0
 
rem position goal
sprite 12,gx,gy,12
ink rgb(0,255,0),0
center text gx,gy-20,"Goal"
if mousex()>sprite x(12) and mousex()<sprite x(12)+sprite width(12) and mousey()>sprite y(12) and mousey()<sprite y(12)+sprite height(12)
   if mouseclick()=1
      if goal_select=0
         offx=mousex()-sprite x(12)
         offy=mousey()-sprite y(12)
         goal_select=1
      endif
      repeat
         paste image 1,0,0
         sprite 12,mousex()-offx,mousey()-offy,12
         gx=sprite x(12)
         gy=sprite y(12)
         if gy<22 then sprite 12,gx,22,12
         ink rgb(0,255,0),0
         center text gx,gy-20,"Goal"
         ink rgb(255,255,255),0
         for t=2 to waypoint
            if dont_draw(t)=0 then line dotx(t),doty(t),dotx(t-1),doty(t-1)
         next t
         for t=1 to circles
            circle cx(t),cy(t),cs(t)
         next t
         sync
      until mouseclick()=0
   endif
endif
if mouseclick()=0 then goal_select=0
 
rem set waypoints for lines
if player_select=0
   if mouseclick()=1 and mousey()>22
      if mousemovex()<>0 or mousemovey()<>0
         if pushed=0
            inc waypoint
            if waypoint>10000 then waypoint=10000
            dotx(waypoint)=mousex():doty(waypoint)=mousey()
            dont_draw(waypoint)=1
            pushed=1
         endif
         inc waypoint
         if waypoint>10000 then waypoint=10000
         dotx(waypoint)=mousex():doty(waypoint)=mousey()
      endif
 
      rem how many waypoints are there currently?
      ink rgb(255,255,255),0
      center text mousex(),mousey()-12,"Waypoints : "+str$(waypoint)
 
   else
      if pushed=1
         inc waypoint
         if waypoint>10000 then waypoint=10000
         dont_draw(waypoint)=1
         pushed=0
      endif
   endif
endif
 
rem draw circles
if mouseclick()=2 and mousey()>22
   if draw_circle=0
      inc circles
      cx(circles)=mousex()
      cy(circles)=mousey()
      draw_circle=1
   endif
   cs(circles)=(abs(cx(circles)-mousex()))+(abs(cy(circles)-mousey()))
endif
if mouseclick()=0 then draw_circle=0
 
rem draw lines
ink rgb(255,255,255),0
for t=2 to waypoint
   if dont_draw(t)=0 then line dotx(t),doty(t),dotx(t-1),doty(t-1)
next t
 
rem draw circles
for t=1 to circles
   circle cx(t),cy(t),cs(t)
next t
 
rem refresh screen
sync
 
rem end of main loop
loop
 
rem Subroutines --------------------------------------------------------------------------------------------------------------------------------
 
play_game:
 
rem setup game
 
rem get level image and save it
if file exist("level.bmp")=1 then delete file "level.bmp"
create bitmap 1,screen width(),screen height()
ink rgb(255,255,255),0
for t=2 to waypoint
   if dont_draw(t)=0 then line dotx(t),doty(t),dotx(t-1),doty(t-1)
next t
for t=1 to circles
   circle cx(t),cy(t),cs(t)
next t
save bitmap "level.bmp",1
get image 10,0,0,screen width(),screen height()
delete bitmap 1
 
rem import bitmap and see which pixels are white(Thankyou TDK! :-)
Open to read 1,"level.bmp":   Rem Colour Image
   Read word 1,Discard:       Rem Identifier
   Read long 1,Discard:       Rem File Size
   Read long 1,Discard:       Rem Reserved
   Read long 1,Discard:       Rem Bitmap Data Offset
   Read long 1,Discard:       Rem Bitmap Header Size
   Read long 1,ImageWidth:    Rem Width
   Read long 1,ImageHeight:   Rem Height
   Read word 1,Discard:       Rem Planes
   Read word 1,bitsperpixel:  Rem Bits Per Pixel
   Read long 1,Discard:       Rem Compression
   Read long 1,bmpdatasize:   Rem Bitmap Data Size
   Read long 1,Discard:       Rem HResolution
   Read long 1,Discard:       Rem VResolution
   Read long 1,Discard:       Rem Colors
   Read long 1,Discard:       Rem Important Colors
 
   Rem Read in the pixel data into the array
   For By = ImageHeight-1 to 0 step-1
      For Bx=0 to ImageWidth-1
         read byte 1,Blue
         read byte 1,Green
         read byte 1,Red
         if blue>0 and green>0 and red>0 and by-20>22 then pixel(bx,by-20)=1
      Next Bx
   Next By
Close File 1
 
rem main loop
sx#=sprite x(11)
sy#=sprite y(11)
win_time=0
do
 
rem paste level
paste image 10,0,0
 
rem print menu
paste image 1,0,0
sprite 2,50,2,2
sprite 3,200,2,3
sprite 4,350,2,4
sprite 5,500,2,5
 
rem what mode?
ink rgb(255,255,0),0
center text screen width()/2,25,"Play Mode"
 
rem control buttons pushed
for t=0 to 3
   if mousex()>sprite x(t+2) and mousex()<sprite x(t+2)+sprite width(t+2) and mousey()>sprite y(t+2) and mousey()<sprite y(t+2)+sprite height(t+2) and mouseclick()=1 then pushed(t)=1 else pushed(t)=0
   if pushed(t)=1 then sprite t+2,sprite x(t+2),sprite y(t+2),t+6
next t
 
rem stop game
if pushed(1)=1 then exit
 
rem get player positions
oldsy#=sy#
 
rem player
if upkey()=1 and grav#=0.0 then grav#=-1
if leftkey()=1 then dec sx#,0.4
if rightkey()=1 then inc sx#,0.4
 
rem gravity
inc grav#,0.005:if grav#>10 then grav#=10
inc sy#,grav#
 
rem screen boundaries
if sy#>screen height()-21 then sy#=screen height()-21:grav#=0.0
if sy#<22 then sy#=22
if sx#<0 then sx#=0
if sx#>screen width()-10 then sx#=screen width()-10
 
rem collision
for x=sprite x(11) to sprite x(11)+10
   for y=sprite y(11)-10 to sprite y(11)
      if grav#>0 and pixel(x,y)=1 then sy#=y:grav#=0.0
   next y
next x
 
rem update player positions
sx=sx#
sy=sy#
sprite 11,sx,sy,11
 
rem win
if sprite x(11)+10>sprite x(12) and sprite x(11)<sprite x(12)+sprite width(12)
   if sprite y(11)+20>sprite y(12) and sprite y(11)<sprite y(12)+sprite height(12)
      win_time=screen fps()*3
   endif
endif
dec win_time
ink rgb(255,255,0),0
if win_time>0 then center text screen width()/2,screen height()/2,"WINNER!!!"
 
rem refresh screen
sync
 
rem end of main loop
loop
 
for x=0 to screen width()
   for y=0 to screen height()
      pixel(x,y)=0
   next y
next x
 
return