Advertisement
Agent_Silence

Rain

Jan 25th, 2015 (edited)
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. local rain = {}
  2. local maxX, maxY = term.getSize()
  3. function newrain()
  4.   local axis = math.random(1,2) == 1 and true or false
  5.   local template = {
  6.   x = axis == true and math.random(1,maxX) or maxX,
  7.   y = axis == false and math.random(1,maxY) or 1,
  8.   color = colors.blue,
  9.   velo = math.random(1,4) == 4 and 2 or 1
  10.   }
  11.   table.insert(rain,template)
  12. end
  13.  
  14. function redraw(bool)
  15.   term.setBackgroundColor(bool == true and colors.white or colors.black)
  16.   term.clear()
  17.   for i,v in ipairs(rain) do
  18.     term.setCursorPos(v.x,v.y)
  19.     term.setTextColor(v.color)
  20.     term.write("/")
  21.     v.x = v.x - v.velo
  22.     v.y = v.y + v.velo
  23.     if v.y > maxX or v.x < 1 then
  24.       table.remove(rain,i)
  25.     end
  26.   end
  27. end
  28.  
  29. local boolean
  30. local light = 0
  31. while true do
  32.     for i=1,3 do
  33.         newrain()
  34.     end
  35.     if boolean == true then
  36.         light = light + 1
  37.         if light == 5 then -- Display lightning for 5 ticks
  38.             boolean = false
  39.             light = 0
  40.         end
  41.     else
  42.         boolean = math.random(1,100) == 1 and true or false -- If the number 1 gets chosen, it sets "boolean" to true
  43.         if boolean == true and commands then
  44.             commands.exec("playsound ambient.weather.thunder"..math.random(1,3).." @p")
  45.         end
  46.     end
  47.     redraw(boolean)
  48.     sleep(0.01)
  49.     if commands then
  50.         commands.exec("playsound ambient.weather.rain @p")
  51.     end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement