Advertisement
King0fGamesYami

Bubbles!

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