Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Draw
- Just Does Games
- --]]
- local w,h = term.getSize()
- local run, debug, inmenu = true, false, false
- local saveDir = "/saves/sv.lua" -- just throwing things around lol
- -- Main Code
- function display()
- term.setBackgroundColor(sv.draw.color.background)
- term.clear() -- usually I do not do this because of the flickering but this is a really small game
- term.setBackgroundColor(sv.draw.color.click)
- term.setTextColor(sv.draw.color.moneyText)
- term.setBackgroundColor(sv.draw.color.background)
- term.setCursorPos(1,1)
- write("Money: "..sv.money)
- term.setTextColor(sv.draw.color.clickWorthText)
- term.setCursorPos(w-string.len(sv.draw.game.drawWorth.."/"..sv.draw.game.overlapWorth),1)
- write(sv.draw.game.drawWorth.."/"..sv.draw.game.overlapWorth)
- term.setTextColor(sv.draw.color.text)
- term.setCursorPos(1,h)
- if not inmenu then
- write("Press 'CTRL' for menu")
- end
- end
- function upgrade(t)
- local cost = upgradeCal()
- if sv.money >= cost then
- sv.money = sv.money - cost
- if t == 1 then
- sv.draw.game.drawWorth = sv.draw.game.drawWorth + 1
- elseif t == 2 then
- sv.draw.game.overlapWorth = sv.draw.game.overlapWorth + 1
- end
- sleep(.1) display()
- end
- end
- function runMenu()
- save(saveDir)
- local sel, r = 1, true
- inmenu = true
- while r do -- use r to leave (to avoid rep clicking)
- local menu = {
- {"Upgrade Draw - $"..upgradeCal(), function() upgrade(1) end},
- {"Upgrade Overlap - $"..upgradeCal(), function() upgrade(2) 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.draw.color.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
- paintutils.drawPixel(x,y,sv.draw.color.click)
- local blocks = {}
- for i=1, w*h do
- table.insert(blocks, {i, 0})
- end
- while true do
- local a,_,x,y = os.pullEvent()
- if a == "mouse_drag" then
- if blocks[x*y][2] == 0 then
- paintutils.drawPixel(x,y,sv.draw.color.click)
- blocks[x*y][2] = blocks[x*y][2]+1
- elseif blocks[x*y][2] == 1 then
- paintutils.drawPixel(x,y,sv.draw.color.clickOverlap)
- blocks[x*y][2] = blocks[x*y][2]+1
- end
- elseif a == "mouse_up" then
- break
- end
- end
- local tmp = 0
- for i=1, #blocks do
- tmp = tmp + math.ceil(blocks[i][2]*sv.draw.game.drawWorth)
- if blocks[i][2] == 2 then
- tmp = tmp + math.ceil(blocks[i][2]*sv.draw.game.overlapWorth)
- end
- end
- sv.money = sv.money + math.floor(tmp/200)
- end
- end
- end
- -- Main Code
- 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.money = sv.money or 0
- sv.draw = {}
- sv.draw.player, sv.draw.game, sv.draw.color = sv.draw.player or {}, sv.draw.game or {}, sv.draw.color or {}
- sv.draw.game.upgradeBase = sv.draw.game.upgradeBase or 1
- sv.draw.game.drawWorth = 1 -- one per block
- sv.draw.game.overlapWorth = 1 -- overlapWorth multiplies for every stack...?
- function upgradeCal() return math.floor(((sv.draw.game.drawWorth+sv.draw.game.overlapWorth)+(sv.draw.game.drawWorth*sv.draw.game.overlapWorth))*sv.draw.game.upgradeBase) end
- sv.draw.color.background = sv.draw.color.background or colors.black
- sv.draw.color.text = sv.draw.color.text or colors.white
- sv.draw.color.moneyText = sv.draw.color.moneyText or colors.lime
- sv.draw.color.menuText = sv.draw.color.menuText or colors.white
- sv.draw.color.clickWorthText = sv.draw.color.clickWorthText or colors.orange
- sv.draw.color.click = sv.draw.color.click or colors.white
- sv.draw.color.clickOverlap = sv.draw.color.clickOverlap or colors.yellow
- runGame()
- save(saveDir)
Advertisement
Add Comment
Please, Sign In to add comment