Guest User

Cookie-ClickerSE

a guest
Oct 1st, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 0 0
  1. local cookies = 0
  2. local cookiesPerSecond = 0
  3. local cursorClick = 1
  4. local gameVersion = 0.5
  5.  
  6. local buildingMenu = false
  7. local termX, termY = term.getSize()
  8.  
  9. function drawCookie() --This function draws the cookie after it sets the rest of the background white.
  10. -- Credits to Hellkid98 for the original function
  11.   term.setBackgroundColor(colors.white)
  12.   term.clear()
  13.   local cookie = {"001111100", "011111110", "121121111", "111211211", "112112111", "011211110", "001111100"}
  14.   for a = 1, #cookie do
  15.     for b = 1,#cookie[a] do
  16.       local str = cookie[a]:sub( b, b )
  17.       if str == "2" then
  18.         term.setBackgroundColor( colors.black )
  19.       elseif str == "1" then
  20.         term.setBackgroundColor( colors.brown )
  21.       elseif str == "0" then
  22.         term.setBackgroundColor( colors.white )
  23.       else
  24.         term.setBackgroundColor( colors.green )
  25.       end
  26.       term.setCursorPos( 2-1+b, 2-1+a )
  27.       term.write( " " )
  28.     end
  29.   end
  30. end
  31. function drawStats() --Draws the stats at their appropriate location(below the cookie)
  32.   local stats = { {"Cookies: ", math.floor(cookies)}, {"CPS: ",  math.floor(cookiesPerSecond)} }
  33.   term.setTextColor(colors.black)
  34.   term.setBackgroundColor(colors.white)
  35.   for i=1, #stats do
  36.     term.setCursorPos(2,10+((i-1)))
  37.     print(stats[i][1]..stats[i][2])
  38.   end
  39. end
  40. function drawTitles() --Draws the titles at the top of the screen
  41.   local titles = {"Cookie Clicker v"..gameVersion, "by ZeeSays"}
  42.   for i=1, #titles do
  43.     term.setCursorPos( (termX - titles[i]:len())/2, i)
  44.     term.setTextColor(colors.orange)
  45.     print(titles[i])
  46.   end
  47.   term.setTextColor(colors.white)
  48. end
  49. function drawBuildings()
  50.   local newX =  6 + (termX/2) - (string.len("|Buildings|")/2)
  51.   local toReturn = newX
  52.   term.setCursorPos( newX, 4 )
  53.   if buildingMenu then term.setTextColor(colors.green) else term.setTextColor(colors.red) end
  54.   print("|Buildings|")
  55.   newX = newX + string.len("|Buildings|")
  56.   term.setCursorPos( newX, 4 )
  57.   term.setBackgroundColor(colors.white)
  58.   term.write("    ")
  59.   newX = newX + string.len("    ")
  60.   term.setCursorPos(newX, 4)
  61.   if buildingMenu then term.setTextColor(colors.red) else term.setTextColor(colors.green) end
  62.   print("|Upgrades|")
  63. end
  64. function drawScreen() --Just a mess of all the 'draw' functions
  65.   term.setBackgroundColor(colors.white)
  66.   term.clear()
  67.   drawCookie()
  68.   drawStats()
  69.   drawTitles()
  70.   drawBuildings()
  71. end
  72. function handleClick(clickX, clickY)
  73.   if clickX > 1 and clickX < 11 and clickY > 1 and clickY < 9 then
  74.     cookies = cookies + cursorClick
  75.   elseif clickX > 25 and clickX < 38 and clickY == 4 then
  76.     buildingMenu = true
  77.   elseif clickX > 40 and clickX < 52 and clickY == 4 then
  78.     buildingMenu = false
  79.   end
  80. end
  81. function handleTimer()
  82.   if cookiesPerSecond < 21 and cookiesPerSecond > 0.9 then
  83.     local n = (1/cookiesPerSecond)
  84.     os.startTimer(1/cookiesPerSecond)
  85.     cookies = cookies + (cookiesPerSecond*n)
  86.   elseif cookiesPerSecond > 20 then
  87.     os.startTimer(0.05)
  88.     cookies = cookies + (cookiesPerSecond/20)
  89.   end
  90. end
  91.  
  92. os.startTimer(1)
  93.  
  94. while true do
  95.   drawScreen()
  96.   local event, button, clickX, clickY = os.pullEvent()
  97.   if event == "mouse_click" then
  98.     handleClick(clickX, clickY)
  99.   elseif event == "timer" then
  100.     handleTimer()
  101.   end
  102. end
Add Comment
Please, Sign In to add comment