Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Change absolutely whatever you need to, even if it says you shouldn't
- ------------ General Settings ------------
- ------ Required Internal ------
- -- Changing anything in this section isn't recommended
- local width, height = term.getSize() -- Must be defined before Gem Settings
- ------ Gem Settings ------
- -- The number of gems to have on the screen at all times
- local gemsOnScreen = 10
- -- The minimum x coordinate that a gem can be generated at
- local minX = 13
- -- The minimum y coordinate that a gem can be generated at
- local minY = 4
- -- The maximum x coordinate that a gem can be generated at
- local maxX = 47
- -- The maximum y coordinate that a gem can be generated at
- local maxY = height - 1
- -- List of possible gem colors
- local colorChoices = { colors.purple, colors.yellow, colors.lime, colors.lightBlue }
- -- Define the gem worth value (money received when clicked)
- local gemValue = { }
- gemValue[colors.purple] = 10 -- Get 10 money when you click a purple gem
- gemValue[colors.yellow] = 5 -- Get 5 money when you click a pink gem
- gemValue[colors.lime] = 15 -- Get 15 money when you click a lime gem
- gemValue[colors.lightBlue] = 20 -- Get 20 money when you click a blue gem
- ------ Screen Settings ------
- -- Background color
- local bgColor = colors.black
- -- Text color
- local txtColor = colors.white
- ------------ Internals ------------
- ------ User Data ------
- local money = 0
- local gemsClicked = 0
- local multi = 1
- local multiCost = 100 -- add new variable for multiCost
- ------ Gem Data ------
- -- Table that stores the pixel data (coordinates and color)
- local gems = { }
- ------------ Functions ------------
- function frame()
- bg = paintutils.loadImage("/.game1")
- paintutils.drawImage(bg, 1,1)
- end
- local function buymultiply() -- make a function out of it so you can use it where you need it
- if money >= multiCost then -- should be > else you only can buy it when you have exactly this amount
- money = money - multiCost
- multiCost = multiCost*2
- multi = multi+1
- stats()
- end
- end
- function newGem()
- local w, h = term.getSize()
- local x, y
- -- Pick a random spot for the pixel to appear
- while true do
- x = math.random(minX, maxX) -- Random number for the x coordinate
- y = math.random(minY, maxY) -- Random number for the y coordinate
- if #gems > 0 then
- local good = true
- for i, v in ipairs(gems) do
- -- Check to see if a gem already exists in that position
- if v[1] == x and v[2] == y then good = false end
- end
- if good then break end
- else
- break
- end
- end
- -- Now, we choose a random color for the pixel (maybe you don't need this)
- local color = colorChoices[math.random(1, #colorChoices)]
- -- This holds the coordinates and the color of the gem
- local gem = {x, y, color}
- table.insert(gems, gem) -- Adds the gem data to the main table
- -- Draw the gem
- term.setCursorPos(x, y)
- term.setBackgroundColor(color)
- write(" ")
- term.setBackgroundColor(bgColor)
- end
- function spawnGems(n)
- for i = 1, n do
- newGem()
- end
- end
- local function mpupgrade()
- local buytext = "Add Multiplier:"
- local mclen = tostring(multiCost) --how many chars has multiply cost at the moment
- local stringlen = #buytext+#mclen
- local mpp = width - stringlen -- substract lenght of buytext + and cost and all charachters after cost from width to put the button to the right side
- if money >= multiCost then
- term.setCursorPos(mpp, 1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write (buytext ..multiCost)
- end
- term.setBackgroundColor(bgColor)
- return mpp, mpp+stringlen-1
- end
- local function checkmultiplier(pos)
- if money < multiCost then
- term.setBackgroundColor(bgColor)
- term.setCursorPos(pos, 1)
- term.clearLine()
- stats()
- end
- end
- function stats()
- frame()
- term.setCursorPos(1,1)
- -- You don't need term.setCursorPos(1, 2) since print automatically moves a line down each time
- print("Money: "..money)
- print("Gems: "..gemsClicked)
- print("Multiplier:")
- print(multi.."x")
- end
- ------------ Running Code ------------
- -- Don't use a number for the color unless absolutely nessecary...and I have no idea when it would be
- -- Use the colors API. 16384 is the same as saying colors.red
- term.setBackgroundColor(bgColor)
- term.setTextColor(txtColor)
- term.clear()
- spawnGems(gemsOnScreen)
- msp, mep = mpupgrade()
- stats()
- while true do
- local e, p1, p2, p3 = os.pullEvent("mouse_click")
- term.setCursorPos(1, 1)
- -- Check if the coordinates clicked are any of the pixel's coordinates
- if p1 == 1 and p2 >= msp and p2 <= mep and p3 == 1 then -- im not sure about this but i this this should work cause needs to be checked after click and has to be outside the loop for getting gemcoords
- buymultiply()
- msp, mep = mpupgrade()
- checkmultiplier(msp)
- end
- for i, v in ipairs(gems) do
- if p1 == 1 and v[1] == p2 and v[2] == p3 then -- A gem was LEFT clicked
- -- Do stuff here
- -- Do more stuff
- -- Increment variables
- gemsClicked = gemsClicked + 1
- -- Give money
- money = money + (gemValue[v[3]] * multi) -- Gem value multiplied by the multiplier
- -- Remove the gem
- term.setBackgroundColor(bgColor)
- term.setCursorPos(v[1], v[2])
- write(" ")
- table.remove(gems, i)
- -- Spawn a new gem
- newGem()
- -- Update stats
- msp, mep = mpupgrade()
- stats()
- end
- end
- sleep(0.05)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement