Nike622000

Snake - main program

May 24th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.67 KB | None | 0 0
  1. mon = peripheral.wrap("back")
  2. mon.clear()
  3. rs.setOutput("bottom", true)
  4. local xMax,yMax = mon.getSize()
  5.  
  6. function hintergrund()
  7.  mon.setBackgroundColor(colors.cyan)
  8.   for b = 0,xMax,1 do
  9.    for i = 0,yMax,1 do
  10.    mon.setCursorPos(b,i)
  11.    mon.write(" ")
  12.    end
  13.   end
  14. end
  15.  
  16. momPosx = 10
  17. momPosy = 10
  18. xMitte = 10
  19. yMitte = 10
  20.  
  21. positionenX = {xMitte-10,xMitte-9,xMitte-8,xMitte-7,xMitte-6,xMitte-5,xMitte-4,xMitte-3,xMitte-2,xMitte-1,xMitte}
  22. positionenY = {yMitte-10,yMitte-9,yMitte-8,yMitte-7,yMitte-6,yMitte-5,yMitte-4,yMitte-3,yMitte-2,yMitte-1,yMitte}
  23.  
  24. function drawSnake(newPosX, newPosY, length)
  25.     mon.setBackgroundColor(colors.cyan)
  26.     for i=1,#positionenX do
  27.         mon.setCursorPos(positionenX[i],positionenY[i])
  28.         mon.write(" ")
  29.     end
  30.    
  31.     for i=2,11 do
  32.         positionenX[i] = positionenX[i-1]
  33.         positionenY[i] = positionenY[i-1]
  34.     end
  35.     positionenX[1] = newPosX
  36.     positionenY[1] = newPosY
  37.  
  38.     mon.setBackgroundColor(colors.white)
  39.     for i=1,#positionenX do
  40.         mon.setCursorPos(positionenX[i],positionenY[i])
  41.         mon.write(" ")
  42.     end
  43. end
  44.  
  45.  
  46. function steuerung()
  47. mon.setBackgroundColor(colors.cyan)
  48. mon.setTextColor(colors.white)
  49. mon.setCursorPos(60,15)
  50. mon.write("W")
  51. mon.setCursorPos(57,17)
  52. mon.write("A")
  53. mon.setCursorPos(60,17)
  54. mon.write("+")
  55. mon.setCursorPos(63,17)
  56. mon.write("S")
  57. mon.setCursorPos(60,19)
  58. mon.write("D")
  59. end
  60.  
  61. steuerung()
  62. sleep(0.1)
  63. os.loadAPI("ocs/apis/sensor")
  64. proximity = sensor.wrap("top")
  65. while true do
  66.  
  67. player = "warte auf Spieler..."
  68.  
  69. sleep(0.1)
  70. targets = proximity.getTargets()
  71. for k,v in pairs(targets) do
  72.   if v.Name == "Player"
  73.   and v.Position.X<=3 and v.Position.X>=-3
  74.   and v.Position.Z<=9 and v.Position.Z>=3
  75.   and v.Position.Y>=-3 and v.Position.Y<=4  
  76.   then
  77.   player = k
  78.  
  79. H = " "
  80.  
  81. --Springen
  82.   if v.Name == "Player" and
  83.      v.Position.X>=-0.5 and v.Position.X <=0.5 and
  84.      v.Position.Z>=5.5 and v.Position.Z<=6.5 and
  85.      v.Position.Y>=-0.5 and v.Position.Y<=2 then
  86.  
  87.   mon.setBackgroundColor(colors.cyan)
  88.   mon.setTextColor(colors.black)
  89.   mon.setCursorPos(60,17)
  90.   mon.write("+")
  91.  
  92.   H = "+"
  93.   print("+")
  94.   else
  95.  
  96.   mon.setBackgroundColor(colors.cyan)
  97.   mon.setTextColor(colors.white)
  98.   mon.setCursorPos(60,17)
  99.   mon.write("+")
  100.   end
  101. --W
  102.   if v.Name == "Player" and
  103.      v.Position.X>=-0.5 and v.Position.X <=0.5 and
  104.      v.Position.Z>=4.5 and v.Position.Z<=5.5 and
  105.      v.Position.Y>=-3 and v.Position.Y<=4 then
  106.  
  107.   mon.setBackgroundColor(colors.cyan)
  108.   mon.setTextColor(colors.blue)
  109.   mon.setCursorPos(60,15)
  110.   mon.write("W")
  111.   hoch()
  112.   H = "W"
  113.   print("W")
  114.   else
  115.  
  116.   mon.setBackgroundColor(colors.cyan)
  117.   mon.setTextColor(colors.white)
  118.   mon.setCursorPos(60,15)
  119.   mon.write("W")
  120.   end
  121. --A
  122.   if v.Name == "Player" and
  123.      v.Position.X>=-1.5 and v.Position.X <=-0.5 and
  124.      v.Position.Z>=5.5 and v.Position.Z<=6.5 and
  125.      v.Position.Y>=-3 and v.Position.Y<=4 then
  126.  
  127.   mon.setBackgroundColor(colors.cyan)
  128.   mon.setTextColor(colors.red)
  129.   mon.setCursorPos(57,17)
  130.   mon.write("A")
  131.   links()
  132.   H = "A"
  133.   print("A")
  134.   else
  135.  
  136.   mon.setBackgroundColor(colors.cyan)
  137.   mon.setTextColor(colors.white)
  138.   mon.setCursorPos(57,17)
  139.   mon.write("A")
  140.   end
  141. --S
  142.   if v.Name == "Player" and
  143.      v.Position.X>=0.5 and v.Position.X <=1.5 and
  144.      v.Position.Z>=5.5 and v.Position.Z<=6.5 and
  145.      v.Position.Y>=-3 and v.Position.Y<=4 then
  146.  
  147.   mon.setBackgroundColor(colors.cyan)
  148.   mon.setTextColor(colors.lime)
  149.   mon.setCursorPos(63,17)
  150.   mon.write("S")
  151.   rechts()
  152.   H = "S"
  153.   print("S")
  154.  
  155.   else
  156.  
  157.   mon.setBackgroundColor(colors.cyan)
  158.   mon.setTextColor(colors.white)
  159.   mon.setCursorPos(63,17)
  160.   mon.write("S")
  161.   end
  162. --D
  163.   if v.Name == "Player" and
  164.      v.Position.X>=-0.5 and v.Position.X <=0.5 and
  165.      v.Position.Z>=6.5 and v.Position.Z<=7.5 and
  166.      v.Position.Y>=-3 and v.Position.Y<=4 then
  167.  
  168.   mon.setBackgroundColor(colors.cyan)
  169.   mon.setTextColor(colors.yellow)
  170.   mon.setCursorPos(60,19)
  171.   mon.write("D")
  172.   H = "D"
  173.   print("D")
  174.   unten()
  175.   else
  176.  
  177.   mon.setBackgroundColor(colors.cyan)
  178.   mon.setTextColor(colors.white)
  179.   mon.setCursorPos(60,19)
  180.   mon.write("D")
  181.   end
  182. end
  183. end
  184.  
  185. function hoch()
  186.  f=1
  187. end
  188. function links()
  189.  f=2
  190. end
  191. function rechts()
  192.  f=3
  193. end
  194. function unten()
  195.  f=4
  196. end
  197.  
  198. if f==1 then
  199.  momPosy = momPosy-1
  200. end
  201.  
  202. if f==2 then
  203.  momPosx = momPosx-1
  204. end
  205.  
  206. if f==3 then
  207.  momPosx = momPosx+1
  208. end
  209.  
  210. if f==4 then
  211.  momPosy = momPosy+1
  212. end
  213.  
  214. xMaxn=xMax+1
  215. yMaxn=yMax+1
  216.  
  217. if momPosx == xMaxn then
  218. momPosx = 1
  219. end
  220. if momPosx == 0 then
  221. momPosx = xMax
  222. end
  223. if momPosy == yMaxn then
  224. momPosy = 1
  225. end
  226. if momPosy == 0 then
  227. momPosy = yMax
  228. end
  229.  
  230. drawSnake(momPosx, momPosy)
  231. sleep(0.2)
  232.  
  233. end
Add Comment
Please, Sign In to add comment