Advertisement
Theo123456

Guerre du ciel

Jul 15th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. m = peripheral.wrap("back")
  2.  
  3. m.setTextScale(0.5)
  4. x,y = m.getSize()
  5. print(x..":"..y)
  6.  
  7. iter = 0
  8. text = "\_/%100%\_/"
  9. --text = "BITE"
  10. items = {}
  11. stars = {}
  12. starsNbr = 150
  13.  
  14. function registerStars()
  15. stars = {}
  16. for i=1,starsNbr do
  17. toAdd = {}
  18. toAdd["x"] = math.random(1,x)
  19. toAdd["y"] = math.random(1,y)
  20. table.insert(stars,toAdd)
  21. end
  22. end
  23.  
  24. function forwardStars()
  25. for k,v in pairs(stars) do
  26. stars[k]["x"] = stars[k]["x"]+1
  27. end
  28. for i=1,10 do
  29. toAdd = {}
  30. toAdd["x"] = 1
  31. toAdd["y"] = math.random(1,y)
  32. if math.random(1,100) > 90 then table.insert(stars,toAdd) end
  33. end
  34. end
  35.  
  36. function drawStars()
  37. for k,v in pairs(stars) do
  38. m.setCursorPos(v["x"],v["y"])
  39. if math.random(1,100) > 70 then m.setTextColor(colors.lightGray) else m.setTextColor(colors.gray) end
  40. m.write(".")
  41. end
  42. end
  43.  
  44. function redraw()
  45. m.clear()
  46. m.setTextColor(colors.gray)
  47. drawStars()
  48. m.setTextColor(colors.lightGray)
  49. for k,v in ipairs(items) do
  50. items[k]["x"] = v["x"]+1
  51. m.setCursorPos(v["x"],v["y"])
  52. m.write(text)
  53. x,y = m.getSize()
  54. if v["x"] > x then table.remove(items,k) end
  55. end
  56. end
  57.  
  58. function addPlot()
  59. h = math.random(1,y)
  60. add = {}
  61. add["x"] = 1
  62. add["y"] = h
  63. table.insert(items,add)
  64. end
  65.  
  66. registerStars()
  67. addPlot()
  68. while true do
  69. iter = iter + 1
  70. redraw()
  71. os.sleep(0.05)
  72. if iter % 14 == 0 then addPlot() end
  73. if iter % 20 == 0 then forwardStars() end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement