Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 4.30 KB | None | 0 0
  1. ` darkbasic pathfinder
  2.  
  3.  
  4. `make a few arrays
  5. DIM grid (100,100)
  6. DIM scanner (100,100)
  7. DIM solution (100,100)
  8.  
  9. `create a nice viewport
  10. make camera 1
  11. position camera 1,0,0,180
  12. POINT camera 1,0,0,100
  13. color backdrop 1,rgb (0,0,0)
  14.  
  15. make light 1
  16. color light 1, rgb(255,50,0)
  17. position light 1,50,0,200
  18.  
  19. make light 2
  20. color light 2, rgb(0,50,255)
  21. position light 2,-50,0,200
  22.  
  23. `set the size of the maze
  24. DATA 13,10
  25. ` set the maze
  26. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  27. DATA 1,3,0,0,0,0,0,0,0,1,2,0,1
  28. DATA 1,1,1,1,1,1,1,1,0,1,1,0,1
  29. DATA 1,0,0,0,0,0,0,0,0,1,1,0,1
  30. DATA 1,0,1,1,1,1,1,1,1,0,1,0,1
  31. DATA 1,0,0,0,0,0,0,0,0,0,1,0,1
  32. DATA 1,0,1,1,1,1,0,1,1,1,1,0,1
  33. DATA 1,1,0,0,0,1,0,1,0,1,0,0,1
  34. DATA 1,0,0,1,0,0,0,0,0,0,0,0,1
  35. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  36.  
  37.  
  38. `READ the maze AND make some objects TO show it
  39. READ maxx
  40. READ maxy
  41. FOR yt = 1 TO maxy
  42.    FOR xt = 1 TO maxx
  43.       an=an+1
  44.       READ griddata
  45.       grid(xt,yt) = griddata
  46.       ypos = 45+(maxy)-(yt*10)
  47.       xpos = 57+(maxx)-(xt*10)
  48.  
  49.       `whole lotta IF
  50.       IF griddata = 1 THEN make object cube an,10 : position object an, xpos,ypos,90:color object an, rgb(145,57,144)
  51.       IF griddata = 2 THEN make object sphere 400,9: position object 400,xpos,ypos,90: color object 400, rgb(0,0,255)
  52.       IF griddata = 3 THEN make object sphere 401,9: position object 401,xpos,ypos,90: color object 401, rgb(255,0,0)
  53.       IF griddata=2 THEN startcoordx=xt
  54.       IF griddata=2 THEN startcoordy=yt
  55.       IF griddata=3 THEN stopcoordx=xt
  56.       IF griddata=3 THEN stopcoordy=yt
  57.  
  58.    NEXT xt
  59. NEXT yt
  60. sync
  61.  
  62. `DEBUGGING CRAP
  63.  
  64. `FOR yf = 1 TO maxy
  65. `   FOR xf = 1 TO maxx
  66. `      scanput = grid(xf,yf)
  67. `      set cursor xf*16,yf*16
  68. `      IF scanput=1 THEN PRINT "#"
  69. `      IF scanput=2 THEN PRINT "F"
  70. `      IF scanput=3 THEN PRINT "S"
  71. `      NEXT
  72. `      NEXT
  73.  
  74.  
  75. `this does stuff
  76. searchx=startcoordx
  77. searchy=startcoordy
  78.  
  79. `CALLS the pathfinding FUNCTION (it's recursive)
  80. scannert(searchx,searchy,99)
  81.  
  82. `some more stuff
  83. upcount=scanner(stopcoordx,stopcoordy)
  84. coordx=stopcoordx
  85. coordy=stopcoordy
  86.  
  87. DO
  88. sync
  89.    `make a 150 ms pause between each LOOP TO keep stuff visible
  90.    SLEEP 150
  91.  
  92.    value=scanner(coordx,coordy)
  93.    newvalue=scanner(coordx+1,coordy)
  94.    gridvar=grid(coordx+1,coordy)
  95.  
  96.    IF value < newvalue  AND gridvar =0 THEN t=t+1:coordx=coordx+1:makeamark(coordx,coordy,maxx,maxy,t)
  97.  
  98.    value=scanner(coordx,coordy)
  99.    newvalue=scanner(coordx-1,coordy)
  100.    gridvar=grid(coordx-1,coordy)
  101.    IF value < newvalue AND gridvar =0  THEN t=t+1:coordx=coordx-1:makeamark(coordx,coordy,maxx,maxy,t)
  102.  
  103.    value=scanner(coordx,coordy)
  104.    newvalue=scanner(coordx,coordy+1)
  105.    gridvar=grid(coordx,coordy+1)
  106.    IF value < newvalue  AND gridvar =0 THEN t=t+1:coordy=coordy+1:makeamark(coordx,coordy,maxx,maxy,t)
  107.  
  108.    value=scanner(coordx,coordy)
  109.    newvalue=scanner(coordx,coordy-1)
  110.    gridvar=grid(coordx,coordy-1)
  111.    IF value < newvalue  AND gridvar =0 THEN t=t+1:coordy=coordy-1:makeamark(coordx,coordy,maxx,maxy,t)
  112.  
  113.    value=scanner(coordx,coordy)
  114.    IF value > 99 THEN GOTO theend
  115.  
  116.  
  117. LOOP
  118.  
  119. theend:
  120. DO:LOOP
  121.  
  122.  
  123. FUNCTION makeamark(x,y,maxx,maxy,t)
  124. `makes a square whwn it finds the right path
  125.  
  126. ` MORE DEBUG CRAP
  127. `set cursor x*16,y*16
  128. `PRINT "X"
  129.  
  130. ypos = 45+(maxy)-(y*10)
  131. xpos = 57+(maxx)-(x*10)
  132.  
  133. make object cube t+500,10: color object t+500,rgb(0,255,0)
  134. position object t+500, xpos,ypos,90
  135.  
  136. endfunction
  137.  
  138.  
  139.  
  140. FUNCTION scannert(x,y,distance)
  141. `the pathfinder
  142.  
  143. scanner(x, y) = distance    ` set the distance TO current location
  144. sync
  145.  
  146.  
  147. ` YOU GUESSED IT, DEBUG
  148. `FOR yf = 1 TO maxy
  149. `   FOR xf = 1 TO maxx
  150. `      scanput = scanner(xf,yf)
  151. `      set cursor xf*16,140+yf*16
  152. `      PRINT scanput
  153. `   NEXT
  154. `NEXT
  155.  
  156. `set cursor 0,200
  157. `PRINT "x = ", x, "y = ", y, " distance = ", distance
  158.  
  159.  
  160.  
  161. ` scan left
  162. gridvar = grid(x-1, y)
  163. scanvar = scanner(x-1, y)
  164. IF scanvar < distance AND gridvar <> 1 THEN scannert(x-1, y, distance - 1)
  165.  
  166. ` scan right
  167. gridvar = grid(x+1, y)
  168. scanvar = scanner(x+1, y)
  169. IF scanvar < distance AND gridvar <> 1 THEN scannert(x+1, y, distance - 1)
  170.  
  171. ` scan up
  172. gridvar = grid(x, y-1)
  173. scanvar = scanner(x, y-1)
  174. IF scanvar < distance AND gridvar <> 1 THEN scannert(x, y-1, distance - 1)
  175.  
  176. ` scan down
  177. gridvar = grid(x, y+1)
  178. scanvar = scanner(x, y+1)
  179. IF scanvar < distance AND gridvar <> 1 THEN scannert(x, y+1, distance - 1)
  180.  
  181. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement