Guest User

Untitled

a guest
Oct 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. mvid={}
  2. mvrx={}
  3. mvry={}
  4.  
  5. rindex=0
  6.  
  7. function updatevars()
  8. x = tpt.get_property("x", centerpt)
  9. y = tpt.get_property("y", centerpt)
  10. end
  11.  
  12. function particles()
  13. updatevars()
  14. add_particle(x,y)
  15. if rindex > 0 then
  16. for tmpid = 1, rindex, 1 do
  17. add_particle(x - mvrx[tmpid], y - mvry[tmpid])
  18. tpt.set_property("x", x - mvrx[tmpid], mvid[tmpid])
  19. tpt.set_property("y", y - mvry[tmpid], mvid[tmpid])
  20. tpt.set_property("vx", tpt.get_property("vx", centerpt), mvid[tmpid])
  21. tpt.set_property("vy", tpt.get_property("vy", centerpt), mvid[tmpid])
  22. end
  23. end
  24. end
  25.  
  26. function add_particle(CDx, CDy)
  27. if tpt.get_property("type", CDx, CDy - 1) == 1 then add_particle_sub(CDx, CDy - 1) end
  28. if tpt.get_property("type", CDx + 1, CDy - 1) == 1 then add_particle_sub(CDx + 1, CDy - 1) end
  29. if tpt.get_property("type", CDx + 1, CDy) == 1 then add_particle_sub(CDx + 1, CDy) end
  30. if tpt.get_property("type", CDx + 1, CDy + 1) == 1 then add_particle_sub(CDx + 1, CDy + 1) end
  31. if tpt.get_property("type", CDx, CDy + 1) == 1 then add_particle_sub(CDx, CDy + 1) end
  32. if tpt.get_property("type", CDx - 1, CDy + 1) == 1 then add_particle_sub(CDx - 1, CDy + 1) end
  33. if tpt.get_property("type", CDx - 1, CDy) == 1 then add_particle_sub(CDx - 1, CDy) end
  34. if tpt.get_property("type", CDx - 1, CDy - 1) == 1 then add_particle_sub(CDx - 1, CDy - 1) end
  35. tpt.drawpixel(CDx, CDy, 0, 192, 127, 127)
  36. end
  37.  
  38. function add_particle_sub(apx, apy)
  39. rindex = rindex + 1
  40. tpt.delete(apx, apy)
  41. mvid[rindex] = tpt.create(apx, apy, "grav")
  42. mvrx[rindex] = x - apx
  43. mvry[rindex] = y - apy
  44. end
  45.  
  46. function reset_moving()
  47. if rindex > 0 then
  48. for tmpid = 1, rindex, 1 do
  49. tpt.delete(tmpid)
  50. end
  51. rindex = 0
  52. end
  53. tpt.unregister_step(particles)
  54. tpt.register_mouseevent(click)
  55. end
  56.  
  57. function click(x, y)
  58. if tpt.get_property("type",x, y) == 1 then
  59. tpt.delete(x, y)
  60. -- Setting up
  61. centerpt = tpt.create(x, y, "grav")
  62.  
  63. mvid={}
  64. mvrx={}
  65. mvry={}
  66.  
  67. rindex=0
  68. updatevars()
  69. -- Setup Complete!
  70. tpt.register_step(particles)
  71. tpt.unregister_mouseevent(click)
  72. end
  73. end
  74.  
  75. tpt.register_mouseevent(click)
Add Comment
Please, Sign In to add comment