· 6 years ago · Dec 29, 2019, 01:54 AM
1-- Graphicals API Embedded. | Copyright Jake Roman 2015
2
3function percent(sInput,sInput2,outputScale)
4 return sInput/sInput2*outputScale
5end
6function loading(sTime)
7 bit = 0
8 if not sTime then
9 local sTime = 2
10 end
11 for i=1,sTime do
12 for p=1,8 do
13 sleep(0.1)
14 term.setCursorPos(25,9)
15 term.setBackgroundColor(colors.lightGray)
16 write(" ")
17 term.setCursorPos(25,10)
18 write(" ")
19 term.setCursorPos(27,10)
20 write(" ")
21 term.setCursorPos(25,11)
22 write(" ")
23 if p == 1 then
24 term.setCursorPos(25,9)
25 end
26 if p == 2 then
27 term.setCursorPos(26,9)
28 end
29 if p == 3 then
30 term.setCursorPos(27,9)
31 end
32 if p == 4 then
33 term.setCursorPos(27,10)
34 end
35 if p == 5 then
36 term.setCursorPos(27,11)
37 end
38 if p == 6 then
39 term.setCursorPos(26,11)
40 end
41 if p == 7 then
42 term.setCursorPos(25,11)
43 end
44 if p == 8 then
45 term.setCursorPos(25,10)
46 end
47 term.setBackgroundColor(colors.blue)
48 write(" ")
49 if p == 1 then
50 term.setCursorPos(25,10)
51 end
52 if p == 2 then
53 term.setCursorPos(25,9)
54 end
55 if p == 3 then
56 term.setCursorPos(26,9)
57 end
58 if p == 4 then
59 term.setCursorPos(27,9)
60 end
61 if p == 5 then
62 term.setCursorPos(27,10)
63 end
64 if p == 6 then
65 term.setCursorPos(27,11)
66 end
67 if p == 7 then
68 term.setCursorPos(26,11)
69 end
70 if p == 8 then
71 term.setCursorPos(25,11)
72 end
73 term.setBackgroundColor(colors.lightBlue)
74 write(" ")
75 end
76 end
77end
78function fadeIn()
79 term.setBackgroundColor(colors.black)
80 term.clear()
81 sleep(0.1)
82 term.setBackgroundColor(colors.gray)
83 term.clear()
84 sleep(0.1)
85 term.setBackgroundColor(colors.lightGray)
86 term.clear()
87 sleep(0.1)
88 term.setBackgroundColor(colors.white)
89 term.clear()
90 sleep(0.1)
91end
92function rainbowPrint(str)
93 color = 0
94 for i=1,#str do
95 color = color + 1
96 if color == 1 then
97 term.setTextColor(colors.red)
98 end
99 if color == 2 then
100 term.setTextColor(colors.orange)
101 end
102 if color == 3 then
103 term.setTextColor(colors.yellow)
104 end
105 if color == 4 then
106 term.setTextColor(colors.lime)
107 end
108 if color == 5 then
109 term.setTextColor(colors.blue)
110 color = 0
111 end
112 write(string.sub(str,i,i))
113 end
114 print("")
115end
116function box(xPos1,yPos1,xPos2,yPos2,sColor,inCol)
117 paintutils.drawFilledBox(xPos1,yPos1,xPos2,yPos2,sColor)
118 if inCol then
119 paintutils.drawFilledBox(xPos1 + 1,yPos1 + 1,xPos2 - 1,yPos2 - 1,inCol)
120 end
121end
122function center(str,rainbow)
123 maxX,maxY = term.getSize()
124 curX,curY = term.getCursorPos()
125 maxX = maxX / 2
126 subX = #str / 2
127 maxX = maxX - subX
128 term.setCursorPos(maxX,curY)
129 if rainbow then
130 rainbowPrint(str)
131 else
132 print(str)
133 end
134end
135function fadeOut()
136 term.setBackgroundColor(colors.white)
137 term.clear()
138 sleep(0.2)
139 term.setBackgroundColor(colors.lightGray)
140 term.clear()
141 sleep(0.2)
142 term.setBackgroundColor(colors.gray)
143 term.clear()
144 sleep(0.2)
145 term.setBackgroundColor(colors.black)
146 term.clear()
147 sleep(0.2)
148end
149function fadeTo(sColor)
150 for i=1,19 do
151 term.setCursorPos(1,i)
152 term.setBackgroundColor(sColor)
153 term.clearLine()
154 sleep(0.1)
155 end
156end
157function loadBar(col1,col2)
158 if not col1 then col1 = colors.red end
159 if not col2 then col2 = colors.lime end
160 curX,curY = term.getCursorPos()
161 term.setCursorPos(2,curY)
162 term.setBackgroundColor(col1)
163 for i=1,49 do
164 write(" ")
165 end
166 term.setCursorPos(2,curY)
167 term.setBackgroundColor(col2)
168 for i=1,49 do
169 sleep(0)
170 write(" ")
171 end
172end
173function clearArea(xPos1,yPos1,xPos2,yPos2)
174 for curY=yPos1,yPos2 do
175 for curX=xPos1,xPos2 do
176 term.setCursorPos(curX,curY)
177 write(" ")
178 end
179 end
180end
181
182fadeIn()
183term.setBackgroundColor(colors.white)
184term.clear()
185term.setCursorPos(1,1)
186term.setBackgroundColor(colors.lightGray)
187term.clearLine()
188term.setCursorPos(1,1)
189term.setTextColor(colors.black)
190center("Cookie Clicker")
191term.setCursorPos(2,18)
192term.setBackgroundColor(colors.white)
193term.setTextColor(colors.gray)
194center("Press any key to start.")
195os.pullEvent("key")
196term.setBackgroundColor(colors.white)
197term.clear()
198local cookies = 0
199local farms = 0
200local grandmas = 0
201local clickers = 0
202local cookiesPerTick = 0
203local tab = 0
204while true do
205 term.current().setVisible(false)
206 cookiesPerTick = (clickers + (grandmas * 2) + (farms * 8)) / 4
207 if tab == 1 then
208 term.setBackgroundColor(colors.white)
209 term.clear()
210 term.setCursorPos(1,1)
211 term.setBackgroundColor(colors.lightGray)
212 term.clearLine()
213 term.setCursorPos(1,1)
214 term.setTextColor(colors.black)
215 center("Clicker Store")
216 term.setCursorPos(47,1)
217 term.setTextColor(colors.blue)
218 write("Back")
219 term.setCursorPos(2,3)
220 if cookies >= 100 then
221 term.setBackgroundColor(colors.lime)
222 else
223 term.setBackgroundColor(colors.lightGray)
224 end
225 term.setTextColor(colors.gray)
226 write("Buy")
227 term.setBackgroundColor(colors.white)
228 term.setTextColor(colors.black)
229 write(" Grandma ")
230 term.setTextColor(colors.green)
231 write("$100")
232 term.setCursorPos(2,5)
233 if cookies >= 25 then
234 term.setBackgroundColor(colors.lime)
235 else
236 term.setBackgroundColor(colors.lightGray)
237 end
238 term.setTextColor(colors.gray)
239 write("Buy")
240 term.setTextColor(colors.black)
241 term.setBackgroundColor(colors.white)
242 write(" Clicker ")
243 term.setTextColor(colors.green)
244 write("$25")
245 term.setCursorPos(2,7)
246 if cookies >= 500 then
247 term.setBackgroundColor(colors.lime)
248 else
249 term.setBackgroundColor(colors.lightGray)
250 end
251 term.setTextColor(colors.gray)
252 write("Buy")
253 term.setTextColor(colors.black)
254 term.setBackgroundColor(colors.white)
255 write(" Farm ")
256 term.setTextColor(colors.green)
257 write("$500")
258 term.setCursorPos(2,18)
259 term.setTextColor(colors.brown)
260 write("Cookies: ")
261 term.setTextColor(colors.gray)
262 write(tostring(math.floor(cookies)))
263 term.setCursorPos(51 - #tostring(grandmas),3)
264 term.setTextColor(colors.gray)
265 write(tostring(grandmas))
266 term.setCursorPos(51 - #tostring(clickers),5)
267 write(tostring(clickers))
268 term.setCursorPos(51 - #tostring(farms),7)
269 write(tostring(farms))
270 timer = os.startTimer(0.5)
271 term.current().setVisible(true)
272 e,c,x,y = os.pullEvent()
273 if e == "mouse_click" then
274 if x >= 2 and x <= 5 then
275 if y == 7 and cookies >= 500 then
276 cookies = cookies - 500
277 farms = farms + 1
278 term.setCursorPos(2,7)
279 term.setBackgroundColor(colors.green)
280 term.setTextColor(colors.gray)
281 write("Buy")
282 sleep(0.3)
283 end
284 if y == 3 and cookies >= 100 then
285 cookies = cookies - 100
286 grandmas = grandmas + 1
287 term.setCursorPos(2,3)
288 term.setBackgroundColor(colors.green)
289 term.setTextColor(colors.gray)
290 write("Buy")
291 sleep(0.3)
292 end
293 if y == 5 and cookies >= 25 then
294 cookies = cookies - 25
295 clickers = clickers + 1
296 term.setCursorPos(2,5)
297 term.setBackgroundColor(colors.green)
298 term.setTextColor(colors.gray)
299 write("Buy")
300 sleep(0.3)
301 end
302 end
303 if x >= 47 and x <= 50 then
304 tab = 0
305 end
306 end
307 if e == "timer" then
308 cookies = cookies + cookiesPerTick
309 else
310 os.cancelTimer(timer)
311 end
312 end
313 if tab == 0 then
314 term.setBackgroundColor(colors.white)
315 term.clear()
316 term.setCursorPos(1,1)
317 term.setBackgroundColor(colors.lightGray)
318 term.clearLine()
319 term.setCursorPos(2,1)
320 term.setTextColor(colors.black)
321 center("Cookie Clicker")
322 term.setCursorPos(46,1)
323 term.setBackgroundColor(colors.lightGray)
324 term.setTextColor(colors.blue)
325 write("Store")
326 term.setCursorPos(3,3)
327 term.setBackgroundColor(colors.brown)
328 write(" ")
329 term.setBackgroundColor(colors.black)
330 write(" ")
331 term.setBackgroundColor(colors.brown)
332 term.setCursorPos(2,4)
333 term.setBackgroundColor(colors.black)
334 write(" ")
335 term.setBackgroundColor(colors.brown)
336 write(" ")
337 term.setBackgroundColor(colors.brown)
338 term.setCursorPos(2,5)
339 write(" ")
340 term.setBackgroundColor(colors.black)
341 write(" ")
342 term.setBackgroundColor(colors.brown)
343 write(" ")
344 term.setCursorPos(3,6)
345 write(" ")
346 term.setCursorPos(2,18)
347 term.setBackgroundColor(colors.white)
348 term.setTextColor(colors.brown)
349 write("Cookies: ")
350 term.setTextColor(colors.gray)
351 write(tostring(math.floor(cookies)))
352 term.setCursorPos(2,17)
353 timer = os.startTimer(0.5)
354 term.current().setVisible(true)
355 e,c,x,y = os.pullEvent()
356 if e == "key" then
357 if c == 41 then
358 box(1,16,51,18,colors.gray,colors.black)
359 term.setCursorPos(2,17)
360 term.setBackgroundColor(colors.black)
361 term.setTextColor(colors.yellow)
362 write("> ")
363 term.setTextColor(colors.white)
364 local input = read()
365 if string.sub(input,1,8) == "cookies " then
366 cookies = tonumber(string.sub(input,9,#input))
367 end
368 end
369 end
370 if e == "timer" then
371 cookies = cookies + cookiesPerTick
372 else
373 os.cancelTimer(timer)
374 end
375 if e == "mouse_click" then
376 if x >= 46 and x <= 50 and y == 1 then
377 tab = 1
378 end
379 if x >= 2 and x <= 4 and y >= 3 and y <= 6 then
380 term.setCursorPos(3,2)
381 term.setTextColor(colors.black)
382 term.setBackgroundColor(colors.white)
383 write("+1")
384 cookies = cookies + 1
385 sleep(0.1)
386 end
387 end
388 end
389end