home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / data1.cab / Lang_Files_(English) / Help / examples / file / file1-example.dba < prev    next >
Encoding:
Text File  |  2004-09-22  |  1.6 KB  |  93 lines

  1. rem File Showcase
  2.  
  3. rem Standard Setup Code for all examples
  4. set text font "arial" : set text size 20
  5. set text to bold : set text transparent
  6.  
  7. rem Arra to hold data
  8. type pos x y endtype
  9. dim coord(100) as pos
  10.  
  11. rem Mainloop
  12. coordmax=0
  13. do
  14.  
  15. rem a pretty backdrop
  16. prettybackdrop()
  17.  
  18. rem Title
  19. center text screen width()/2,20,"SIMPLE DATABASE OF CO-ORDINATES"
  20. center text screen width()/2,screen height()-30,"Click To Draw Lines then Press [R] to Replay"
  21.  
  22. rem Show coords so far
  23. for n=0 to coordmax-1
  24.  dot coord(n).x,coord(n).y
  25. next n
  26.  
  27. rem Record or Playback
  28. if mouseclick()=1
  29.  if cl=0
  30.   coord(coordmax).x=mousex()
  31.   coord(coordmax).y=mousey()
  32.   inc coordmax : if coordmax>99 then coordmax=99
  33.   cl=1
  34.  endif
  35. else
  36.  cl=0
  37. endif
  38.  
  39. rem Playback
  40. if inkey$()="r"
  41.  
  42.  rem Save data
  43.  if coordmax>0
  44.   delete file "coordata.dat"
  45.   open to write 1,"coordata.dat"
  46.   write file 1,coordmax
  47.   for n=0 to coordmax
  48.    write file 1,coord(n).x
  49.    write file 1,coord(n).y
  50.   next n
  51.   close file 1
  52.  endif
  53.  
  54.  rem Clear data
  55.  for n=0 to 100
  56.   coord(n).x=0
  57.   coord(n).y=0
  58.  next n
  59.  
  60.  rem Load data
  61.  open to read 1,"coordata.dat"
  62.  read file 1,coordmax
  63.  for n=0 to coordmax
  64.   read file 1,coord(n).x
  65.   read file 1,coord(n).y
  66.  next n
  67.  close file 1
  68.  
  69.  rem Draw data
  70.  for n=0 to coordmax-1
  71.   if n>0 then line nx,ny,coord(n).x,coord(n).y
  72.   nx=coord(n).x
  73.   ny=coord(n).y
  74.   sleep 100
  75.  next n
  76.  sleep 2000
  77.  
  78.  rem Reset write ptr
  79.  coordmax=0
  80.  
  81.  endif
  82.  
  83. rem Update screen
  84. sync
  85.  
  86. rem Endloop
  87. loop
  88.  
  89. rem Pretty Backdrop Function
  90. function prettybackdrop()
  91.  box 0,0,640,480,rgb(0,128,128),rgb(128,0,0),rgb(128,0,128),rgb(128,128,0)
  92. endfunction
  93.