particles.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. -- title: simple particle system
  2. -- author: pixelbath
  3. -- desc: basic particle system, first used in Alter Ego by Kyuchumimo
  4. -- script: lua
  5. t=0
  6. x=96
  7. y=24
  8. particles = {}
  9. local starcolors = { 8, 9, 10, 11, 12 }
  10. local snowcolors = { 12, 13 }
  11. local raincolors = { 8, 9 } -- in order of depth, farthest to closest
  12. -- rain|snow|stars
  13. particletype = 'snow'
  14. -- numparticles = number of particles to show
  15. function particleinit(numparticles)
  16. -- initialize
  17. particles = {}
  18. for i = 0, numparticles do
  19. table.insert(particles, {
  20. x = math.random() * 240,
  21. y = math.random() * 136,
  22. lastx = 0,
  23. lasty = 0,
  24. color = 2,
  25. t = 0,
  26. vel = 0,
  27. })
  28. end
  29. if particletype == 'stars' then
  30. for i = 1, #particles do
  31. particles[i].twinkle = math.random() > 0.49 -- randomly pick true/false
  32. particles[i].color = starcolors[math.random(#starcolors)]
  33. end
  34. end
  35. if particletype == 'rain' then
  36. for i = 1, #particles do
  37. particles[i].vel = math.random(4) + 1
  38. particles[i].color = raincolors[1]
  39. if particles[i].vel > 3.1 then
  40. particles[i].color = raincolors[2]
  41. end
  42. end
  43. end
  44. if particletype == 'snow' then
  45. for i = 1, #particles do
  46. particles[i].color = snowcolors[1]
  47. particles[i].vel = math.random() + 0.2
  48. if particles[i].vel > 0.8 then
  49. particles[i].color = snowcolors[2]
  50. end
  51. end
  52. end
  53. end
  54. function particleupdate()
  55. if particletype == 'stars' then
  56. for i = 1,#particles do
  57. local p = particles[i]
  58. if not p.twinkle then goto continueTwinkle end
  59. if t % 15 == 0 and math.random() > 0.1 then
  60. p.color = starcolors[math.random(#starcolors)]
  61. end
  62. ::continueTwinkle::
  63. end
  64. end
  65. if particletype == 'rain' then
  66. for i = 1,#particles do
  67. local p = particles[i]
  68. if p.lasty and p.lasty > 136 then
  69. p.y = 0
  70. p.lasty = 0
  71. p.x = math.random() * 260 - 10
  72. end
  73. p.lasty = p.y
  74. p.lastx = p.x
  75. p.x = p.x - p.vel / 5
  76. p.y = p.y + p.vel * 1.5
  77. end
  78. end
  79. if particletype == 'snow' then
  80. for i = 1,#particles do
  81. local p = particles[i]
  82. if p.y and p.y > 136 then
  83. p.y = 0
  84. p.lasty = 0
  85. p.x = math.random() * 260 - 10
  86. end
  87. p.x = p.x - (math.random() - 0.4)
  88. p.y = p.y + p.vel
  89. end
  90. end
  91. end
  92. function particledraw()
  93. if (particletype == 'rain') then
  94. for i = 1,#particles do
  95. local p = particles[i]
  96. line(p.x, p.y, p.lastx, p.lasty, p.color)
  97. end
  98. return
  99. end
  100. for i = 1,#particles do
  101. local p = particles[i]
  102. pix(p.x, p.y, p.color)
  103. end
  104. end
  105. -- init here for title screen
  106. particleinit(150)
  107. function TIC()
  108. if btn(0) then y=y-1 end
  109. if btn(1) then y=y+1 end
  110. if btn(2) then x=x-1 end
  111. if btn(3) then x=x+1 end
  112. cls(0)
  113. particleupdate()
  114. particledraw()
  115. spr(1+t%60//30*2,x,y,14,3,0,0,2,2)
  116. print("HELLO WORLD!",84,84)
  117. t=t+1
  118. end
  119. -- <TILES>
  120. -- 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc
  121. -- 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c
  122. -- 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc
  123. -- 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c
  124. -- 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
  125. -- 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
  126. -- 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
  127. -- 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
  128. -- </TILES>
  129. -- <WAVES>
  130. -- 000:00000000ffffffff00000000ffffffff
  131. -- 001:0123456789abcdeffedcba9876543210
  132. -- 002:0123456789abcdef0123456789abcdef
  133. -- </WAVES>
  134. -- <SFX>
  135. -- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
  136. -- </SFX>
  137. -- <PALETTE>
  138. -- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
  139. -- </PALETTE>