Advertisement
Guest User

flappyPixel

a guest
Jun 19th, 2014
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.77 KB | None | 0 0
  1. ver = "beta 1.0 build 04"
  2. aF = true
  3. betatesting = true
  4.  
  5. function drawMenu()
  6.   term.setCursorPos(1,1)
  7.   term.setBackgroundColor(colors.lightBlue)
  8.   term.setTextColor(colors.green)
  9.   term.clear()
  10.   term.setBackgroundColor(colors.white)
  11.   term.write("FlappyPixel game by Konlab")
  12.   print("                           ")
  13.   print("                           ")
  14.   print()
  15.   print("Begin game                 ")
  16.   print()
  17.   print("Controls                   ")
  18.   print()
  19.   print("Exit game                  ")
  20.   if betatesting then
  21.   term.setBackgroundColor(colors.lightBlue)
  22.   term.setCursorPos(1,20)
  23.   term.write("Beta testing")
  24.   end
  25.   term.setBackgroundColor(colors.lightBlue)
  26.  
  27.  
  28. end
  29. hmD = 0
  30. q = math.random(3,18)
  31. w = math.random(3,18)
  32. e = math.random(3,18)
  33. qp = 28
  34. wp = 38
  35. ep = 45
  36. --pp = 10
  37. function kpress()
  38.   while true do
  39.     event2,char2 = os.pullEvent("char")
  40. --    print(event2..char2)
  41.     if char2 == "w" then
  42.       hmD = 0
  43.       ppos = ppos-3
  44.     end
  45.    
  46.   end
  47. end
  48. function gener()
  49.   term.clear()
  50.  
  51.  
  52.   if qp == 1 then
  53.   q = math.random(3,18)
  54.   qp = 28
  55.   end
  56.   if wp == 1 then
  57.   w = math.random(3,18)
  58.   wp = 28
  59.   end
  60.   if ep == 1 then
  61.   e = math.random(3,18)
  62.  
  63. ep = 28
  64. end
  65.   qp = qp - 1
  66.   wp = wp-1
  67.   ep = ep - 1
  68.   term.setBackgroundColor(colors.brown)
  69.   for j = 1,3 do
  70.   for i=1,26 do
  71.     if j == 1 then
  72.       term.setCursorPos(qp,i)
  73.       term.write(" ")
  74.     elseif j == 2 then
  75.       term.setCursorPos(wp,i)
  76.       term.write(" ")
  77.     elseif j == 3 then
  78.       term.setCursorPos(ep,i)
  79.       term.write(" ")
  80.     end
  81.   end  
  82.   end
  83.   term.setBackgroundColor(colors.blue)
  84.   for j=1,3 do
  85.   for i=-2,0,1 do
  86.     if j==1 then
  87.     term.setCursorPos(qp,q+i)
  88.     term.write(" ")
  89.     elseif j == 2 then
  90.     term.setCursorPos(wp,w+i)
  91.     term.write(" ")
  92.     elseif j == 3 then
  93.     term.setCursorPos(ep,e+i)
  94.     term.write(" ")
  95.    
  96.     end
  97.   end
  98.   end
  99. end
  100. function game()
  101.   parallel.waitForAny(game2,kpress)
  102. end
  103. function lose(text)
  104.   sleep(2)
  105.   term.setBackgroundColor(colors.lightBlue)
  106.   term.setTextColor(colors.yellow)
  107.   term.setCursorPos(1,5)
  108.   term.clear()
  109.   print(text)
  110.   sleep(1)
  111.   term.setCursorPos(1,7)
  112.   print("Click to continue")
  113.   qp = 28
  114.   wp = 38
  115.   ep = 45
  116.  
  117.   os.pullEvent("mouse_click")
  118.   return
  119. end
  120. function game2()
  121.   term.setBackgroundColor(colors.blue)
  122.   term.clear()
  123.   function simu()
  124.   ppos = 10
  125.   while true do
  126. --  gener()      
  127. --  goup()
  128.   --ppos = ppos+2
  129. --  hmD = hmD+1
  130.   if ppos < 2 then
  131.     ppos = 1
  132.   end
  133.   gener()
  134.   goup()
  135.   if hmD == 0 then
  136.     ppos = ppos+1
  137.     hmD = 1
  138.   elseif hmD < 5 then
  139.     ppos = ppos+1
  140.     hmD = hmD+1
  141.   elseif hmD < 8 then
  142.     ppos = ppos+2
  143.     hmD = hmD + 1
  144.   elseif hmD < 16 then
  145.     ppos = ppos+3
  146.     hmD = hmD - 1
  147.   else
  148.     ppos = ppos+4
  149.   end
  150.  
  151.   if ppos > 20 then
  152.     lose("You're fallen in nether")
  153.     return
  154.   end
  155.   if qp == 2 then
  156.   if q ~= ppos and q ~= ppos - 1 and q ~= ppos + 1 then
  157.     lose("FlappyPixel hit building")
  158.     return
  159.   end
  160.   end
  161.   if w ~= ppos and w ~= ppos + 1 and w ~= ppos - 1 and wp == 2 then
  162.     lose("FlappyPixel hit building")
  163.     return
  164.   end
  165.   if e ~= ppos and e~= ppos-1 and e~= ppos+1 and ep == 2 then
  166.     lose("FlappyPixel hit building")
  167.     return
  168.   end
  169.   sleep(0.3)
  170.   end
  171.   end
  172.   function goup()
  173.   pp = 10
  174. --  while true do
  175.     for i=-1,0 do
  176.       term.setCursorPos(2,ppos+i)
  177.       term.write(" ")
  178.     end
  179.     term.setCursorPos(2,ppos)
  180.     if aF then
  181.     term.write("x")
  182.     aF = false
  183.     else
  184.     term.write("+")
  185.     aF = true
  186.     end
  187. --    pp = pp+1
  188.    
  189. --  end  
  190.   end
  191.   simu()
  192. --  parallel.waitForAny(simu,kpress)
  193. end
  194. function credits()
  195.  
  196.   term.clear()
  197.   term.setCursorPos(1,1)
  198.   print("FlappyPixel - Controls")
  199.   print("W to jump")
  200.   print()
  201.   print("Current version:")
  202.   print(ver)
  203.   print()
  204.   if betatesting then
  205.    
  206.     print("Use at your own risk!")
  207.     print()
  208.   end
  209.   print("Click to continue")
  210.   os.pullEvent("mouse_click")
  211.   return
  212. end
  213. function main()
  214.   while true do
  215.     drawMenu()
  216.     event,button,x,y = os.pullEvent("mouse_click")
  217.     if y == 4 then
  218.       game()
  219.     elseif y == 6 then
  220.       credits()
  221.     elseif y == 8 then
  222.       return
  223.     end
  224.    
  225.    
  226.   end  
  227. end
  228. --
  229. local ok,err = pcall(main)
  230. if err == "Terminated" then
  231.   print("Terminated")
  232.   print("Thanks for using FlappyPixel")
  233.   return  
  234. end
  235. --if ok then
  236.   term.setBackgroundColor(colors.black)
  237.   term.setTextColor(colors.white)
  238.   term.clear()
  239.   term.setCursorPos(1,1)
  240. if ok then
  241.   print("Thanks for using FlappyPixel")
  242.   term.setCursorPos(1,3)
  243. else
  244.   print("--Crash report begin--")
  245.   print("Ohh no! Crashed:")
  246.   print()
  247.   print(err)
  248.   print()
  249.   print("Please report!")
  250.   print("--End--")
  251.   print("press any key")
  252.   os.pullEvent("key")
  253. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement