Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Clicker
- Just Does Games
- --]]
- local w,h = term.getSize()
- if not term.isColor() then error("Advanced Computer Required") end
- local run, inmenu, debug = true, false, false -- debug erases any save data
- function createClickable()
- if #clicks ~= sv.clicker.game.maxClicks then
- table.insert(clicks, {math.random(1,w), math.random(2,h-1)}) -- Exclude the top and bottom for menu reasons
- end
- end
- function checkClick(x,y)
- for i=1, #clicks do
- if x == clicks[i][1] and y == clicks[i][2] then return {true,i} end
- end
- return false
- end
- function resetClicks()
- clicks = {}
- for i=1, sv.clicker.game.totalClicks do createClickable() end -- reset all clickables just in case
- --error(clicks[1][1].." "..clicks[1][2])
- end
- function display()
- term.setBackgroundColor(sv.clicker.colors.background)
- term.clear() -- usually I do not do this because of the flickering but this is a really small game
- term.setBackgroundColor(sv.clicker.colors.click)
- for i=1, #clicks do
- --error(clicks[i][1].." "..clicks[i][2] )
- term.setCursorPos(clicks[i][1], clicks[i][2])
- write(" ")
- end
- term.setTextColor(sv.clicker.colors.moneyText)
- term.setBackgroundColor(sv.clicker.colors.background)
- term.setCursorPos(1,1)
- write("Money: "..sv.clicker.player.money)
- term.setTextColor(sv.clicker.colors.clickWorthText)
- term.setCursorPos(w-string.len(sv.clicker.game.clickWorth.."/"..sv.clicker.game.totalClicks),1)
- write(sv.clicker.game.clickWorth.."/"..sv.clicker.game.totalClicks)
- term.setTextColor(sv.clicker.colors.text)
- term.setCursorPos(1,h)
- if not inmenu then
- write("Press 'CTRL' for menu")
- end
- end
- function upgrade(t)
- local cost = upgradeCal()
- if sv.clicker.player.money >= cost then
- sv.clicker.player.money = sv.clicker.player.money - cost
- if t == 1 then
- sv.clicker.game.clickWorth = sv.clicker.game.clickWorth + 1
- elseif t == 2 then
- if sv.clicker.game.totalClicks ~= sv.clicker.game.maxClicks then
- sv.clicker.game.totalClicks = sv.clicker.game.totalClicks + 1
- resetClicks()
- else
- sv.clicker.player.money = sv.clicker.player.money + cost
- end
- elseif t == 3 then
- sv.clicker.game.aClickerWorth = sv.clicker.game.aClickerWorth + 1
- end
- sleep(.1) display()
- end
- end
- function runClicker()
- while true do
- sleep(1)
- sv.clicker.player.money = sv.clicker.player.money + (sv.clicker.game.clickWorth*sv.clicker.game.aClickerWorth)
- end
- end
- function runMenu()
- local sel, r = 1, true
- inmenu = true
- while r do -- use r to leave (to avoid rep clicking)
- local menu = {
- {"Upgrade Worth - $"..upgradeCal(), function() upgrade(1) end},
- {"Upgrade Clicks - $"..upgradeCal(), function() upgrade(2) end},
- {"Upgrade Auto Clicker - $"..upgradeCal(), function() upgrade(3) end},
- {"Save and Exit", function() run, r = false, false end}
- }
- while true do -- use break to leave
- term.setCursorPos(1,h)
- term.clearLine()
- term.setCursorPos(1,h)
- term.setTextColor(sv.clicker.colors.menuText)
- write("< "..menu[sel][1].." >")
- a,b = os.pullEvent()
- if a == "key" then
- if b == keys.leftCtrl or b == keys.rightCtrl or b == keys.q then
- r = false
- elseif b == keys.d or b == keys.right then
- if sel ~= #menu then
- sel = sel + 1
- end
- elseif b == keys.a or b == keys.left then
- if sel ~= 1 then
- sel = sel - 1
- end
- elseif b == keys.enter or b == keys.e then
- menu[sel][2]() break
- end
- elseif a == "mouse_click" then
- r = false
- end
- if not r then break end
- end
- end
- inmenu = false
- end
- function runGame()
- while run do
- display()
- a,b,x,y = os.pullEvent()
- if a == "key" then -- menu things
- if b == keys.q then
- run = false
- elseif b == keys.rightCtrl or b == keys.leftCtrl then
- runMenu()
- end
- elseif a == "mouse_click" or a == "mouse_drag" then -- mouse drag because... ... fuck you
- local tmp = checkClick(x,y)
- if tmp then
- table.remove(clicks, tmp[2])
- createClickable()
- sv.clicker.player.money = sv.clicker.player.money + sv.clicker.game.clickWorth
- end
- end
- end
- end
- local saveDir = "/saves/sv.lua" -- just throwing things around lol
- function save(dir)
- local f = fs.open(dir, "w")
- if f then f.write(textutils.serialize(sv)) f.close() end
- end
- if debug then save(saveDir) end
- function load(dir)
- local f = fs.open(dir, "r")
- if f then sv = textutils.unserialize(f.readAll()) f.close() end
- end
- load(saveDir)
- sv = sv or {}
- sv.clicker = sv.clicker or {}
- sv.clicker.player, sv.clicker.game, sv.clicker.colors = sv.clicker.player or {}, sv.clicker.game or {}, sv.clicker.colors or {}
- sv.clicker.player.money = sv.clicker.player.money or 0
- sv.clicker.game.clickWorth = sv.clicker.game.clickWorth or 1
- --sv.clicker.game.clicks = sv.clicker.game.clicks or {}
- local clicks = {}
- sv.clicker.game.totalClicks = sv.clicker.game.totalClicks or 1
- sv.clicker.game.maxClicks = sv.clicker.game.maxClicks or 60
- sv.clicker.game.upgradeBase = sv.clicker.game.upgradeBase or 6 -- base
- sv.clicker.game.aClickerWorth = sv.clicker.game.aClickerWorth or 0
- function upgradeCal() return math.floor(((sv.clicker.game.clickWorth+sv.clicker.game.totalClicks+sv.clicker.game.aClickerWorth)+(sv.clicker.game.clickWorth*sv.clicker.game.totalClicks*sv.clicker.game.aClickerWorth))*sv.clicker.game.upgradeBase) end
- sv.clicker.colors.background = sv.clicker.colors.background or colors.black
- sv.clicker.colors.text = sv.clicker.colors.text or colors.white
- sv.clicker.colors.moneyText = sv.clicker.colors.moneyText or colors.lime
- sv.clicker.colors.menuText = sv.clicker.colors.menuText or colors.white
- sv.clicker.colors.clickWorthText = sv.clicker.colors.clickWorthText or colors.yellow
- sv.clicker.colors.click = sv.clicker.colors.click or colors.green
- resetClicks()
- parallel.waitForAny(runGame, runClicker)
- save(saveDir)
- term.clear()
- term.setCursorPos(1,1) sleep(.1) -- to avoid other issues sleep for .1
- return true
Advertisement
Add Comment
Please, Sign In to add comment