Guest User

flappyPixel

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