brett122798

Moneybags Alpha 1.2.1

May 25th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.74 KB | None | 0 0
  1. -- PROGRAM CONFIGURATION:
  2.  
  3. tickSpeed = 0.1  -- How fast the game goes. Lower the faster. 0.1 is the recommended speed.
  4. MPtickSpeed = 0.1 -- How fast the game goes in Multiplayer. This data will be sent to your opponent so you two will be at the same speed. 0.1 is the recommended speed.
  5.  
  6. -- END OF CONFIGURATION
  7.  
  8. version = "a1.2.1"
  9.  
  10.  
  11. function titleScreen()
  12.     term.clear()
  13.     term.setCursorPos(1, 1)
  14.     print("")
  15.     print("               $$$  Moneybags  $$$               ")
  16.     print("                   Alpha 1.2.1                   ")
  17.     print("")
  18.     print("")
  19.     menuPos = 1
  20.     while true do
  21.         term.setCursorPos(1, 6)
  22.         if menuPos == 1 then
  23.             print("                > Single Player <                ")
  24.         else
  25.             print("                  Single Player                  ")
  26.         end
  27.         print("")
  28.         if menuPos == 2 then
  29.             print("                 > Multiplayer <                 ")
  30.         else
  31.             print("                   Multiplayer                   ")
  32.         end
  33.         print("")
  34.         if menuPos == 3 then
  35.             print("                  > Quit Game <                  ")
  36.         else
  37.             print("                    Quit Game                    ")
  38.         end
  39.         event, key = os.pullEvent("key")
  40.         if (key == 17 or key == 200) and (menuPos >= 2) then
  41.             menuPos = menuPos - 1
  42.         elseif (key == 31 or key == 208) and (menuPos <= 2) then
  43.             menuPos = menuPos + 1
  44.         elseif key == 28 and menuPos == 1 then
  45.             parallel.waitForAny(singlePlayer, singlePlayerKeyListener)
  46.             term.setCursorPos(1, 5)
  47.             print("          -----------------------------          ")
  48.             print("          |         You Lose!         |          ")
  49.             print("")
  50.             print("          -----------------------------          ")
  51.             print("          |         Game Data         |          ")
  52.             print("          |---------------------------|          ")
  53.             print("          | Score: "..score)
  54.             term.setCursorPos(39, 11)
  55.             print("|")
  56.             print("          | Ticks: "..tickCount)
  57.             term.setCursorPos(39, 12)
  58.             print("|")
  59.             print("          -----------------------------          ")
  60.             loseCount = 9
  61.             repeat
  62.                 term.setCursorPos(1, 7)
  63.                 print("          | Continuing in "..loseCount.." seconds.. |          ")
  64.                 loseCount = loseCount - 1
  65.                 sleep(1)
  66.             until loseCount == 0
  67.             term.clear()
  68.             term.setCursorPos(1, 1)
  69.             print("")
  70.     print("               $$$  Moneybags  $$$               ")
  71.     print("                   Alpha 1.2.1                   ")
  72.     print("")
  73.     print("")
  74.         elseif key == 28 and menuPos == 2 then
  75.             parallel.waitForAny(multiPlayer)
  76.         elseif key == 28 and menuPos == 3 then
  77.             term.clear()
  78.             term.setCursorPos(1, 1)
  79.             break
  80.         end
  81.         term.setCursorPos(1, 6)
  82.         term.clearLine()
  83.         term.clearLine()
  84.         term.clearLine()
  85.     end
  86.  
  87. end
  88.  
  89. function singlePlayer()
  90.     -- Variable Definitions
  91.     money = 300
  92.     playerPos = 8
  93.     score = 0
  94.     lives = 3
  95.     lose = false
  96.     moneybagTimer = 0
  97.     moneybagOne =
  98.     {
  99.         onScreen = false,
  100.         xPos = 0
  101.     }
  102.     moneybagTwo =
  103.     {
  104.         onScreen = false,
  105.         xPos = 0
  106.     }
  107.     moneybagThree =
  108.     {
  109.         onScreen = false,
  110.         xPos = 0
  111.     }
  112.     moneybagFour =
  113.     {
  114.         onScreen = false,
  115.         xPos = 0
  116.     }
  117.     moneybagFive =
  118.     {
  119.         onScreen = false,
  120.         xPos = 0
  121.     }
  122.     moneybagSix =
  123.     {
  124.         onScreen = false,
  125.         xPos = 0
  126.     }
  127.     moneybagSeven =
  128.     {
  129.         onScreen = false,
  130.         xPos = 0
  131.     }
  132.     moneybagEight =
  133.     {
  134.         onScreen = false,
  135.         xPos = 0
  136.     }
  137.  
  138.     playerMove = false
  139.     tickCount = 0
  140.     -- End of Variable Definitions
  141.    
  142.    
  143.     -- Tick Loop
  144.     repeat
  145.         if playerMove == true then
  146.             if currentKey == "up" and playerPos > 1 then
  147.                 playerPos = playerPos - 1
  148.                 currentKey = false
  149.             elseif currentKey == "down" and playerPos < 17 then
  150.                 playerPos = playerPos + 1
  151.                 currentKey = false
  152.             end
  153.             playerMove = false
  154.         else
  155.             playerMove = true
  156.         end
  157.         if moneybagTimer == 6 then
  158.             moneybagTimer = 0
  159.             if moneybagOne.onScreen == false then
  160.                 moneybagOne.onScreen = true
  161.                 moneybagOne.yPos = math.random(1, 17)
  162.             elseif moneybagTwo.onScreen == false then
  163.                 moneybagTwo.onScreen = true
  164.                 moneybagTwo.yPos = math.random(1, 17)
  165.             elseif moneybagThree.onScreen == false then
  166.                 moneybagThree.onScreen = true
  167.                 moneybagThree.yPos = math.random(1, 17)
  168.             elseif moneybagFour.onScreen == false then
  169.                 moneybagFour.onScreen = true
  170.                 moneybagFour.yPos = math.random(1, 17)
  171.             elseif moneybagFive.onScreen == false then
  172.                 moneybagFive.onScreen = true
  173.                 moneybagFive.yPos = math.random(1, 17)
  174.             elseif moneybagSix.onScreen == false then
  175.                 moneybagSix.onScreen = true
  176.                 moneybagSix.yPos = math.random(1, 17)
  177.             elseif moneybagSeven.onScreen == false then
  178.                 moneybagSeven.onScreen = true
  179.                 moneybagSeven.yPos = math.random(1, 17)
  180.             elseif moneybagEight.onScreen == false then
  181.                 moneybagEight.onScreen = true
  182.                 moneybagEight.yPos = math.random(1, 17)
  183.             end
  184.         else
  185.             moneybagTimer = moneybagTimer + 1
  186.         end
  187.         if moneybagOne.onScreen == true then
  188.             if moneybagOne.xPos == 48 then
  189.                 moneybagOne.onScreen = false
  190.                 moneybagOne.xPos = 0
  191.                 score = score + 1
  192.             else
  193.                 moneybagOne.xPos = moneybagOne.xPos + 1
  194.             end
  195.         end
  196.         if moneybagTwo.onScreen == true then
  197.             if moneybagTwo.xPos == 48 then
  198.                 moneybagTwo.onScreen = false
  199.                 moneybagTwo.xPos = 0
  200.                 score = score + 1
  201.             else
  202.                 moneybagTwo.xPos = moneybagTwo.xPos + 1
  203.             end
  204.         end
  205.         if moneybagThree.onScreen == true then
  206.             if moneybagThree.xPos == 48 then
  207.                 moneybagThree.onScreen = false
  208.                 moneybagThree.xPos = 0
  209.                 score = score + 1
  210.             else
  211.                 moneybagThree.xPos = moneybagThree.xPos + 1
  212.             end
  213.         end
  214.         if moneybagFour.onScreen == true then
  215.             if moneybagFour.xPos == 48 then
  216.                 moneybagFour.onScreen = false
  217.                 moneybagFour.xPos = 0
  218.                 score = score + 1
  219.             else
  220.                 moneybagFour.xPos = moneybagFour.xPos + 1
  221.             end
  222.         end
  223.         if moneybagFive.onScreen == true then
  224.             if moneybagFive.xPos == 48 then
  225.                 moneybagFive.onScreen = false
  226.                 moneybagFive.xPos = 0
  227.                 score = score + 1
  228.             else
  229.                 moneybagFive.xPos = moneybagFive.xPos + 1
  230.             end
  231.         end
  232.         if moneybagSix.onScreen == true then
  233.             if moneybagSix.xPos == 48 then
  234.                 moneybagSix.onScreen = false
  235.                 moneybagSix.xPos = 0
  236.                 score = score + 1
  237.             else
  238.                 moneybagSix.xPos = moneybagSix.xPos + 1
  239.             end
  240.         end
  241.         if moneybagSeven.onScreen == true then
  242.             if moneybagSeven.xPos == 48 then
  243.                 moneybagSeven.onScreen = false
  244.                 moneybagSeven.xPos = 0
  245.                 score = score + 1
  246.             else
  247.                 moneybagSeven.xPos = moneybagSeven.xPos + 1
  248.             end
  249.         end
  250.         if moneybagEight.onScreen == true then
  251.             if moneybagEight.xPos == 48 then
  252.                 moneybagEight.onScreen = false
  253.                 moneybagEight.xPos = 0
  254.                 score = score + 1
  255.             else
  256.                 moneybagEight.xPos = moneybagEight.xPos + 1
  257.             end
  258.         end
  259.         if (((moneybagOne.yPos == playerPos and moneybagOne.xPos == 47) or (moneybagTwo.yPos == playerPos and moneybagTwo.xPos == 47)) or ((moneybagThree.yPos == playerPos and moneybagThree.xPos == 47) or (moneybagFour.yPos == playerPos and moneybagFour.xPos == 47)) or ((moneybagFive.yPos == playerPos and moneybagFive.xPos == 47) or (moneybagSix.yPos == playerPos and moneybagSix.xPos == 47)) or ((moneybagSeven.yPos == playerPos and moneybagSeven.xPos == 47) or (moneybagEight.yPos == playerPos and moneybagEight.xPos == 47))) then
  260.         lives = lives - 1
  261.         end
  262.         if lives == 0 then
  263.         lose = true
  264.         end
  265.         tickCount = tickCount + 1
  266.         refreshSinglePlayerGraphics()
  267.         sleep(tickSpeed)
  268.     until lose
  269.     -- End of Tick Loop
  270. end
  271.  
  272. function singlePlayerKeyListener()
  273.     while true do
  274.     event, key = os.pullEvent("key")
  275.     if key == 17 or key == 200 then
  276.         currentKey = "up"
  277.     elseif key == 31 or key == 208 then
  278.         currentKey = "down"
  279.     elseif key == 1 then
  280.         currentKey = "escape"
  281.     end
  282.     end
  283. end
  284.  
  285. function refreshSinglePlayerGraphics()
  286.     term.clear()
  287.     term.setCursorPos(1, 1)
  288.     print("Ticks: "..tickCount.."    Score: "..score.."   Lives: "..lives)
  289.     term.setCursorPos(48, playerPos + 1)
  290.     print("X")
  291.     if moneybagOne.onScreen == true then
  292.     term.setCursorPos(moneybagOne.xPos, moneybagOne.yPos + 1)
  293.     print(">$")
  294.     end
  295.     if moneybagTwo.onScreen == true then
  296.     term.setCursorPos(moneybagTwo.xPos, moneybagTwo.yPos + 1)
  297.     print(">$")
  298.     end
  299.     if moneybagThree.onScreen == true then
  300.     term.setCursorPos(moneybagThree.xPos, moneybagThree.yPos + 1)
  301.     print(">$")
  302.     end
  303.     if moneybagFour.onScreen == true then
  304.     term.setCursorPos(moneybagFour.xPos, moneybagFour.yPos + 1)
  305.     print(">$")
  306.     end
  307.     if moneybagFive.onScreen == true then
  308.     term.setCursorPos(moneybagFive.xPos, moneybagFive.yPos + 1)
  309.     print(">$")
  310.     end
  311.     if moneybagSix.onScreen == true then
  312.     term.setCursorPos(moneybagSix.xPos, moneybagSix.yPos + 1)
  313.     print(">$")
  314.     end
  315.     if moneybagSeven.onScreen == true then
  316.     term.setCursorPos(moneybagSeven.xPos, moneybagSeven.yPos + 1)
  317.     print(">$")
  318.     end
  319.     if moneybagEight.onScreen == true then
  320.     term.setCursorPos(moneybagEight.xPos, moneybagEight.yPos + 1)
  321.     print(">$")
  322.     end
  323. end
  324.  
  325. titleScreen()
Add Comment
Please, Sign In to add comment