Nike622000

Snake

May 23rd, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.25 KB | None | 0 0
  1. monSide = "back"
  2. mon = peripheral.wrap(monSide)
  3.  
  4. local xMax,yMax = mon.getSize()
  5.  
  6.  
  7. rs.setOutput("bottom", false)
  8. i=1
  9.  
  10. function hintergrund()
  11.  mon.setBackgroundColor(colors.cyan)
  12.   for b = 0,xMax,1 do
  13.    for i = 0,yMax,1 do
  14.    mon.setCursorPos(b,i)
  15.    mon.write(" ")
  16.    end
  17.   end
  18. end
  19.  
  20. function animation()
  21.  mon.setBackgroundColor(colors.white)
  22.    g = -2
  23.    for l = 1,8,1 do
  24.      mon.setBackgroundColor(colors.white)
  25.      mon.setCursorPos(l,2)
  26.      mon.write(" ")
  27.      sleep(0.1)
  28.      mon.setBackgroundColor(coloranimation)
  29.      mon.setCursorPos(g,2)
  30.      mon.write(" ")
  31.      g = g+1
  32.      mon.setBackgroundColor(colors.white)
  33.    end
  34.      
  35. --S
  36.    for l = 8,6,-1 do
  37.      mon.setCursorPos(l,2)
  38.      mon.write(" ")
  39.      sleep(0.1)
  40.    end
  41.      mon.setCursorPos(6,3)
  42.      mon.write(" ")
  43.      sleep(0.1)
  44.    for l = 6,8,1 do
  45.      mon.setCursorPos(l,4)
  46.      mon.write(" ")
  47.      sleep(0.1)
  48.    end  
  49.      mon.setCursorPos(8,5)
  50.      mon.write(" ")
  51.      sleep(0.1)
  52.    for l = 8,6,-1 do
  53.      mon.setCursorPos(l,6)
  54.      mon.write(" ")
  55.      sleep(0.1)
  56.    end
  57. --N
  58.    for l = 6,2,-1 do
  59.      mon.setCursorPos(10,l)
  60.      mon.write(" ")
  61.      sleep(0.1)
  62.    end
  63.      mon.setCursorPos(11,2)
  64.    g = 11
  65.    for l = 3,5,1 do  
  66.      mon.setCursorPos(g,l)
  67.      mon.write(" ")
  68.      g=g+1
  69.      sleep(0.1)
  70.    end
  71.    for l = 6,2,-1 do
  72.      mon.setCursorPos(14,l)
  73.      mon.write(" ")
  74.      sleep(0.1)
  75.    end
  76. --A
  77.    for l = 6,3,-1 do
  78.      mon.setCursorPos(16,l)
  79.      mon.write(" ")
  80.      sleep(0.1)
  81.    end
  82.    for l = 17,18,1 do
  83.      mon.setCursorPos(l,2)
  84.      mon.write(" ")
  85.      sleep(0.1)
  86.    end
  87.    for l = 3,6,1 do
  88.      mon.setCursorPos(19,l)
  89.      mon.write(" ")
  90.      sleep(0.1)
  91.    end  
  92.    for l = 17,18,1 do
  93.      mon.setCursorPos(l,4)
  94.      mon.write(" ")
  95.      sleep(0.1)
  96.    end  
  97. --K
  98.    for l = 6,2,-1 do
  99.      mon.setCursorPos(21,l)
  100.      mon.write(" ")
  101.      sleep(0.1)
  102.    end
  103.    g = 4
  104.    for l = 22,24,1 do
  105.      mon.setCursorPos(l,g)
  106.      mon.write(" ")
  107.      g=g-1
  108.      sleep(0.1)
  109.    end
  110.    g = 5
  111.    for l = 23,24,1 do
  112.      mon.setCursorPos(l,g)
  113.      mon.write(" ")
  114.      g=g+1
  115.      sleep(0.1)
  116.    end
  117. --E
  118.    for l = 6,2,-1 do
  119.      mon.setCursorPos(26,l)
  120.      mon.write(" ")
  121.      sleep(0.1)
  122.    end
  123.    for g = 2,6,2 do
  124.      for l = 27,28,1 do
  125.        mon.setCursorPos(l,g)
  126.        mon.write(" ")
  127.        sleep(0.1)
  128.      end
  129.    end
  130.    g = 27
  131.    for l = 29,xMax,1 do
  132.      mon.setBackgroundColor(colors.white)
  133.      mon.setCursorPos(l,6)
  134.      mon.write(" ")
  135.      sleep(0.1)
  136.      if g >= 29 then
  137.      mon.setBackgroundColor(coloranimation)
  138.      mon.setCursorPos(g,6)
  139.      mon.write(" ")
  140.      end
  141.      g=g+1
  142.    end
  143.      snake=xMax-5
  144.      for l = xMax,snake,-1 do
  145.      mon.setBackgroundColor(coloranimation)
  146.      mon.setCursorPos(l,6)
  147.      mon.write(" ")
  148.      end
  149. end
  150.  
  151. function steuerung()
  152. mon.setBackgroundColor(colors.cyan)
  153. mon.setTextColor(colors.white)
  154. mon.setCursorPos(60,15)
  155. mon.write("W")
  156. mon.setCursorPos(57,17)
  157. mon.write("A")
  158. mon.setCursorPos(60,17)
  159. mon.write("+")
  160. mon.setCursorPos(63,17)
  161. mon.write("S")
  162. mon.setCursorPos(60,19)
  163. mon.write("D")
  164. end
  165.  
  166. function hauptmenu()
  167. coloranimation = colors.cyan
  168.  hintergrund()
  169.  animation()
  170.  steuerung()
  171.  mon.setBackgroundColor(colors.cyan)
  172.  mon.setTextScale(1)
  173.  mon.setTextColor(colors.white)
  174.  mon.setCursorPos(7,8)
  175.  mon.write("[Spiel starten]")
  176.  sleep(0.5)
  177.  mon.setCursorPos(7,9)
  178.  mon.write("[Optionen]")
  179.  sleep(0.5)
  180.  mon.setCursorPos(7,10)
  181.  mon.write("[Anleitung]")
  182.  sleep(0.5)
  183.  mon.setCursorPos(7,11)
  184.  mon.write("[Beenden]")
  185. end
  186.  
  187. hauptmenu()
  188.  
  189. os.loadAPI("ocs/apis/sensor")
  190. proximity = sensor.wrap("top")
  191. while true do
  192. player = "warte auf Spieler..."
  193. sleep(0.2)
  194. targets = proximity.getTargets()
  195. for k,v in pairs(targets) do
  196.   if v.Name == "Player"
  197.   and v.Position.X<=3 and v.Position.X>=-3
  198.   and v.Position.Z<=9 and v.Position.Z>=3
  199.   and v.Position.Y>=-3 and v.Position.Y<=4  
  200.   then
  201.   player = k
  202.  
  203. H = " "
  204.  
  205. --Springen
  206.   if v.Name == "Player" and
  207.      v.Position.X>=-0.5 and v.Position.X <=0.5 and
  208.      v.Position.Z>=5.5 and v.Position.Z<=6.5 and
  209.      v.Position.Y>=-0.5 and v.Position.Y<=2 then
  210.  
  211.   mon.setBackgroundColor(colors.cyan)
  212.   mon.setTextColor(colors.black)
  213.   mon.setCursorPos(60,17)
  214.   mon.write("+")
  215.  
  216.   H = "+"
  217.   print("+")
  218.   else
  219.  
  220.   mon.setBackgroundColor(colors.cyan)
  221.   mon.setTextColor(colors.white)
  222.   mon.setCursorPos(60,17)
  223.   mon.write("+")
  224.   end
  225. --W
  226.   if v.Name == "Player" and
  227.      v.Position.X>=-0.5 and v.Position.X <=0.5 and
  228.      v.Position.Z>=4.5 and v.Position.Z<=5.5 and
  229.      v.Position.Y>=-3 and v.Position.Y<=4 then
  230.  
  231.   mon.setBackgroundColor(colors.cyan)
  232.   mon.setTextColor(colors.blue)
  233.   mon.setCursorPos(60,15)
  234.   mon.write("W")
  235.  
  236.   H = "W"
  237.   print("W")
  238.   else
  239.  
  240.   mon.setBackgroundColor(colors.cyan)
  241.   mon.setTextColor(colors.white)
  242.   mon.setCursorPos(60,15)
  243.   mon.write("W")
  244.   end
  245. --A
  246.   if v.Name == "Player" and
  247.      v.Position.X>=-1.5 and v.Position.X <=-0.5 and
  248.      v.Position.Z>=5.5 and v.Position.Z<=6.5 and
  249.      v.Position.Y>=-3 and v.Position.Y<=4 then
  250.  
  251.   mon.setBackgroundColor(colors.cyan)
  252.   mon.setTextColor(colors.red)
  253.   mon.setCursorPos(57,17)
  254.   mon.write("A")
  255.  
  256.   H = "A"
  257.   print("A")
  258.   else
  259.  
  260.   mon.setBackgroundColor(colors.cyan)
  261.   mon.setTextColor(colors.white)
  262.   mon.setCursorPos(57,17)
  263.   mon.write("A")
  264.   end
  265. --S
  266.   if v.Name == "Player" and
  267.      v.Position.X>=0.5 and v.Position.X <=1.5 and
  268.      v.Position.Z>=5.5 and v.Position.Z<=6.5 and
  269.      v.Position.Y>=-3 and v.Position.Y<=4 then
  270.  
  271.   mon.setBackgroundColor(colors.cyan)
  272.   mon.setTextColor(colors.lime)
  273.   mon.setCursorPos(63,17)
  274.   mon.write("S")
  275.  
  276.   H = "S"
  277.   print("S")
  278.  
  279.   else
  280.  
  281.   mon.setBackgroundColor(colors.cyan)
  282.   mon.setTextColor(colors.white)
  283.   mon.setCursorPos(63,17)
  284.   mon.write("S")
  285.   end
  286. --D
  287.   if v.Name == "Player" and
  288.      v.Position.X>=-0.5 and v.Position.X <=0.5 and
  289.      v.Position.Z>=6.5 and v.Position.Z<=7.5 and
  290.      v.Position.Y>=-3 and v.Position.Y<=4 then
  291.  
  292.   mon.setBackgroundColor(colors.cyan)
  293.   mon.setTextColor(colors.yellow)
  294.   mon.setCursorPos(60,19)
  295.   mon.write("D")
  296.   H = "D"
  297.   print("D")
  298.  
  299.   else
  300.  
  301.   mon.setBackgroundColor(colors.cyan)
  302.   mon.setTextColor(colors.white)
  303.   mon.setCursorPos(60,19)
  304.   mon.write("D")
  305.   end
  306.  
  307.   if H == "W" then
  308.   i=i-1
  309.   sleep(0.6)
  310.   end
  311.   if H == "D" then
  312.   i=i+1
  313.   sleep(0.6)
  314.   end
  315.   print(i)
  316.   if i == 0 then
  317.   i = 4
  318.   end
  319.   if i == 5 then
  320.   i = 1
  321.   end
  322.  
  323. if i == 1 then
  324.  mon.setBackgroundColor(colors.cyan)
  325.  mon.setTextColor(colors.red)
  326.  mon.setCursorPos(7,8)
  327.  mon.write("[Spiel starten]")
  328. else
  329.  mon.setBackgroundColor(colors.cyan)
  330.  mon.setTextColor(colors.white)
  331.  mon.setCursorPos(7,8)
  332.  mon.write("[Spiel starten]")
  333. end
  334. if i == 1 and H == "+" then
  335.  print("Spiel starten")
  336.  shell.run("snake")
  337. end
  338. if i == 2 then
  339.  mon.setBackgroundColor(colors.cyan)
  340.  mon.setTextColor(colors.red)
  341.  mon.setCursorPos(7,9)
  342.  mon.write("[Optionen]")
  343. else
  344.  mon.setBackgroundColor(colors.cyan)
  345.  mon.setTextColor(colors.white)
  346.  mon.setCursorPos(7,9)
  347.  mon.write("[Optionen]")
  348. end
  349. if i == 2 and H == "+" then
  350.  print("Optionen")
  351. end
  352. if i == 3 then
  353.  mon.setBackgroundColor(colors.cyan)
  354.  mon.setTextColor(colors.red)
  355.  mon.setCursorPos(7,10)
  356.  mon.write("[Anleitung]")
  357. else
  358.  mon.setBackgroundColor(colors.cyan)
  359.  mon.setTextColor(colors.white)
  360.  mon.setCursorPos(7,10)
  361.  mon.write("[Anleitung]")
  362. end
  363. if i == 3 and H == "+" then
  364.  print("Anleitung")
  365.   mon.clear()
  366.   mon.setBackgroundColor(colors.black)
  367.   for b = 0,xMax,1 do
  368.    for i = 0,yMax,1 do
  369.    mon.setCursorPos(b,i)
  370.    mon.write(" ")  
  371.    end
  372.   end
  373.   coloranimation = colors.black
  374.   animation()
  375.   mon.setTextColor(colors.white)
  376.   mon.setCursorPos(7,8)
  377.   mon.write("Anleitung:")
  378.   sleep(10)
  379.   hauptmenu()
  380. end
  381. if i == 4 then
  382.  mon.setBackgroundColor(colors.cyan)
  383.  mon.setTextColor(colors.red)
  384.  mon.setCursorPos(7,11)
  385.  mon.write("[Beenden]")
  386. else
  387.  mon.setBackgroundColor(colors.cyan)
  388.  mon.setTextColor(colors.white)
  389.  mon.setCursorPos(7,11)
  390.  mon.write("[Beenden]")
  391. end
  392. if i == 4 and H == "+" then
  393.  print("Beenden")
  394.  os.reboot()
  395. end
  396. end
  397. end
  398. for l = 1,xMax,1 do
  399. mon.setCursorPos(l,1)
  400. mon.setBackgroundColor(colors.cyan)
  401. mon.write(" ")
  402. end
  403. mon.setCursorPos(1,1)
  404. mon.setTextColor(colors.white)
  405. mon.setBackgroundColor(colors.black)
  406. mon.write(player)
  407. end
Add Comment
Please, Sign In to add comment