Advertisement
justync7

gem

May 22nd, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.36 KB | None | 0 0
  1. -- Variables --
  2. debug = "Debug"
  3. w, h = term.getSize()
  4.  
  5. -- Values --
  6.  
  7. limeName = "Lime gem: "
  8. limeSell = 10
  9. lblueName = "Light blue gem: "
  10. lblueSell = 15
  11. yellowName = "Yellow gem: "
  12. yellowSell = 50
  13. orangeName = "Orange gem: "
  14. orangeSell = 100
  15. redName= "Red gem:"
  16. redSell = 1000
  17.  
  18. -- Stats --
  19. money = 0
  20. playerName = "nil"
  21. limeGems = 0
  22. lblueGems = 0
  23. yellowGems = 0
  24. orangeGems = 0
  25. redGems = 0
  26. multi = 1
  27. multiCost = 1000
  28. -- End Stats --
  29.  
  30. -- End Variables --
  31. -- Game --
  32.  
  33. function playGame()
  34. slc = 1
  35. -- Variables --
  36. minX = 13
  37. maxX = w-1
  38. minY = 2
  39. maxY = h-1
  40. maxGem = 20
  41. spawnedGems = 0
  42. bgColor = colors.black
  43. local gems = { }
  44.  
  45. function spawnGem()
  46. if spawnedGems >= maxGem then
  47. gemClick()
  48. else
  49. sleep(0.05)
  50. paintutils.drawPixel(newX, newY, color)
  51. spawnedGems = spawnedGems + 1
  52. sleep(0.05)
  53. local Gem = {newX, newY, color}
  54. table.insert(gems, Gem)
  55. gem()
  56. end
  57. end
  58.  
  59. function gem()
  60. while true do
  61. newX = math.random(minX, maxX)
  62. newY = math.random(minY, maxY)
  63. colorNum = math.random(1,5)
  64. if colorNum == 1 then
  65. color = colors.orange
  66. sleep(0.1)
  67. spawnGem()
  68. elseif colorNum == 2 then
  69. color = colors.yellow
  70. sleep(0.1)
  71. spawnGem()
  72. elseif colorNum == 3 then
  73. color = colors.lime
  74. sleep(0.1)
  75. spawnGem()
  76. elseif colorNum == 4 then
  77. color = colors.lightBlue
  78. sleep(0.1)
  79. spawnGem()
  80. elseif colorNum == 5 then
  81. color = colors.red
  82. sleep(0.1)
  83. spawnGem()
  84. end
  85. end
  86. end
  87.  
  88. function gemClick()
  89. slc = 1
  90. while true do
  91. local e, p1, p2, p3 = os.pullEvent("mouse_click")
  92. if slc == 1 then
  93. for i, v in ipairs(gems) do
  94. if p1 == 1 and v[1] == p2 and v[2] == p3 then -- A gem was LEFT clicked
  95. -- Remove the gem
  96. term.setBackgroundColor(bgColor)
  97. term.setCursorPos(v[1], v[2])
  98. write(" ")
  99. table.remove(gems, i)
  100. spawnedGems = spawnedGems - 1
  101. if v[3] == colors.orange then
  102. orangeGems = orangeGems + (1*multi)
  103. elseif v[3] == colors.yellow then
  104. yellowGems = yellowGems + (1*multi)
  105. elseif v[3] == colors.lime then
  106. limeGems = limeGems + (1*multi)
  107. elseif v[3] == colors.lightBlue then
  108. lblueGems = lblueGems +(1*multi)
  109. elseif v[3] == colors.red then
  110. redGems = redGems + (1*multi)
  111. end
  112.  
  113.  
  114. -- Spawn a new gem
  115. gem()
  116.  
  117. elseif p1 == 1 and p2 >= 5 and p2 <= 10 and p3 == h-4 then
  118. frame2()
  119. end
  120.  
  121. end
  122. sleep(0.05)
  123. end
  124. end
  125. end
  126.  
  127.  
  128. local function frame()
  129. term.clear()
  130. term.setBackgroundColor(colors.black)
  131. term.clear()
  132. paintutils.drawLine(12, 1, 12, h, colors.red)
  133. paintutils.drawLine(12, 1, w, 1, colors.red)
  134. paintutils.drawLine(12, h, w, h, colors.red)
  135. paintutils.drawLine(w, 1, w, h, colors.red)
  136. paintutils.drawLine(1, 1, 1, h, colors.red)
  137. paintutils.drawLine(1, 1, 1, h, colors.red)
  138. paintutils.drawLine(2, 1, 2, h, colors.red)
  139. paintutils.drawLine(3, 1, 3, h, colors.red)
  140. paintutils.drawLine(4, 1, 4, h, colors.red)
  141. paintutils.drawLine(5, 1, 5, h, colors.red)
  142. paintutils.drawLine(6, 1, 6, h, colors.red)
  143. paintutils.drawLine(7, 1, 7, h, colors.red)
  144. paintutils.drawLine(8, 1, 8, h, colors.red)
  145. paintutils.drawLine(9, 1, 9, h, colors.red)
  146. paintutils.drawLine(10, 1, 10, h, colors.red)
  147. paintutils.drawLine(11, 1, 11, h, colors.red)
  148. term.setBackgroundColor(colors.lime)
  149. term.setTextColor(colors.black)
  150. term.setCursorPos(1, 2)
  151. print("Multiplier:")
  152. term.setCursorPos(1,4)
  153. print(multi)
  154. term.setCursorPos(5, h-4)
  155. print(" Exit ")
  156. end
  157.  
  158.  
  159.  
  160.  
  161. frame()
  162. gem()
  163.  
  164. end
  165.  
  166. function sellGems()
  167. term.setBackgroundColor(1)
  168. term.clear()
  169. paintutils.drawPixel(1, 4, 32)
  170. paintutils.drawPixel(1, 6, 8)
  171. paintutils.drawPixel(1, 8, 16)
  172. paintutils.drawPixel(1, 10, 2)
  173. paintutils.drawPixel(1, 12, 16384)
  174. term.setBackgroundColor(1)
  175. term.setCursorPos(1, 2)
  176. print("Money: "..money)
  177. term.setCursorPos(3, 4)
  178. print(limeName ..limeGems)
  179. term.setCursorPos(3, 6)
  180. print(lblueName ..lblueGems)
  181. term.setCursorPos(3, 8)
  182. print(yellowName ..yellowGems)
  183. term.setCursorPos(3, 10)
  184. print(orangeName ..orangeGems)
  185. term.setCursorPos(3, 12)
  186. print(redName ..redGems)
  187. print("Back")
  188. term.setCursorPos(w-25, 5)
  189. print("Upgrades Cost")
  190. term.setCursorPos(w-25, 7)
  191. print("+1 Multiplier "..multiCost)
  192. while true do
  193. event, but, x, y = os.pullEvent("mouse_click")
  194. if event == "mouse_click" then
  195. if but == 1 and x >= 3 and x <= 13 and y == 4 then
  196. money = limeGems*limeSell + money
  197. limeGems = 0
  198. sellGems()
  199. elseif but == 1 and x >= 3 and x <= 18 and y == 6 then
  200. money = lblueGems*lblueSell+money
  201. lblueGems = 0
  202. sellGems()
  203. elseif but == 1 and x >= 3 and x <= 14 and y == 8 then
  204. money = yellowGems*yellowSell+money
  205. yellowGems = 0
  206. sellGems()
  207. elseif but == 1 and x >= 3 and x <= 14 and y == 10 then
  208. money = orangeGems*orangeSell+money
  209. orangeGems = 0
  210. sellGems()
  211. elseif but == 1 and x >= 3 and x <= 14 and y == 12 then
  212. money = redGems*redSell+money
  213. redGems = 0
  214. sellGems()
  215. elseif but == 1 and x >= 3 and x <= (w-25)+14 and y == 7 then
  216. if money >= multiCost then
  217. money = money-multiCost
  218. multi = multi+1
  219. multiCost = multiCost*2
  220. sellGems()
  221. end
  222. elseif but == 1 and x >= 3 and x <= 7 and y == 13 then
  223. frame2()
  224. end
  225. end
  226. end
  227. end
  228.  
  229.  
  230.  
  231. function frame2()
  232. slc = 0
  233. term.setBackgroundColor(colors.white)
  234. term.clear()
  235. term.setCursorPos(math.floor(w-string.len("Logged in as: "..playerName))/2, 2)
  236. print("Logged in as: "..playerName )
  237. paintutils.drawPixel(1, 4, 32)
  238. paintutils.drawPixel(1, 6, 8)
  239. paintutils.drawPixel(1, 8, 16)
  240. paintutils.drawPixel(1, 10, 2)
  241. paintutils.drawPixel(1, 12, 16384)
  242. term.setBackgroundColor(1)
  243. term.setCursorPos(3, 4)
  244. print(limeName ..limeGems)
  245. term.setCursorPos(3, 6)
  246. print(lblueName ..lblueGems)
  247. term.setCursorPos(3, 8)
  248. print(yellowName ..yellowGems)
  249. term.setCursorPos(3, 10)
  250. print(orangeName ..orangeGems)
  251. term.setCursorPos(3, 12)
  252. print(redName ..redGems)
  253. term.setBackgroundColor(32)
  254. term.setCursorPos(10, 15)
  255. print("Play")
  256. term.setCursorPos(20, 15)
  257. print("Sell Gems")
  258. while true do
  259. event, button, x, y = os.pullEvent("mouse_click")
  260. if event == "mouse_click" then
  261. if slc == 0 then
  262. if x >= 10 and x <= 15 and y == 15 and button == 1 then
  263. term.clear()
  264. playGame()
  265. break
  266. elseif x >= 20 and x <= 30 and y == 15 and button == 1 then
  267. sellGems()
  268. end
  269. elseif slc == 1 then
  270. if x >= 5 and x <= 10 and y == h-4 and button == 1 then
  271. slc = 0
  272. frame2()
  273. end
  274. end
  275. end
  276. end
  277. end
  278.  
  279. function game()
  280. term.clear()
  281. term.setBackgroundColor(1)
  282. term.setTextColor(32768)
  283. term.clear()
  284. term.setCursorPos(math.floor(w-string.len("Name: "))/2, 2)
  285. write("Name: ")
  286. playerName = read()
  287. if playerName == "" then
  288. game()
  289. else
  290. frame2()
  291. end
  292. end
  293.  
  294. -- End Functions --
  295.  
  296. game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement