Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- PROGRAM CONFIGURATION:
- tickSpeed = 0.05 -- How fast the game goes. Higher the slower. 0.05 is the recommended speed.
- 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.
- -- END OF CONFIGURATION
- version = "a1.4.1"
- function titleScreen()
- term.clear()
- term.setCursorPos(1, 1)
- print("")
- print(" $$$ Moneybags $$$ ")
- print(" Alpha 1.4.1 ")
- print("")
- print("")
- menuPos = 1
- while true do
- term.setCursorPos(1, 6)
- if menuPos == 1 then
- print(" > Single Player < ")
- else
- print(" Single Player ")
- end
- print("")
- if menuPos == 2 then
- print(" > Multiplayer < ")
- else
- print(" Multiplayer ")
- end
- print("")
- if menuPos == 3 then
- print(" > Quit Game < ")
- else
- print(" Quit Game ")
- end
- event, key = os.pullEvent("key")
- if (key == 17 or key == 200) and (menuPos >= 2) then
- menuPos = menuPos - 1
- elseif (key == 31 or key == 208) and (menuPos <= 2) then
- menuPos = menuPos + 1
- elseif key == 28 and menuPos == 1 then
- parallel.waitForAny(singlePlayer, keyListener)
- if lose then
- term.setCursorPos(1, 5)
- print(" ----------------------------- ")
- print(" | You Lose! | ")
- print(" ----------------------------- ")
- print(" | $$ Game Data $$ | ")
- print(" |---------------------------| ")
- print(" | Score: "..score)
- term.setCursorPos(39, 10)
- print("|")
- print(" | Ticks: "..tickCount)
- term.setCursorPos(39, 11)
- print("|")
- print(" ----------------------------- ")
- sleep(1)
- print(" | Press any key to continue | ")
- print(" | to the Main Menu. | ")
- print(" ----------------------------- ")
- os.pullEvent("key")
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("")
- print(" $$$ Moneybags $$$ ")
- print(" Alpha 1.4.1 ")
- print("")
- print("")
- elseif key == 28 and menuPos == 2 then
- parallel.waitForAny(multiPlayer, keyListener, packetListener)
- elseif key == 28 and menuPos == 3 then
- term.clear()
- term.setCursorPos(1, 1)
- break
- end
- term.setCursorPos(1, 6)
- term.clearLine()
- term.clearLine()
- term.clearLine()
- end
- end
- function singlePlayer()
- -- Variable Definitions
- money = 300
- payday = 0
- playerPos = 8
- score = 0
- prevLifeScore = 0
- lives = 3
- lose = false
- gameExit = false
- moneybagTimer = 0
- moneybag =
- {
- [1] =
- {
- onScreen = false,
- xPos = 0
- },
- [2] =
- {
- onScreen = false,
- xPos = 0
- },
- [3] =
- {
- onScreen = false,
- xPos = 0
- },
- [4] =
- {
- onScreen = false,
- xPos = 0
- },
- [5] =
- {
- onScreen = false,
- xPos = 0
- },
- [6] =
- {
- onScreen = false,
- xPos = 0
- },
- [7] =
- {
- onScreen = false,
- xPos = 0
- },
- [8] =
- {
- onScreen = false,
- xPos = 0
- },
- [9] =
- {
- onScreen = false,
- xPos = 0
- },
- [10] =
- {
- onScreen = false,
- xPos = 0
- },
- [11] =
- {
- onScreen = false,
- xPos = 0
- },
- [12] =
- {
- onScreen = false,
- xPos = 0
- },
- [13] =
- {
- onScreen = false,
- xPos = 0
- },
- [14] =
- {
- onScreen = false,
- xPos = 0
- },
- [15] =
- {
- onScreen = false,
- xPos = 0
- },
- [16] =
- {
- onScreen = false,
- xPos = 0
- }
- }
- playerMove = false
- tickCount = 0
- -- End of Variable Definitions
- -- Tick Loop
- repeat
- if playerMove == true then
- if currentKey == "up" and playerPos > 1 then
- playerPos = playerPos - 1
- currentKey = false
- elseif currentKey == "down" and playerPos < 17 then
- playerPos = playerPos + 1
- currentKey = false
- end
- playerMove = false
- else
- playerMove = true
- end
- if payday == 120 then
- money = money + 300
- payday = 0
- else
- payday = payday + 1
- end
- if moneybagTimer == 3 and money >= 10 then
- moneybagTimer = 0
- money = money - 10
- i = 0
- repeat
- i = i + 1
- if moneybag[i].onScreen == false then
- moneybag[i].onScreen = true
- moneybag[i].yPos = math.random(1, 17)
- moneybagDeployed = true
- end
- until moneybagDeployed
- moneybagDeployed = false
- elseif money >= 10 then
- moneybagTimer = moneybagTimer + 1
- end
- for i = 1, 16 do
- if moneybag[i].onScreen then
- if moneybag[i].xPos == 48 then
- moneybag[i].onScreen = false
- moneybag[i].xPos = 0
- score = score + 1
- else
- moneybag[i].xPos = moneybag[i].xPos + 1
- end
- end
- end
- for i = 1, 16 do
- if moneybag[i].yPos == playerPos and moneybag[i].xPos == 47 then
- lives = lives - 1
- end
- end
- if score - prevLifeScore == 500 then
- prevLifeScore = prevLifeScore + 500
- lives = lives + 1
- end
- if lives == 0 then
- lose = true
- end
- if currentKey == "enter" then
- singlePlayerMenu()
- currentKey = true
- end
- tickCount = tickCount + 1
- refreshSinglePlayerGraphics()
- sleep(tickSpeed)
- until lose or gameExit
- -- End of Tick Loop
- end
- function singlePlayerMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("Ticks: "..tickCount.." Score: "..score.." Money: $"..money.." Lives: "..lives)
- term.setCursorPos(1, 4)
- print(" --------------------------------------- ")
- print(" | Game is paused. | ")
- print(" --------------------------------------- ")
- print(" | | ")
- SPmenuPos = 1
- while true do
- term.setCursorPos(1, 8)
- if SPmenuPos == 1 then
- print(" | > Back to Game < | ")
- else
- print(" | Back to Game | ")
- end
- print(" | | ")
- if SPmenuPos == 2 then
- print(" | > Exit to Main Menu < | ")
- else
- print(" | Exit to Main Menu | ")
- end
- print(" | | ")
- print(" --------------------------------------- ")
- event, key = os.pullEvent("key")
- if key == 17 or key == 200 then
- SPmenuPos = 1
- elseif key == 31 or key == 208 then
- SPmenuPos = 2
- elseif key == 28 and SPmenuPos == 1 then
- break
- elseif key == 28 and SPmenuPos == 2 then
- gameExit = true
- break
- end
- end
- end
- function keyListener()
- while true do
- event, key = os.pullEvent("key")
- if currentKey ~= true then
- if key == 17 or key == 200 then
- currentKey = "up"
- elseif key == 31 or key == 208 then
- currentKey = "down"
- elseif key == 28 then
- currentKey = "enter"
- end
- else
- currentKey = false
- end
- end
- end
- function refreshSinglePlayerGraphics()
- term.clear()
- term.setCursorPos(1, 1)
- print("Ticks: "..tickCount.." Score: "..score.." Money: $"..money.." Lives: "..lives)
- term.setCursorPos(48, playerPos + 1)
- print("X")
- for i = 1, 16 do
- if moneybag[i].onScreen then
- term.setCursorPos(moneybag[i].xPos, moneybag[i].yPos + 1)
- print(">$")
- end
- end
- end
- function multiPlayer()
- end
- function packetListener()
- while true do
- id, message = rednet.receive()
- if id == opcompid then
- packet = message
- end
- end
- end
- titleScreen()
Add Comment
Please, Sign In to add comment