Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 3.78 KB | None | 0 0
  1. `make a few arrays
  2. DIM grid (100,100)
  3. DIM scanner (100,100)
  4.  
  5. `create a nice viewport AND set the romantic mood
  6. make camera 1
  7. position camera 1,0,0,180
  8. POINT camera 1,0,0,100
  9. color backdrop 1,rgb (0,0,0)
  10. make light 1
  11. color light 1, rgb(255,50,0)
  12. position light 1,50,0,200
  13. make light 2
  14. color light 2, rgb(0,50,255)
  15. position light 2,-50,0,200
  16.  
  17. `set the size of the maze
  18. DATA 13,10
  19. ` set the maze
  20. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  21. DATA 1,3,0,0,0,0,0,0,0,1,2,0,1
  22. DATA 1,1,1,1,1,1,1,1,0,1,1,0,1
  23. DATA 1,0,0,0,0,0,0,0,0,1,1,0,1
  24. DATA 1,0,1,1,1,1,1,1,1,0,1,0,1
  25. DATA 1,0,0,0,0,0,0,0,0,0,1,0,1
  26. DATA 1,0,1,1,1,1,0,1,1,1,1,0,1
  27. DATA 1,1,0,0,0,1,0,1,0,1,0,0,1
  28. DATA 1,0,0,1,0,0,0,0,0,0,0,0,1
  29. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  30.  
  31.  
  32. `READ the maze size
  33. READ maxx
  34. READ maxy
  35.  
  36. `READ the maze into an array
  37.  
  38. FOR yt = 1 TO maxy
  39.    FOR xt = 1 TO maxx
  40.       an=an+1
  41.  
  42.       READ griddata
  43.       grid(xt,yt) = griddata
  44.       ypos = 45+(maxy)-(yt*10)
  45.       xpos = 57+(maxx)-(xt*10)
  46.  
  47.       `make the objects AND position them
  48.       IF griddata = 1 THEN make object cube an,10 : position object an, xpos,ypos,90:color object an, rgb(145,57,144)
  49.       IF griddata = 2 THEN make object sphere 400,9: position object 400,xpos,ypos,90: color object 400, rgb(0,0,255)
  50.       IF griddata = 3 THEN make object sphere 401,9: position object 401,xpos,ypos,90: color object 401, rgb(255,0,0)
  51.  
  52.       `find start AND END of maze
  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. `this does stuff
  63. searchx=startcoordx
  64. searchy=startcoordy
  65.  
  66. `CALLS the pathfinding FUNCTION (it's recursive)
  67. scannert(searchx,searchy,99)
  68.  
  69. `some more stuff
  70. upcount=scanner(stopcoordx,stopcoordy)
  71. coordx=stopcoordx
  72. coordy=stopcoordy
  73.  
  74. `main LOOP
  75. DO
  76.    `make a 150 ms pause between each LOOP TO keep stuff visible
  77.    SLEEP 150
  78.  
  79.    value=scanner(coordx,coordy)
  80.    newvalue=scanner(coordx+1,coordy)
  81.    gridvar=grid(coordx+1,coordy)
  82.    IF value < newvalue  AND gridvar =0 THEN t=t+1:coordx=coordx+1:makeamark(coordx,coordy,maxx,maxy,t)
  83.  
  84.    value=scanner(coordx,coordy)
  85.    newvalue=scanner(coordx-1,coordy)
  86.    gridvar=grid(coordx-1,coordy)
  87.    IF value < newvalue AND gridvar =0  THEN t=t+1:coordx=coordx-1:makeamark(coordx,coordy,maxx,maxy,t)
  88.  
  89.    value=scanner(coordx,coordy)
  90.    newvalue=scanner(coordx,coordy+1)
  91.    gridvar=grid(coordx,coordy+1)
  92.    IF value < newvalue  AND gridvar =0 THEN t=t+1:coordy=coordy+1:makeamark(coordx,coordy,maxx,maxy,t)
  93.  
  94.    value=scanner(coordx,coordy)
  95.    newvalue=scanner(coordx,coordy-1)
  96.    gridvar=grid(coordx,coordy-1)
  97.    IF value < newvalue  AND gridvar =0 THEN t=t+1:coordy=coordy-1:makeamark(coordx,coordy,maxx,maxy,t)
  98.  
  99.    value=scanner(coordx,coordy)
  100.    IF value > 99 THEN GOTO theend
  101.  
  102.    sync
  103.  
  104. LOOP
  105.  
  106. theend:
  107. DO:LOOP
  108.  
  109.  
  110. FUNCTION makeamark(x,y,maxx,maxy,t)
  111. `makes a square when it finds the right path
  112.  
  113. ypos = 45+(maxy)-(y*10)
  114. xpos = 57+(maxx)-(x*10)
  115.  
  116. make object cube t+500,10: color object t+500,rgb(0,255,0)
  117. position object t+500, xpos,ypos,90
  118.  
  119. endfunction
  120.  
  121.  
  122.  
  123. FUNCTION scannert(x,y,distance)
  124. `the pathfinder
  125.  
  126. scanner(x, y) = distance    ` set the distance TO current location
  127.  
  128. ` scan left
  129. gridvar = grid(x-1, y)
  130. scanvar = scanner(x-1, y)
  131. IF scanvar < distance AND gridvar <> 1 THEN scannert(x-1, y, distance - 1)
  132.  
  133. ` scan right
  134. gridvar = grid(x+1, y)
  135. scanvar = scanner(x+1, y)
  136. IF scanvar < distance AND gridvar <> 1 THEN scannert(x+1, y, distance - 1)
  137.  
  138. ` scan up
  139. gridvar = grid(x, y-1)
  140. scanvar = scanner(x, y-1)
  141. IF scanvar < distance AND gridvar <> 1 THEN scannert(x, y-1, distance - 1)
  142.  
  143. ` scan down
  144. gridvar = grid(x, y+1)
  145. scanvar = scanner(x, y+1)
  146. IF scanvar < distance AND gridvar <> 1 THEN scannert(x, y+1, distance - 1)
  147.  
  148. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement