particles.lua 3.5 KB

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