LDDestroier

CC QuickDraw game

Apr 10th, 2016
1,423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.26 KB | None | 0 0
  1. --[[
  2.  QuickDraw!
  3.   Can you outshoot the cowbow?
  4.    I bet you can! It's actually really easy...
  5.  
  6.  pastebin get uGTzMxNL quickdraw
  7.  std pb uGTzMxNL quickdraw
  8.  std ld quickdraw
  9. --]]
  10.  
  11. local difficulty = 1.2 --amount of time you have to shoot im'
  12.  
  13. local isRunning = true  --whether the game should loop
  14. local over = false      --whether you or the guy is dead
  15.  
  16. local wins = 0
  17. local losses = 0
  18.  
  19. local s = {
  20.     enemy = {
  21.         getready = {{},{},{0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,},{0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,},{0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,16,16,},{0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,16,16,},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,},{0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,128,4096,4096,4096,4096,},{0,0,0,0,0,0,0,0,0,0,0,4096,0,4096,128,4096,4096,0,4096,},{0,0,0,0,0,0,0,0,0,0,0,4096,0,4096,128,4096,4096,0,4096,},{0,0,0,0,0,0,0,0,0,0,0,4096,0,4096,128,4096,4096,0,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,256,4096,128,4096,4096,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,2048,2048,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,2048,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},},
  22.         shoot1 = {{},{},{0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,},{0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,},{0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,16,16,},{0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,16,16,},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,},{0,0,0,0,0,0,0,0,0,0,0,0,0,4096,128,4096,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,128,4096,4096,4096,},{0,0,0,0,0,0,0,0,0,0,0,4096,0,4096,4096,128,4096,4096,},{0,0,0,0,0,0,0,0,0,0,0,256,0,4096,4096,128,4096,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,128,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,2048,2048,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,2048,2048,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},},
  23.         shoot2 = {{},{},{0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,},{0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,},{0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,16,16,},{0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,16,16,},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,},{0,0,0,0,0,0,0,0,0,0,0,0,256,4096,4096,128,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,4096,128,4096,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,128,4096,0,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,128,4096,0,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,128,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,2048,2048,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,2048,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},},
  24.         laugh = {{},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,0,0,0,0,1,1,32768,1,1,32768,1,1,32768,32768,1,1,32768,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,16,16,0,0,0,1,1,1,1,32768,1,1,32768,1,32768,1,1,32768,1,32768,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,16,16,0,1,1,1,1,1,1,32768,32768,32768,32768,1,32768,32768,32768,32768,1,32768,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,0,0,0,0,1,1,1,1,32768,1,1,32768,1,32768,1,1,32768,1,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,128,4096,0,0,0,0,0,1,1,32768,1,1,32768,1,32768,1,1,32768,1,32768,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,4096,128,4096,4096,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,4096,0,4096,4096,128,4096,0,4096,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,4096,0,4096,4096,128,4096,0,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,4096,128,4096,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,2048,2048,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,2048,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},},
  25.         dead = {{},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,0,0,0,0,1,1,1,32768,32768,1,1,32768,1,32768,1,32768,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,4096,0,16,16,16,16,0,4096,0,1,1,1,1,32768,1,1,32768,1,32768,1,32768,1,32768,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,4096,0,16,16,16,16,0,1,1,1,1,1,1,32768,32768,32768,32768,1,32768,32768,32768,1,32768,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,4096,0,0,16,16,0,0,4096,0,1,1,1,1,32768,1,1,32768,1,32768,1,32768,1,1,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,4096,0,4096,4096,128,4096,0,4096,0,0,0,1,1,32768,1,1,32768,1,32768,1,32768,1,32768,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,4096,128,4096,4096,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,128,4096,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,},{0,0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,128,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,0,4096,4096,128,4096,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,2048,2048,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,2048,0,2048,},{0,0,0,0,0,0,0,0,0,0,0,0,0,2048,0,0,2048,},{0,0,0,0,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8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,},{8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,},{8,8,8,8,8,128,128,128,128,128,128,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,},{8,8,8,8,8,128,128,128,128,128,128,128,128,128,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,16,16,16,16,16,16,16,16,16,},{16,16,16,16,16,128,128,128,128,128,128,128,128,128,16,16,16,16,16,16,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,},{16,16,16,16,16,128,128,128,128,128,128,128,128,128,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,},{16,16,16,16,16,128,128,128,128,128,128,128,128,128,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,},{256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,},{256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,},{16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,},},
  28. }
  29. _s = s
  30.  
  31. local scr_x, scr_y = term.getSize()
  32.  
  33. local yield = function()
  34.     os.queueEvent("yield")
  35.     os.pullEvent("yield")
  36. end
  37.  
  38. local RPGslowprint = function(text,rate)
  39.     local cX,cY = term.getCursorPos()
  40.     yield()
  41.     local uutcome = parallel.waitForAny(function()
  42.         textutils.slowPrint(text,rate or 20)
  43.     end, function()
  44.         os.pullEvent("key")
  45.     end)
  46.     if uutcome == 2 then
  47.         term.setCursorPos(cX,cY)
  48.         print(text)
  49.     end
  50. end
  51.  
  52. local displayHelp = function(cli)
  53.     local helptext = [[
  54.  QuickDraw by EldidiStroyrr
  55.  
  56.  HOW TO PLAY:
  57.  
  58.   1) Click and hold on the green square for three seconds.
  59.   2) As soon as it says DRAW, quickly move your mouse over the guy and let go.
  60.   3) If you win, it'll get slightly harder
  61.  
  62. Press 'Q' to quit ingame.
  63. ]]
  64.     if cli then
  65.         print(helptext)
  66.     else
  67.         term.setBackgroundColor(colors.gray)
  68.         term.setTextColor(colors.white)
  69.         term.setCursorPos(1,2)
  70.         term.clear()
  71.         RPGslowprint(helptext,30)
  72.         term.setCursorPos(2,scr_y-1)
  73.         term.write("Press any key to continue!")
  74.         yield()
  75.         os.pullEvent("key")
  76.     end
  77. end
  78.  
  79. function mixImages( img1, img2 )
  80.     local output = { }
  81.     for a = 1, #img2 do
  82.         output[ a ] = { }
  83.         if not img1[ a ] then
  84.             for b = 1, #img2[ a ] do
  85.                 output[ a ][ b ] = img2[ a ][ b ]
  86.             end
  87.         else
  88.             for b = 1, #img2[ a ] do
  89.                 if img1[ a ][ b ] then
  90.                     if img1[ a ][ b ] ~= 0 then
  91.                         output[ a ][ b ] = img1[ a ][ b ]
  92.                     else
  93.                         output[ a ][ b ] = img2[ a ][ b ]
  94.                     end
  95.                 else
  96.                     output[ a ][ b ] = img2[ a ][ b ]
  97.                 end
  98.             end
  99.         end
  100.     end
  101.     return output
  102. end
  103.  
  104. local function clear()
  105.     local b,t = term.getBackgroundColor(), term.getTextColor()
  106.     term.setBackgroundColor(colors.black)
  107.     term.clear()
  108.     term.setBackgroundColor(b)
  109. end
  110.  
  111. local function cprint(txt)
  112.     local pX, pY = term.getCursorPos()
  113.     term.setCursorPos((scr_x/2)-math.floor(#txt/2),(scr_y/2)+4)
  114.     term.write(txt)
  115.     term.setCursorPos(pX,pY)
  116. end
  117.  
  118. local gameArea, alive
  119.  
  120. local function handleShooting()
  121.     currentSprite = "getready"
  122.     sleep(difficulty/4)
  123.     paintutils.drawImage(mixImages(s.enemy.shoot1,s.bg),1,1)
  124.     currentSprite = "shoot1"
  125.     sleep(difficulty/4)
  126.     paintutils.drawImage(mixImages(s.enemy.shoot2,s.bg),1,1)
  127.     currentSprite = "shoot2"
  128.     sleep(difficulty/2)
  129.     os.queueEvent("thoseWhoDig",false)
  130.     return false, "dead"
  131. end
  132.  
  133. function drawHitBox(color)
  134.     paintutils.drawFilledBox(scr_x-3,scr_y-2,scr_x,scr_y,color)
  135.     term.setBackgroundColor(colors.lightBlue)
  136.     term.setTextColor(colors.white)
  137.     local txt = "YOU: "..wins.." / ENEMY: "..losses
  138.     term.setCursorPos(scr_x-(#txt+1)+1,1)
  139.     term.write(txt)
  140.     term.setBackgroundColor(colors.lightGray)
  141.     term.setTextColor(colors.gray)
  142.     local txt = "TIME: "..tostring(difficulty):sub(1,5).." SEC"
  143.     term.setCursorPos(2,scr_y-1)
  144.     term.write(txt)
  145. end
  146.  
  147. function exitGame()
  148.     if not isRunning then
  149.         term.setCursorPos(1,scr_y)
  150.         term.setBackgroundColor(colors.black)
  151.         term.write(string.rep(" ",scr_x-4))
  152.         term.setCursorPos(1,scr_y)
  153.         sleep(0)
  154.     end
  155.     error()
  156. end
  157.  
  158. currentSprite = "getready"
  159.  
  160. local function countdown()
  161.     term.setCursorPos((scr_x/2)-2,scr_y/2)
  162.     term.setTextColor(colors.black)
  163.     term.setBackgroundColor(colors.lightBlue)
  164.     cprint("3...")
  165.     sleep(0.8)
  166.     cprint("2...")
  167.     sleep(0.8)
  168.     cprint("1...")
  169.     sleep(0.8)
  170.     cprint("DRAW!")
  171. end
  172.  
  173. function getInput()
  174.     alive = true
  175.     os.pullEvent("getMeSomeInput")
  176.     while true do
  177.         local evt
  178.         if gameArea == "beginning1" then
  179.             evt = {os.pullEvent()}
  180.             if evt[1] == "mouse_click" then
  181.                 if evt[3] >= scr_x-3 and evt[4] >= scr_y-2 then
  182.                     local res = parallel.waitForAny(function()
  183.                         while true do
  184.                             local evt = {os.pullEvent()}
  185.                             if evt[1] == "mouse_up" or evt[1] == "mouse_click" then
  186.                                 break
  187.                             elseif evt[1] == "mouse_drag" then
  188.                                 if (evt[3] < scr_x-3) or (evt[4] < scr_y-2) then
  189.                                     break
  190.                                 end
  191.                             end
  192.                         end
  193.                     end, countdown)
  194.                     if (res == 1) and not over then
  195.                         cprint("FOUL!!")
  196.                         --exitGame()
  197.                     end
  198.                     os.queueEvent("imready")
  199.                     parallel.waitForAny(function()
  200.                         while alive do
  201.                             evt = {os.pullEvent()}
  202.                             if evt[1] == "mouse_up" then
  203.                                 local x,y = evt[3],evt[4]
  204.                                 if _s.enemy[currentSprite][y] then
  205.                                     if _s.enemy[currentSprite][y][x] then
  206.                                         if _s.enemy[currentSprite][y][x] ~= 0 then
  207.                                             os.queueEvent("thoseWhoDig",true,x,y)
  208.                                             break
  209.                                         end
  210.                                     end
  211.                                 end
  212.                                 sleep(0.2)
  213.                             elseif evt[1] == "mouse_click" then --yay for anticheating
  214.                                 sleep(1)
  215.                             end
  216.                         end
  217.                     end, handleShooting)
  218.                 end
  219.             elseif evt[1] == "key" then
  220.                 if evt[2] == keys.q then
  221.                     isRunning = false
  222.                     exitGame()
  223.                 end
  224.             end
  225.         end
  226.     end
  227. end
  228.  
  229. local flash = {
  230.     colors.white,
  231.     colors.lightGray,
  232.     colors.black,
  233.     colors.gray,
  234. }
  235.  
  236. local tArg = {...}
  237. if tArg[1] == "help" then
  238.     return displayHelp(true)
  239. end
  240.  
  241. function game()
  242.     over = false
  243.     term.setTextColor(colors.white)
  244.     while true do
  245.         gameArea = "beginning1"
  246.         paintutils.drawImage(mixImages(s.enemy.getready,s.bg),1,1)
  247.         drawHitBox(colors.green)
  248.         currentSprite = "getready"
  249.         os.queueEvent("getMeSomeInput")
  250.         os.pullEvent("imready")
  251.         os.queueEvent("shootStart!")
  252.         local _,alive,x,y = os.pullEvent("thoseWhoDig")
  253.         over = true
  254.         if not alive then
  255.             for a = 1, #flash do
  256.                 term.setBackgroundColor(flash[a])
  257.                 term.clear()
  258.                 sleep(0.1)
  259.             end
  260.             losses = losses + 1
  261.             paintutils.drawImage(mixImages(s.enemy.laugh,s.bg),1,1)
  262.             term.setTextColor(colors.red)
  263.             term.setBackgroundColor(colors.lightBlue)
  264.             sleep(0.5)
  265.             --exitGame()
  266.         else
  267.             paintutils.drawImage(mixImages(s.enemy.dead,s.bg),1,1)
  268.             paintutils.drawPixel(x,y,colors.red)
  269.             sleep(0.2)
  270.             term.setBackgroundColor(colors.lightBlue)
  271.             term.setTextColor(colors.black)
  272.             cprint("YOU WIN!")
  273.             wins = wins + 1
  274.             sleep(0.8)
  275.             difficulty = difficulty * 0.92
  276.             --exitGame()
  277.         end
  278.     end
  279. end
  280.  
  281. clear()
  282. displayHelp(false)
  283. while isRunning do
  284.     parallel.waitForAny(getInput,game)
  285.     if isRunning then
  286.         sleep(0.8)
  287.     end
  288. end
Add Comment
Please, Sign In to add comment