Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables --
- debug = "Debug"
- w, h = term.getSize()
- -- Values --
- limeName = "Lime gem: "
- limeSell = 10
- lblueName = "Light blue gem: "
- lblueSell = 15
- yellowName = "Yellow gem: "
- yellowSell = 50
- orangeName = "Orange gem: "
- orangeSell = 100
- -- Stats --
- money = 0
- playerName = "nil"
- limeGems = 0
- lblueGems = 0
- yellowGems = 0
- orangeGems = 0
- multi = 1
- multiCost = 1000
- -- End Stats --
- -- End Variables --
- -- Game --
- function playGame()
- slc = 1
- -- Variables --
- minX = 13
- maxX = w-1
- minY = 2
- maxY = h-1
- maxGem = 20
- spawnedGems = 0
- bgColor = colors.black
- local gems = { }
- function spawnGem()
- if spawnedGems >= maxGem then
- gemClick()
- else
- sleep(0.05)
- paintutils.drawPixel(newX, newY, color)
- spawnedGems = spawnedGems + 1
- sleep(0.05)
- local Gem = {newX, newY, color}
- table.insert(gems, Gem)
- gem()
- end
- end
- function gem()
- while true do
- newX = math.random(minX, maxX)
- newY = math.random(minY, maxY)
- colorNum = math.random(1,4)
- if colorNum == 1 then
- color = colors.orange
- sleep(0.1)
- spawnGem()
- elseif colorNum == 2 then
- color = colors.yellow
- sleep(0.1)
- spawnGem()
- elseif colorNum == 3 then
- color = colors.lime
- sleep(0.1)
- spawnGem()
- elseif colorNum == 4 then
- color = colors.lightBlue
- sleep(0.1)
- spawnGem()
- end
- end
- end
- function gemClick()
- slc = 1
- while true do
- local e, p1, p2, p3 = os.pullEvent("mouse_click")
- if slc == 1 then
- for i, v in ipairs(gems) do
- if p1 == 1 and v[1] == p2 and v[2] == p3 then -- A gem was LEFT clicked
- -- Remove the gem
- term.setBackgroundColor(bgColor)
- term.setCursorPos(v[1], v[2])
- write(" ")
- table.remove(gems, i)
- spawnedGems = spawnedGems - 1
- if v[3] == colors.orange then
- orangeGems = orangeGems + (1*multi)
- elseif v[3] == colors.yellow then
- yellowGems = yellowGems + (1*multi)
- elseif v[3] == colors.lime then
- limeGems = limeGems + (1*multi)
- elseif v[3] == colors.lightBlue then
- lblueGems = lblueGems +(1*multi)
- end
- -- Spawn a new gem
- gem()
- elseif p1 == 1 and p2 >= 5 and p2 <= 10 and p3 == h-4 then
- frame2()
- end
- end
- sleep(0.05)
- end
- end
- end
- local function frame()
- term.clear()
- term.setBackgroundColor(colors.black)
- term.clear()
- paintutils.drawLine(12, 1, 12, h, colors.red)
- paintutils.drawLine(12, 1, w, 1, colors.red)
- paintutils.drawLine(12, h, w, h, colors.red)
- paintutils.drawLine(w, 1, w, h, colors.red)
- paintutils.drawLine(1, 1, 1, h, colors.red)
- paintutils.drawLine(1, 1, 1, h, colors.red)
- paintutils.drawLine(2, 1, 2, h, colors.red)
- paintutils.drawLine(3, 1, 3, h, colors.red)
- paintutils.drawLine(4, 1, 4, h, colors.red)
- paintutils.drawLine(5, 1, 5, h, colors.red)
- paintutils.drawLine(6, 1, 6, h, colors.red)
- paintutils.drawLine(7, 1, 7, h, colors.red)
- paintutils.drawLine(8, 1, 8, h, colors.red)
- paintutils.drawLine(9, 1, 9, h, colors.red)
- paintutils.drawLine(10, 1, 10, h, colors.red)
- paintutils.drawLine(11, 1, 11, h, colors.red)
- term.setBackgroundColor(colors.lime)
- term.setTextColor(colors.black)
- term.setCursorPos(1, 2)
- print("Multiplier:")
- term.setCursorPos(1,4)
- print(multi)
- term.setCursorPos(5, h-4)
- print(" Exit ")
- end
- frame()
- gem()
- end
- function sellGems()
- term.setBackgroundColor(1)
- term.clear()
- paintutils.drawPixel(1, 4, 32)
- paintutils.drawPixel(1, 6, 8)
- paintutils.drawPixel(1, 8, 16)
- paintutils.drawPixel(1, 10, 2)
- term.setBackgroundColor(1)
- term.setCursorPos(1, 2)
- print("Money: "..money)
- term.setCursorPos(3, 4)
- print(limeName ..limeGems)
- term.setCursorPos(3, 6)
- print(lblueName ..lblueGems)
- term.setCursorPos(3, 8)
- print(yellowName ..yellowGems)
- term.setCursorPos(3, 10)
- print(orangeName ..orangeGems)
- term.setCursorPos(3, 12)
- print("Back")
- term.setCursorPos(w-25, 5)
- print("Upgrades Cost")
- term.setCursorPos(w-25, 7)
- print("+1 Multiplier "..multiCost)
- while true do
- event, but, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" then
- if but == 1 and x >= 3 and x <= 13 and y == 4 then
- money = limeGems*limeSell + money
- limeGems = 0
- sellGems()
- elseif but == 1 and x >= 3 and x <= 18 and y == 6 then
- money = lblueGems*lblueSell+money
- lblueGems = 0
- sellGems()
- elseif but == 1 and x >= 3 and x <= 14 and y == 8 then
- money = yellowGems*yellowSell+money
- yellowGems = 0
- sellGems()
- elseif but == 1 and x >= 3 and x <= 14 and y == 10 then
- money = orangeGems*orangeSell+money
- orangeGems = 0
- sellGems()
- elseif but == 1 and x >= 3 and x <= (w-25)+14 and y == 7 then
- if money >= multiCost then
- money = money-multiCost
- multi = multi+1
- multiCost = multiCost*2
- sellGems()
- end
- elseif but == 1 and x >= 3 and x <= 7 and y == 12 then
- frame2()
- end
- end
- end
- end
- function frame2()
- slc = 0
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setCursorPos(math.floor(w-string.len("Logged in as: "..playerName))/2, 2)
- print("Logged in as: "..playerName )
- paintutils.drawPixel(1, 4, 32)
- paintutils.drawPixel(1, 6, 8)
- paintutils.drawPixel(1, 8, 16)
- paintutils.drawPixel(1, 10, 2)
- term.setBackgroundColor(1)
- term.setCursorPos(3, 4)
- print(limeName ..limeGems)
- term.setCursorPos(3, 6)
- print(lblueName ..lblueGems)
- term.setCursorPos(3, 8)
- print(yellowName ..yellowGems)
- term.setCursorPos(3, 10)
- print(orangeName ..orangeGems)
- term.setBackgroundColor(32)
- term.setCursorPos(10, 15)
- print("Play")
- term.setCursorPos(20, 15)
- print("Sell Gems")
- while true do
- event, button, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" then
- if slc == 0 then
- if x >= 10 and x <= 15 and y == 15 and button == 1 then
- term.clear()
- playGame()
- break
- elseif x >= 20 and x <= 30 and y == 15 and button == 1 then
- sellGems()
- end
- elseif slc == 1 then
- if x >= 5 and x <= 10 and y == h-4 and button == 1 then
- slc = 0
- frame2()
- end
- end
- end
- end
- end
- function game()
- term.clear()
- term.setBackgroundColor(1)
- term.setTextColor(32768)
- term.clear()
- term.setCursorPos(math.floor(w-string.len("Name: "))/2, 2)
- write("Name: ")
- playerName = read()
- if playerName == "" then
- game()
- else
- frame2()
- end
- end
- -- End Functions --
- game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement