Advertisement
Mackan90096

Untitled

Apr 11th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.83 KB | None | 0 0
  1. -- Change absolutely whatever you need to, even if it says you shouldn't
  2.  
  3. gamebar = paintutils.loadImage("/sprites/bars/.game1")
  4. ------------ General Settings ------------
  5.  
  6. ------ Required Internal ------
  7. -- Changing anything in this section isn't recommended
  8. local width, height = term.getSize() -- Must be defined before Gem Settings
  9.  
  10. ------ Gem Settings ------
  11. -- The number of gems to have on the screen at all times
  12. local gemsOnScreen = 10
  13. -- The minimum x coordinate that a gem can be generated at
  14. local minX = 13
  15. -- The minimum y coordinate that a gem can be generated at
  16. local minY = 4
  17. -- The maximum x coordinate that a gem can be generated at
  18. local maxX = 47
  19. -- The maximum y coordinate that a gem can be generated at
  20. local maxY = height - 1
  21. -- List of possible gem colors
  22. local colorChoices = { colors.purple, colors.yellow, colors.lime, colors.lightBlue }
  23. -- Define the gem worth value (money received when clicked)
  24. local gemValue = { }
  25. gemValue[colors.purple] = 10 -- Get 10 money when you click a purple gem
  26. gemValue[colors.yellow] = 5 -- Get 5 money when you click a pink gem
  27. gemValue[colors.lime] = 15 -- Get 15 money when you click a lime gem
  28. gemValue[colors.lightBlue] = 20 -- Get 20 money when you click a blue gem
  29.  
  30. ------ Screen Settings ------
  31. -- Background color
  32. local bgColor = colors.red
  33. -- Text color
  34. local txtColor = colors.white
  35.  
  36. ------------ Internals ------------
  37.  
  38. ------ User Data ------
  39. local money = 0
  40. local gemsClicked = 0
  41. local multi = 1
  42. local multiCost = 100 -- add new variable for multiCost
  43.  
  44. ------ Gem Data ------
  45. -- Table that stores the pixel data (coordinates and color)
  46. local gems = { }
  47.  
  48. ------------ Functions ------------
  49.  
  50. local function buymultiply() -- make a function out of it so you can use it where you need it  
  51. if money >= multiCost then  -- should be > else you only can buy it when you have exactly this amount
  52. multiCost = multiCost*2
  53.  multi = multi+1
  54. end
  55. end
  56.  
  57. function newGem()
  58.     local w, h = term.getSize()
  59.     local x, y
  60.  
  61.     -- Pick a random spot for the pixel to appear
  62.     while true do
  63.         x = math.random(minX, maxX) -- Random number for the x coordinate
  64.         y = math.random(minY, maxY) -- Random number for the y coordinate
  65.         if #gems > 0 then
  66.             local good = true
  67.             for i, v in ipairs(gems) do
  68.                 -- Check to see if a gem already exists in that position
  69.                 if v[1] == x and v[2] == y then good = false end
  70.             end
  71.             if good then break end
  72.         else
  73.             break
  74.         end
  75.     end
  76.  
  77.     -- Now, we choose a random color for the pixel (maybe you don't need this)
  78.     local color = colorChoices[math.random(1, #colorChoices)]
  79.  
  80.     -- This holds the coordinates and the color of the gem
  81.     local gem = {x, y, color}
  82.     table.insert(gems, gem) -- Adds the gem data to the main table
  83.  
  84.     -- Draw the gem
  85.     term.setCursorPos(x, y)
  86.     term.setBackgroundColor(color)
  87.     write(" ")
  88.     term.setBackgroundColor(bgColor)
  89. end
  90.  
  91. function spawnGems(n)
  92.     for i = 1, n do
  93.         newGem()
  94.     end
  95. end
  96.  
  97. function stats()
  98.     paintutils.drawImage(gamebar, 1,1)
  99.     term.setCursorPos(1,1)
  100.     -- You don't need term.setCursorPos(1, 2) since print automatically moves a line down each time
  101.     print("Money: "..money)
  102.     print("Gems: "..gemsClicked)
  103.     print("Multiplier: ")
  104.     print(multi.."x")
  105.     print("")
  106.     print("Upgrades:")
  107.     print("Multiplier")
  108.     print("Price:")
  109.     print(multiCost)
  110. end
  111. ------------ Running Code ------------
  112.  
  113. -- Don't use a number for the color unless absolutely nessecary...and I have no idea when it would be
  114. -- Use the colors API. 16384 is the same as saying colors.red
  115. term.setBackgroundColor(bgColor)
  116. term.setTextColor(txtColor)
  117. term.clear()
  118. spawnGems(gemsOnScreen)
  119. stats()
  120.  
  121. while true do
  122.     local e, p1, p2, p3 = os.pullEvent("mouse_click")
  123.     -- Check if the coordinates clicked are any of the pixel's coordinates
  124.     if  p1 >= 1 and p1 <= 11 and p2 == 7 then  -- im not sure about this but i thik this should work cause needs to be checked after click and has to be outside the loop for getting gemcoords
  125.         buymultiply()
  126.     end
  127.     for i, v in ipairs(gems) do
  128.         if p1 == 1 and v[1] == p2 and v[2] == p3 then -- A gem was LEFT clicked
  129.             -- Do stuff here
  130.             -- Do more stuff
  131.             -- Increment variables
  132.             gemsClicked = gemsClicked + 1
  133.  
  134.             -- Give money
  135.             money = money + (gemValue[v[3]] * multi) -- Gem value multiplied by the multiplier
  136.  
  137.             -- Remove the gem
  138.             term.setBackgroundColor(bgColor)
  139.             term.setCursorPos(v[1], v[2])
  140.             write(" ")
  141.             table.remove(gems, i)
  142.  
  143.             -- Spawn a new gem
  144.             newGem()
  145.  
  146.             -- Update stats
  147.             stats()
  148.         end
  149.     end
  150.     sleep(0.05)
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement