brett122798

Moneybags Alpha 1.4

Jun 5th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.76 KB | None | 0 0
  1. -- PROGRAM CONFIGURATION:
  2.  
  3. tickSpeed = 0.05  -- How fast the game goes. Higher the slower. 0.05 is the recommended speed.
  4. MPtickSpeed = 0.05 -- 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.05 is the recommended speed.
  5.  
  6. -- END OF CONFIGURATION
  7.  
  8. version = "a1.4"
  9.  
  10.  
  11. function titleScreen()
  12.     term.clear()
  13.     term.setCursorPos(1, 1)
  14.     print("")
  15.     print("               $$$  Moneybags  $$$               ")
  16.     print("                    Alpha 1.4                    ")
  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, keyListener)
  46.             if lose then
  47.                 term.setCursorPos(1, 5)
  48.                 print("          -----------------------------          ")
  49.                 print("          |         You Lose!         |          ")
  50.                 print("          -----------------------------          ")
  51.                 print("          |     $$  Game Data  $$     |          ")
  52.                 print("          |---------------------------|          ")
  53.                 print("          | Score: "..score)
  54.                 term.setCursorPos(39, 10)
  55.                 print("|")
  56.                 print("          | Ticks: "..tickCount)
  57.                 term.setCursorPos(39, 11)
  58.                 print("|")
  59.                 print("          -----------------------------          ")
  60.                 sleep(1)
  61.                 print("          | Press any key to continue |          ")
  62.                 print("          |     to the Main Menu.     |          ")
  63.                 print("          -----------------------------          ")
  64.                 os.pullEvent("key")
  65.             end
  66.             term.clear()
  67.             term.setCursorPos(1, 1)
  68.             print("")
  69.             print("               $$$  Moneybags  $$$               ")
  70.             print("                    Alpha 1.4                    ")
  71.             print("")
  72.             print("")
  73.         elseif key == 28 and menuPos == 2 then
  74.             parallel.waitForAny(multiPlayer, keyListener, packetListener)
  75.         elseif key == 28 and menuPos == 3 then
  76.             term.clear()
  77.             term.setCursorPos(1, 1)
  78.             break
  79.         end
  80.         term.setCursorPos(1, 6)
  81.         term.clearLine()
  82.         term.clearLine()
  83.         term.clearLine()
  84.     end
  85.  
  86. end
  87.  
  88. function singlePlayer()
  89.     -- Variable Definitions
  90.     money = 300
  91.     payday = 0
  92.     playerPos = 8
  93.     score = 0
  94.     prevLifeScore = 0
  95.     lives = 3
  96.     lose = false
  97.     gameExit = false
  98.     moneybagTimer = 0
  99.     moneybagOne =
  100.     {
  101.         onScreen = false,
  102.         xPos = 0
  103.     }
  104.     moneybagTwo =
  105.     {
  106.         onScreen = false,
  107.         xPos = 0
  108.     }
  109.     moneybagThree =
  110.     {
  111.         onScreen = false,
  112.         xPos = 0
  113.     }
  114.     moneybagFour =
  115.     {
  116.         onScreen = false,
  117.         xPos = 0
  118.     }
  119.     moneybagFive =
  120.     {
  121.         onScreen = false,
  122.         xPos = 0
  123.     }
  124.     moneybagSix =
  125.     {
  126.         onScreen = false,
  127.         xPos = 0
  128.     }
  129.     moneybagSeven =
  130.     {
  131.         onScreen = false,
  132.         xPos = 0
  133.     }
  134.     moneybagEight =
  135.     {
  136.         onScreen = false,
  137.         xPos = 0
  138.     }
  139.     moneybagNine =
  140.     {
  141.         onScreen = false,
  142.         xPos = 0
  143.     }
  144.     moneybagTen =
  145.     {
  146.         onScreen = false,
  147.         xPos = 0
  148.     }
  149.     moneybagEleven =
  150.     {
  151.         onScreen = false,
  152.         xPos = 0
  153.     }
  154.     moneybagTwelve =
  155.     {
  156.         onScreen = false,
  157.         xPos = 0
  158.     }
  159.     moneybagThirteen =
  160.     {
  161.         onScreen = false,
  162.         xPos = 0
  163.     }
  164.     moneybagFourteen =
  165.     {
  166.         onScreen = false,
  167.         xPos = 0
  168.     }
  169.     moneybagFifteen =
  170.     {
  171.         onScreen = false,
  172.         xPos = 0
  173.     }
  174.     moneybagSixteen =
  175.     {
  176.         onScreen = false,
  177.         xPos = 0
  178.     }
  179.  
  180.     playerMove = false
  181.     tickCount = 0
  182.     -- End of Variable Definitions
  183.    
  184.    
  185.     -- Tick Loop
  186.     repeat
  187.         if playerMove == true then
  188.             if currentKey == "up" and playerPos > 1 then
  189.                 playerPos = playerPos - 1
  190.                 currentKey = false
  191.             elseif currentKey == "down" and playerPos < 17 then
  192.                 playerPos = playerPos + 1
  193.                 currentKey = false
  194.             end
  195.             playerMove = false
  196.         else
  197.             playerMove = true
  198.         end
  199.         if payday == 120 then
  200.             money = money + 300
  201.             payday = 0
  202.         else
  203.             payday = payday + 1
  204.         end
  205.         if moneybagTimer == 3 and money >= 10 then
  206.             moneybagTimer = 0
  207.             money = money - 10
  208.             if moneybagOne.onScreen == false then
  209.                 moneybagOne.onScreen = true
  210.                 moneybagOne.yPos = math.random(1, 17)
  211.             elseif moneybagTwo.onScreen == false then
  212.                 moneybagTwo.onScreen = true
  213.                 moneybagTwo.yPos = math.random(1, 17)
  214.             elseif moneybagThree.onScreen == false then
  215.                 moneybagThree.onScreen = true
  216.                 moneybagThree.yPos = math.random(1, 17)
  217.             elseif moneybagFour.onScreen == false then
  218.                 moneybagFour.onScreen = true
  219.                 moneybagFour.yPos = math.random(1, 17)
  220.             elseif moneybagFive.onScreen == false then
  221.                 moneybagFive.onScreen = true
  222.                 moneybagFive.yPos = math.random(1, 17)
  223.             elseif moneybagSix.onScreen == false then
  224.                 moneybagSix.onScreen = true
  225.                 moneybagSix.yPos = math.random(1, 17)
  226.             elseif moneybagSeven.onScreen == false then
  227.                 moneybagSeven.onScreen = true
  228.                 moneybagSeven.yPos = math.random(1, 17)
  229.             elseif moneybagEight.onScreen == false then
  230.                 moneybagEight.onScreen = true
  231.                 moneybagEight.yPos = math.random(1, 17)
  232.             elseif moneybagNine.onScreen == false then
  233.                 moneybagNine.onScreen = true
  234.                 moneybagNine.yPos = math.random(1, 17)
  235.             elseif moneybagTen.onScreen == false then
  236.                 moneybagTen.onScreen = true
  237.                 moneybagTen.yPos = math.random(1, 17)
  238.             elseif moneybagEleven.onScreen == false then
  239.                 moneybagEleven.onScreen = true
  240.                 moneybagEleven.yPos = math.random(1, 17)
  241.             elseif moneybagTwelve.onScreen == false then
  242.                 moneybagTwelve.onScreen = true
  243.                 moneybagTwelve.yPos = math.random(1, 17)
  244.             elseif moneybagThirteen.onScreen == false then
  245.                 moneybagThirteen.onScreen = true
  246.                 moneybagThirteen.yPos = math.random(1, 17)
  247.             elseif moneybagFourteen.onScreen == false then
  248.                 moneybagFourteen.onScreen = true
  249.                 moneybagFourteen.yPos = math.random(1, 17)
  250.             elseif moneybagFifteen.onScreen == false then
  251.                 moneybagFifteen.onScreen = true
  252.                 moneybagFifteen.yPos = math.random(1, 17)
  253.             elseif moneybagSixteen.onScreen == false then
  254.                 moneybagSixteen.onScreen = true
  255.                 moneybagSixteen.yPos = math.random(1, 17)
  256.             end
  257.         elseif money >= 10 then
  258.             moneybagTimer = moneybagTimer + 1
  259.         end
  260.         if moneybagOne.onScreen == true then
  261.             if moneybagOne.xPos == 48 then
  262.                 moneybagOne.onScreen = false
  263.                 moneybagOne.xPos = 0
  264.                 score = score + 1
  265.             else
  266.                 moneybagOne.xPos = moneybagOne.xPos + 1
  267.             end
  268.         end
  269.         if moneybagTwo.onScreen == true then
  270.             if moneybagTwo.xPos == 48 then
  271.                 moneybagTwo.onScreen = false
  272.                 moneybagTwo.xPos = 0
  273.                 score = score + 1
  274.             else
  275.                 moneybagTwo.xPos = moneybagTwo.xPos + 1
  276.             end
  277.         end
  278.         if moneybagThree.onScreen == true then
  279.             if moneybagThree.xPos == 48 then
  280.                 moneybagThree.onScreen = false
  281.                 moneybagThree.xPos = 0
  282.                 score = score + 1
  283.             else
  284.                 moneybagThree.xPos = moneybagThree.xPos + 1
  285.             end
  286.         end
  287.         if moneybagFour.onScreen == true then
  288.             if moneybagFour.xPos == 48 then
  289.                 moneybagFour.onScreen = false
  290.                 moneybagFour.xPos = 0
  291.                 score = score + 1
  292.             else
  293.                 moneybagFour.xPos = moneybagFour.xPos + 1
  294.             end
  295.         end
  296.         if moneybagFive.onScreen == true then
  297.             if moneybagFive.xPos == 48 then
  298.                 moneybagFive.onScreen = false
  299.                 moneybagFive.xPos = 0
  300.                 score = score + 1
  301.             else
  302.                 moneybagFive.xPos = moneybagFive.xPos + 1
  303.             end
  304.         end
  305.         if moneybagSix.onScreen == true then
  306.             if moneybagSix.xPos == 48 then
  307.                 moneybagSix.onScreen = false
  308.                 moneybagSix.xPos = 0
  309.                 score = score + 1
  310.             else
  311.                 moneybagSix.xPos = moneybagSix.xPos + 1
  312.             end
  313.         end
  314.         if moneybagSeven.onScreen == true then
  315.             if moneybagSeven.xPos == 48 then
  316.                 moneybagSeven.onScreen = false
  317.                 moneybagSeven.xPos = 0
  318.                 score = score + 1
  319.             else
  320.                 moneybagSeven.xPos = moneybagSeven.xPos + 1
  321.             end
  322.         end
  323.         if moneybagEight.onScreen == true then
  324.             if moneybagEight.xPos == 48 then
  325.                 moneybagEight.onScreen = false
  326.                 moneybagEight.xPos = 0
  327.                 score = score + 1
  328.             else
  329.                 moneybagEight.xPos = moneybagEight.xPos + 1
  330.             end
  331.         end
  332.         if moneybagNine.onScreen == true then
  333.             if moneybagNine.xPos == 48 then
  334.                 moneybagNine.onScreen = false
  335.                 moneybagNine.xPos = 0
  336.                 score = score + 1
  337.             else
  338.                 moneybagNine.xPos = moneybagNine.xPos + 1
  339.             end
  340.         end
  341.         if moneybagTen.onScreen == true then
  342.             if moneybagTen.xPos == 48 then
  343.                 moneybagTen.onScreen = false
  344.                 moneybagTen.xPos = 0
  345.                 score = score + 1
  346.             else
  347.                 moneybagTen.xPos = moneybagTen.xPos + 1
  348.             end
  349.         end
  350.         if moneybagEleven.onScreen == true then
  351.             if moneybagEleven.xPos == 48 then
  352.                 moneybagEleven.onScreen = false
  353.                 moneybagEleven.xPos = 0
  354.                 score = score + 1
  355.             else
  356.                 moneybagEleven.xPos = moneybagEleven.xPos + 1
  357.             end
  358.         end
  359.         if moneybagTwelve.onScreen == true then
  360.             if moneybagTwelve.xPos == 48 then
  361.                 moneybagTwelve.onScreen = false
  362.                 moneybagTwelve.xPos = 0
  363.                 score = score + 1
  364.             else
  365.                 moneybagTwelve.xPos = moneybagTwelve.xPos + 1
  366.             end
  367.         end
  368.         if moneybagThirteen.onScreen == true then
  369.             if moneybagThirteen.xPos == 48 then
  370.                 moneybagThirteen.onScreen = false
  371.                 moneybagThirteen.xPos = 0
  372.                 score = score + 1
  373.             else
  374.                 moneybagThirteen.xPos = moneybagThirteen.xPos + 1
  375.             end
  376.         end
  377.         if moneybagFourteen.onScreen == true then
  378.             if moneybagFourteen.xPos == 48 then
  379.                 moneybagFourteen.onScreen = false
  380.                 moneybagFourteen.xPos = 0
  381.                 score = score + 1
  382.             else
  383.                 moneybagFourteen.xPos = moneybagFourteen.xPos + 1
  384.             end
  385.         end
  386.         if moneybagFifteen.onScreen == true then
  387.             if moneybagFifteen.xPos == 48 then
  388.                 moneybagFifteen.onScreen = false
  389.                 moneybagFifteen.xPos = 0
  390.                 score = score + 1
  391.             else
  392.                 moneybagFifteen.xPos = moneybagFifteen.xPos + 1
  393.             end
  394.         end
  395.         if moneybagSixteen.onScreen == true then
  396.             if moneybagSixteen.xPos == 48 then
  397.                 moneybagSixteen.onScreen = false
  398.                 moneybagSixteen.xPos = 0
  399.                 score = score + 1
  400.             else
  401.                 moneybagSixteen.xPos = moneybagSixteen.xPos + 1
  402.             end
  403.         end
  404.         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))) or (((moneybagNine.yPos == playerPos and moneybagNine.xPos == 47) or (moneybagTen.yPos == playerPos and moneybagTen.xPos == 47)) or ((moneybagEleven.yPos == playerPos and moneybagEleven.xPos == 47) or (moneybagTwelve.yPos == playerPos and moneybagTwelve.xPos == 47)) or ((moneybagThirteen.yPos == playerPos and moneybagThirteen.xPos == 47) or (moneybagFourteen.yPos == playerPos and moneybagFourteen.xPos == 47)) or ((moneybagFifteen.yPos == playerPos and moneybagFifteen.xPos == 47) or (moneybagSixteen.yPos == playerPos and moneybagSixteen.xPos == 47)))) then
  405.             lives = lives - 1
  406.         elseif score - prevLifeScore == 500 then
  407.             prevLifeScore = prevLifeScore + 500
  408.             lives = lives + 1
  409.         end
  410.         if lives == 0 then
  411.             lose = true
  412.         end
  413.         if currentKey == "enter" then
  414.             singlePlayerMenu()
  415.             currentKey = true
  416.         end
  417.         tickCount = tickCount + 1
  418.         refreshSinglePlayerGraphics()
  419.         sleep(tickSpeed)
  420.     until lose or gameExit
  421.     -- End of Tick Loop
  422. end
  423.  
  424. function singlePlayerMenu()
  425.     term.clear()
  426.     term.setCursorPos(1, 1)
  427.     print("Ticks: "..tickCount.."  Score: "..score.."  Money: $"..money.."  Lives: "..lives)
  428.     term.setCursorPos(1, 4)
  429.     print("     ---------------------------------------     ")
  430.     print("     |           Game is paused.           |     ")
  431.     print("     ---------------------------------------     ")
  432.     print("     |                                     |     ")
  433.     SPmenuPos = 1
  434.     while true do
  435.         term.setCursorPos(1, 8)
  436.         if SPmenuPos == 1 then
  437.             print("     |          > Back to Game <           |     ")
  438.         else
  439.             print("     |            Back to Game             |     ")
  440.         end
  441.         print("     |                                     |     ")
  442.         if SPmenuPos == 2 then
  443.             print("     |        > Exit to Main Menu <        |     ")
  444.         else
  445.             print("     |          Exit to Main Menu          |     ")
  446.         end
  447.         print("     |                                     |     ")
  448.         print("     ---------------------------------------     ")
  449.        
  450.         event, key = os.pullEvent("key")
  451.         if key == 17 or key == 200 then
  452.             SPmenuPos = 1
  453.         elseif key == 31 or key == 208 then
  454.             SPmenuPos = 2
  455.         elseif key == 28 and SPmenuPos == 1 then
  456.             break
  457.         elseif key == 28 and SPmenuPos == 2 then
  458.             gameExit = true
  459.             break
  460.         end
  461.     end
  462. end
  463.  
  464. function keyListener()
  465.     while true do
  466.         event, key = os.pullEvent("key")
  467.         if currentKey ~= true then
  468.             if key == 17 or key == 200 then
  469.                 currentKey = "up"
  470.             elseif key == 31 or key == 208 then
  471.                 currentKey = "down"
  472.             elseif key == 28 then
  473.                 currentKey = "enter"
  474.             end
  475.         else
  476.         currentKey = false
  477.         end
  478.     end
  479. end
  480.  
  481. function refreshSinglePlayerGraphics()
  482.     term.clear()
  483.     term.setCursorPos(1, 1)
  484.     print("Ticks: "..tickCount.."  Score: "..score.."  Money: $"..money.."  Lives: "..lives)
  485.     term.setCursorPos(48, playerPos + 1)
  486.     print("X")
  487.     if moneybagOne.onScreen == true then
  488.         term.setCursorPos(moneybagOne.xPos, moneybagOne.yPos + 1)
  489.         print(">$")
  490.     end
  491.     if moneybagTwo.onScreen == true then
  492.         term.setCursorPos(moneybagTwo.xPos, moneybagTwo.yPos + 1)
  493.         print(">$")
  494.     end
  495.     if moneybagThree.onScreen == true then
  496.         term.setCursorPos(moneybagThree.xPos, moneybagThree.yPos + 1)
  497.         print(">$")
  498.     end
  499.     if moneybagFour.onScreen == true then
  500.         term.setCursorPos(moneybagFour.xPos, moneybagFour.yPos + 1)
  501.         print(">$")
  502.     end
  503.     if moneybagFive.onScreen == true then
  504.         term.setCursorPos(moneybagFive.xPos, moneybagFive.yPos + 1)
  505.         print(">$")
  506.     end
  507.     if moneybagSix.onScreen == true then
  508.         term.setCursorPos(moneybagSix.xPos, moneybagSix.yPos + 1)
  509.         print(">$")
  510.     end
  511.     if moneybagSeven.onScreen == true then
  512.         term.setCursorPos(moneybagSeven.xPos, moneybagSeven.yPos + 1)
  513.         print(">$")
  514.     end
  515.     if moneybagEight.onScreen == true then
  516.         term.setCursorPos(moneybagEight.xPos, moneybagEight.yPos + 1)
  517.         print(">$")
  518.     end
  519.     if moneybagNine.onScreen == true then
  520.         term.setCursorPos(moneybagNine.xPos, moneybagNine.yPos + 1)
  521.         print(">$")
  522.     end
  523.     if moneybagTen.onScreen == true then
  524.         term.setCursorPos(moneybagTen.xPos, moneybagTen.yPos + 1)
  525.         print(">$")
  526.     end
  527.     if moneybagEleven.onScreen == true then
  528.         term.setCursorPos(moneybagEleven.xPos, moneybagEleven.yPos + 1)
  529.         print(">$")
  530.     end
  531.     if moneybagTwelve.onScreen == true then
  532.         term.setCursorPos(moneybagTwelve.xPos, moneybagTwelve.yPos + 1)
  533.         print(">$")
  534.     end
  535.     if moneybagThirteen.onScreen == true then
  536.         term.setCursorPos(moneybagThirteen.xPos, moneybagThirteen.yPos + 1)
  537.         print(">$")
  538.     end
  539.     if moneybagFourteen.onScreen == true then
  540.         term.setCursorPos(moneybagFourteen.xPos, moneybagFourteen.yPos + 1)
  541.         print(">$")
  542.     end
  543.     if moneybagFifteen.onScreen == true then
  544.         term.setCursorPos(moneybagFifteen.xPos, moneybagFifteen.yPos + 1)
  545.         print(">$")
  546.     end
  547.     if moneybagSixteen.onScreen == true then
  548.         term.setCursorPos(moneybagSixteen.xPos, moneybagSixteen.yPos + 1)
  549.         print(">$")
  550.     end
  551. end
  552.  
  553. function multiPlayer()
  554.  
  555. end
  556.  
  557. function packetListener()
  558.     while true do
  559.         id, message = rednet.receive()
  560.         if id == opcompid then
  561.             packet = message
  562.         end
  563.     end
  564. end
  565.  
  566.  
  567.  
  568. titleScreen()
Add Comment
Please, Sign In to add comment