sidekick_

Minecraft Valentines Code for Evilguard

Jan 14th, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.10 KB | None | 0 0
  1. sPictureFolder = "valentines"
  2. t_heartFiles = { {fileName = "heartSmall", pastebin_url = "LTGTvHTU"}, {fileName = "heartMedium", pastebin_url = "mMtPd9Xc"}, {fileName = "heartBig", pastebin_url = "U81i0r34"}}
  3. nHeartAnimationDelay = 0.1
  4. screenX, screenY = term.getSize()
  5. start = false
  6.  
  7. function centerW(text, yPos, col)
  8.     term.setCursorPos(math.floor((screenX-#text)/2), yPos)
  9.     term.setTextColour(col)
  10.     write(text)
  11.     term.setTextColour(colours.black)
  12. end
  13.  
  14. function animateHearts()
  15.     heartTimer = os.startTimer(nHeartAnimationDelay)
  16.     for times = 1, 6 do
  17.         term.clear()
  18.         for i = 1, #t_heartFiles do
  19.             heart = paintutils.loadImage(sPictureFolder .. "/" .. t_heartFiles[i].fileName)
  20.             xPos = screenX/2 - (2^i)
  21.             yPos = screenY/2 - (2*i-1)
  22.             paintutils.drawImage(heart, xPos, yPos)
  23.             repeat _, timer = os.pullEvent("timer") until timer == heartTimer
  24.             heartTimer = os.startTimer(nHeartAnimationDelay)
  25.         end    
  26.     end
  27. end
  28.  
  29. function ask(method)
  30.     term.clear()
  31.     if method == "cart" then
  32.         t_Options = { {text = "Yes", xPos = 14, colour = colours.yellow}, {text = "No", xPos = 34, colour = colours.red}}
  33.         centerW(not start and "Are you in the cart?" or "Are you in the cart yet? :)", 3, colours.yellow)
  34.         for i = 1, #t_Options do
  35.             term.setCursorPos(t_Options[i].xPos, 5)
  36.             term.setTextColour(t_Options[i].colour)
  37.             write(t_Options[i].text)
  38.         end
  39.         while true do
  40.             _, b, x, y = os.pullEvent("mouse_click")
  41.             if b == 1 then -- left click
  42.                 for i = 1, #t_Options do
  43.                     if x >= t_Options[i].xPos and x < (t_Options[i].xPos + #t_Options[i].text) and y == 5 then
  44.                         return t_Options[i].text
  45.                     end
  46.                 end
  47.             end
  48.         end
  49.     elseif method == "answer" then
  50.         while true do
  51.             centerW("What is the answer?", 5, colours.yellow)
  52.             term.setCursorPos((screenX-4)/2, 6)
  53.             term.setTextColour(colours.lightBlue)
  54.             answer = read()
  55.             if answer == "42" then -- For when it's correct
  56.                 term.clear()
  57.                 centerW("Yay!", 5, colours.red)
  58.                 rs.setOutput("right", true) -- this code triggers the redstone signal to the right of the computer
  59.                 while true do sleep(10) end
  60.             else
  61.                 term.clear()
  62.                 centerW(":(", 5, colours.red) -- This will write each time he gets the answer wrong
  63.                 sleep(3)
  64.             end
  65.         end
  66.     end
  67. end
  68.  
  69. function download(sCode, sPath)
  70.     local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode ) )
  71.     if response then       
  72.         file = fs.open( sPath, "w" )
  73.         file.write( response.readAll() )
  74.         file.close()
  75.         response.close()
  76.     end
  77. end
  78.  
  79. if not fs.isDir(sPictureFolder) then fs.makeDir(sPictureFolder) end
  80. for i = 1, #t_heartFiles do
  81.     if not fs.exists(sPictureFolder .. "/" .. t_heartFiles[i].fileName) then
  82.         download(t_heartFiles[i].pastebin_url, sPictureFolder .. "/" .. t_heartFiles[i].fileName)
  83.     end
  84. end
  85.  
  86. while true do
  87.     option = ask("cart")
  88.     if not start then start = not start end
  89.     if option == "Yes" then
  90.         animateHearts()
  91.         ask("answer")
  92.         break
  93.     elseif option == "No" then
  94.         term.clear()
  95.         centerW("Ok :(", 4, colours.red)
  96.         centerW("Please get in the", 5, colours.yellow)
  97.         centerW("cart when you can :)", 6, colours.yellow)
  98.         sleep(3)
  99.     end
  100. end
Advertisement
Add Comment
Please, Sign In to add comment