atmos.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. -- title: atmos
  2. -- author: pixelbath
  3. -- desc: some atmospheric-type particle effects
  4. -- PARTICLE/VFX STUFF
  5. particletype = 'rain' -- snow|rain|stars
  6. particles = {}
  7. local starcolors = { 9, 10, 11, 12}
  8. t = 0
  9. function particleinit(numparticles)
  10. particles = {}
  11. if particletype == 'stars' then
  12. for i = 0, numparticles do
  13. table.insert(particles, {
  14. x = math.random() * 240,
  15. y = math.random() * 136,
  16. twinkle = math.random() > 0.49, -- randomly pick true/false
  17. color = starcolors[math.random(#starcolors)],
  18. t = 0,
  19. vel = 0,
  20. })
  21. end
  22. end
  23. if particletype == 'rain' or particletype == 'snow' then
  24. for i = 0, numparticles do
  25. table.insert(particles, {
  26. x = math.random() * 240,
  27. y = math.random() * 136,
  28. lastx = 0,
  29. lasty = -3,
  30. t = 0,
  31. vel = (math.random() * 3) + 1,
  32. })
  33. end
  34. end
  35. end
  36. function particleupdate()
  37. if particletype == 'stars' then
  38. for i = 1,#particles do
  39. local p = particles[i]
  40. if not p.twinkle then goto continueTwinkle end
  41. ::continueTwinkle::
  42. if t % 15 == 0 and math.random() > 0.1 then
  43. p.color = starcolors[math.random(#starcolors)]
  44. end
  45. end
  46. end
  47. if particletype == 'rain' then
  48. for i = 1,#particles do
  49. local p = particles[i]
  50. if p.lasty and p.lasty > 136 then
  51. p.y = 0
  52. p.lasty = 0
  53. p.color = 9
  54. p.x = math.random() * 240
  55. end
  56. p.lasty = p.y
  57. p.lastx = p.x
  58. p.y = p.y + p.vel
  59. end
  60. end
  61. if particletype == 'snow' then
  62. for i = 1,#particles do
  63. local p = particles[i]
  64. if p.y and p.y > 136 then
  65. p.y = 0
  66. p.lasty = 0
  67. p.color = 12
  68. p.x = math.random() * 240
  69. end
  70. p.x = p.x - (math.random() - 0.4)
  71. p.y = p.y + p.vel
  72. end
  73. end
  74. end
  75. function particledraw()
  76. if particletype == 'rain' then
  77. for i = 1,#particles do
  78. local p = particles[i]
  79. line(p.x, p.y, p.lastx, p.lasty, p.color)
  80. end
  81. else
  82. for i = 1,#particles do
  83. local p = particles[i]
  84. pix(p.x, p.y, p.color)
  85. end
  86. end
  87. end
  88. particleinit(100)
  89. function TIC()
  90. if btnp(4) then
  91. particletype='rain'
  92. particleinit(100)
  93. end
  94. if btnp(5) then
  95. particletype='stars'
  96. particleinit(80)
  97. end
  98. if btnp(6) then
  99. particletype='snow'
  100. particleinit(100)
  101. end
  102. cls(0)
  103. particleupdate()
  104. particledraw()
  105. t = t + 1
  106. end
  107. -- <PALETTE>
  108. -- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
  109. -- </PALETTE>