Advertisement
Guest User

bubbles

a guest
Dec 8th, 2014
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. local bubbles = {}
  2. local bubbleChars = { "0", "O", "o", ",", "*" }
  3. local x, y = term.getSize()
  4. term.setTextColor( colors.lightBlue )
  5. pRunning = true
  6.  
  7. local rise = {
  8. ["0"] = 3,
  9. O = 3,
  10. o = 2,
  11. [","] = 1,
  12. ["*"] = 1,
  13. ["."] = 1,
  14. }
  15.  
  16. for i = 1, x, 3 do
  17. bubbles[ #bubbles + 1 ] = { c = bubbleChars[ math.random( 1, #bubbleChars ) ], x = i + math.random( 0, 2 ), y = y - math.random( 0, 3 ), ly = 1}
  18. end
  19.  
  20. function BubblesMain()
  21. while pRunning == true do
  22. for _, bubble in ipairs( bubbles ) do
  23. if bubble.y < 1 then
  24. bubble.y = y
  25. bubble.c = bubbleChars[ math.random( 1, #bubbleChars ) ]
  26. bubble.lx = bubble.x
  27. bubble.x = bubble.x + math.random( -1, 1 )
  28. end
  29. term.setCursorPos( bubble.lx or bubble.x, bubble.ly )
  30. term.write( ' ' )
  31. term.setCursorPos( bubble.x, bubble.y )
  32. term.write( bubble.c )
  33. bubble.ly = bubble.y
  34. local doesRise = math.random( 0, rise[ bubble.c ] ) > 0
  35. bubble.y = bubble.y - (doesRise and 1 or 0)
  36. bubble.lx = nil
  37. end
  38. sleep( 0.05 )
  39. end
  40. end
  41.  
  42. parallel.waitForAny(BubblesMain, function()
  43. os.pullEvent("key")
  44. pRunning = false
  45. end)
  46.  
  47. term.setCursorPos(1,1)
  48. term.clear()
  49. term.setBackgroundColor(colors.black)
  50. term.setTextColor(colors.white)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement