brett122798

Moneybags Alpha 1.4.1

Jun 5th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.67 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.1"
  9.  
  10.  
  11. function titleScreen()
  12.     term.clear()
  13.     term.setCursorPos(1, 1)
  14.     print("")
  15.     print("               $$$  Moneybags  $$$               ")
  16.     print("                   Alpha 1.4.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, 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.1                   ")
  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.    
  100.     moneybag =
  101.     {
  102.         [1] =
  103.         {
  104.             onScreen = false,
  105.             xPos = 0
  106.         },
  107.         [2] =
  108.         {
  109.             onScreen = false,
  110.             xPos = 0
  111.         },
  112.         [3] =
  113.         {
  114.             onScreen = false,
  115.             xPos = 0
  116.         },
  117.         [4] =
  118.         {
  119.             onScreen = false,
  120.             xPos = 0
  121.         },
  122.         [5] =
  123.         {
  124.             onScreen = false,
  125.             xPos = 0
  126.         },
  127.         [6] =
  128.         {
  129.             onScreen = false,
  130.             xPos = 0
  131.         },
  132.         [7] =
  133.         {
  134.             onScreen = false,
  135.             xPos = 0
  136.         },
  137.         [8] =
  138.         {
  139.             onScreen = false,
  140.             xPos = 0
  141.         },
  142.         [9] =
  143.         {
  144.             onScreen = false,
  145.             xPos = 0
  146.         },
  147.         [10] =
  148.         {
  149.             onScreen = false,
  150.             xPos = 0
  151.         },
  152.         [11] =
  153.         {
  154.             onScreen = false,
  155.             xPos = 0
  156.         },
  157.         [12] =
  158.         {
  159.             onScreen = false,
  160.             xPos = 0
  161.         },
  162.         [13] =
  163.         {
  164.             onScreen = false,
  165.             xPos = 0
  166.         },
  167.         [14] =
  168.         {
  169.             onScreen = false,
  170.             xPos = 0
  171.         },
  172.         [15] =
  173.         {
  174.             onScreen = false,
  175.             xPos = 0
  176.         },
  177.         [16] =
  178.         {
  179.             onScreen = false,
  180.             xPos = 0
  181.         }
  182.     }
  183.  
  184.     playerMove = false
  185.     tickCount = 0
  186.     -- End of Variable Definitions
  187.    
  188.    
  189.     -- Tick Loop
  190.     repeat
  191.         if playerMove == true then
  192.             if currentKey == "up" and playerPos > 1 then
  193.                 playerPos = playerPos - 1
  194.                 currentKey = false
  195.             elseif currentKey == "down" and playerPos < 17 then
  196.                 playerPos = playerPos + 1
  197.                 currentKey = false
  198.             end
  199.             playerMove = false
  200.         else
  201.             playerMove = true
  202.         end
  203.         if payday == 120 then
  204.             money = money + 300
  205.             payday = 0
  206.         else
  207.             payday = payday + 1
  208.         end
  209.         if moneybagTimer == 3 and money >= 10 then
  210.             moneybagTimer = 0
  211.             money = money - 10
  212.             i = 0
  213.             repeat
  214.                 i = i + 1
  215.                 if moneybag[i].onScreen == false then
  216.                     moneybag[i].onScreen = true
  217.                     moneybag[i].yPos = math.random(1, 17)
  218.                     moneybagDeployed = true
  219.                 end
  220.             until moneybagDeployed
  221.             moneybagDeployed = false
  222.         elseif money >= 10 then
  223.             moneybagTimer = moneybagTimer + 1
  224.         end
  225.         for i = 1, 16 do
  226.             if moneybag[i].onScreen then
  227.                 if moneybag[i].xPos == 48 then
  228.                     moneybag[i].onScreen = false
  229.                     moneybag[i].xPos = 0
  230.                     score = score + 1
  231.                 else
  232.                     moneybag[i].xPos = moneybag[i].xPos + 1
  233.                 end
  234.             end
  235.         end
  236.         for i = 1, 16 do
  237.             if moneybag[i].yPos == playerPos and moneybag[i].xPos == 47 then
  238.                 lives = lives - 1
  239.             end
  240.         end
  241.         if score - prevLifeScore == 500 then
  242.             prevLifeScore = prevLifeScore + 500
  243.             lives = lives + 1
  244.         end
  245.         if lives == 0 then
  246.             lose = true
  247.         end
  248.         if currentKey == "enter" then
  249.             singlePlayerMenu()
  250.             currentKey = true
  251.         end
  252.         tickCount = tickCount + 1
  253.         refreshSinglePlayerGraphics()
  254.         sleep(tickSpeed)
  255.     until lose or gameExit
  256.     -- End of Tick Loop
  257. end
  258.  
  259. function singlePlayerMenu()
  260.     term.clear()
  261.     term.setCursorPos(1, 1)
  262.     print("Ticks: "..tickCount.."  Score: "..score.."  Money: $"..money.."  Lives: "..lives)
  263.     term.setCursorPos(1, 4)
  264.     print("     ---------------------------------------     ")
  265.     print("     |           Game is paused.           |     ")
  266.     print("     ---------------------------------------     ")
  267.     print("     |                                     |     ")
  268.     SPmenuPos = 1
  269.     while true do
  270.         term.setCursorPos(1, 8)
  271.         if SPmenuPos == 1 then
  272.             print("     |          > Back to Game <           |     ")
  273.         else
  274.             print("     |            Back to Game             |     ")
  275.         end
  276.         print("     |                                     |     ")
  277.         if SPmenuPos == 2 then
  278.             print("     |        > Exit to Main Menu <        |     ")
  279.         else
  280.             print("     |          Exit to Main Menu          |     ")
  281.         end
  282.         print("     |                                     |     ")
  283.         print("     ---------------------------------------     ")
  284.        
  285.         event, key = os.pullEvent("key")
  286.         if key == 17 or key == 200 then
  287.             SPmenuPos = 1
  288.         elseif key == 31 or key == 208 then
  289.             SPmenuPos = 2
  290.         elseif key == 28 and SPmenuPos == 1 then
  291.             break
  292.         elseif key == 28 and SPmenuPos == 2 then
  293.             gameExit = true
  294.             break
  295.         end
  296.     end
  297. end
  298.  
  299. function keyListener()
  300.     while true do
  301.         event, key = os.pullEvent("key")
  302.         if currentKey ~= true then
  303.             if key == 17 or key == 200 then
  304.                 currentKey = "up"
  305.             elseif key == 31 or key == 208 then
  306.                 currentKey = "down"
  307.             elseif key == 28 then
  308.                 currentKey = "enter"
  309.             end
  310.         else
  311.         currentKey = false
  312.         end
  313.     end
  314. end
  315.  
  316. function refreshSinglePlayerGraphics()
  317.     term.clear()
  318.     term.setCursorPos(1, 1)
  319.     print("Ticks: "..tickCount.."  Score: "..score.."  Money: $"..money.."  Lives: "..lives)
  320.     term.setCursorPos(48, playerPos + 1)
  321.     print("X")
  322.     for i = 1, 16 do
  323.         if moneybag[i].onScreen then
  324.             term.setCursorPos(moneybag[i].xPos, moneybag[i].yPos + 1)
  325.         print(">$")
  326.         end
  327.     end
  328. end
  329.  
  330. function multiPlayer()
  331.  
  332. end
  333.  
  334. function packetListener()
  335.     while true do
  336.         id, message = rednet.receive()
  337.         if id == opcompid then
  338.             packet = message
  339.         end
  340.     end
  341. end
  342.  
  343.  
  344.  
  345. titleScreen()
Add Comment
Please, Sign In to add comment