Guest User

Untitled

a guest
Oct 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 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. PT_CD()
  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. if tpt.get_property("type", centerpt) == 116 then reset_moving() end
  25. end
  26.  
  27. function add_particle(CDx, CDy)
  28. if tpt.get_property("type", CDx, CDy - 1) == 1 then add_particle_sub(CDx, CDy - 1) end
  29. if tpt.get_property("type", CDx + 1, CDy - 1) == 1 then add_particle_sub(CDx + 1, CDy - 1) end
  30. if tpt.get_property("type", CDx + 1, CDy) == 1 then add_particle_sub(CDx + 1, CDy) end
  31. if tpt.get_property("type", CDx + 1, CDy + 1) == 1 then add_particle_sub(CDx + 1, CDy + 1) end
  32. if tpt.get_property("type", CDx, CDy + 1) == 1 then add_particle_sub(CDx, CDy + 1) end
  33. if tpt.get_property("type", CDx - 1, CDy + 1) == 1 then add_particle_sub(CDx - 1, CDy + 1) end
  34. if tpt.get_property("type", CDx - 1, CDy) == 1 then add_particle_sub(CDx - 1, CDy) end
  35. if tpt.get_property("type", CDx - 1, CDy - 1) == 1 then add_particle_sub(CDx - 1, CDy - 1) end
  36. if tpt.get_property("type", CDx, CDy) == 102 then tpt.drawpixel(CDx, CDy, 0, 192, 127, 127) end
  37. end
  38.  
  39. function PT_CD()
  40. if x ~= tpt.get_property("x", centerpt) then
  41. if y ~= tpt.get_property("y", centerpt) then
  42. errors = 0
  43. if rindex > 0 then
  44. for tmpid = 1, rindex, 1 do
  45. CDx = x - mvrx[tmpid]
  46. CDy = y - mvry[tmpid]
  47. if tpt.get_property("type", CDx, CDy - 1) ~= 0 then if tpt.get_property("type", CDx, CDy - 1) ~= 102 then errors = 1 end end
  48. if tpt.get_property("type", CDx + 1, CDy - 1) ~= 0 then if tpt.get_property("type", CDx + 1, CDy - 1) ~= 102 then errors = 1 end end
  49. if tpt.get_property("type", CDx + 1, CDy) ~= 0 then if tpt.get_property("type", CDx + 1, CDy) ~= 102 then errors = 1 end end
  50. if tpt.get_property("type", CDx + 1, CDy + 1) ~= 0 then if tpt.get_property("type", CDx + 1, CDy + 1) ~= 102 then errors = 1 end end
  51. if tpt.get_property("type", CDx, CDy + 1) ~= 0 then if tpt.get_property("type", CDx, CDy + 1) ~= 102 then errors = 1 end end
  52. if tpt.get_property("type", CDx - 1, CDy + 1) ~= 0 then if tpt.get_property("type", CDx - 1, CDy + 1) ~= 102 then errors = 1 end end
  53. if tpt.get_property("type", CDx - 1, CDy) ~= 0 then if tpt.get_property("type", CDx - 1, CDy) ~= 102 then errors = 1 end end
  54. if tpt.get_property("type", CDx - 1, CDy - 1) ~= 0 then if tpt.get_property("type", CDx - 1, CDy - 1) ~= 102 then errors = 1 end end
  55. end
  56. end
  57. if errors == 1 then tpt.set_property("x", x, centerpt) tpt.set_property("y", y, centerpt) updatevars() end
  58. end
  59. end
  60. end
  61.  
  62. function add_particle_sub(apx, apy)
  63. rindex = rindex + 1
  64. tpt.delete(apx, apy)
  65. mvid[rindex] = tpt.create(apx, apy, "grav")
  66. mvrx[rindex] = x - apx
  67. mvry[rindex] = y - apy
  68. end
  69.  
  70. function reset_moving()
  71. if rindex > 0 then
  72. for tmpid = 1, rindex, 1 do
  73. tpt.delete(tmpid)
  74. end
  75. rindex = 0
  76. end
  77. tpt.unregister_step(particles)
  78. tpt.register_mouseevent(click)
  79. end
  80.  
  81. function click(x, y)
  82. if tpt.get_property("type",x, y) == 1 then
  83. tpt.delete(x, y)
  84. -- Setting up
  85. centerpt = tpt.create(x, y, "grav")
  86.  
  87. mvid={}
  88. mvrx={}
  89. mvry={}
  90.  
  91. rindex=0
  92. updatevars()
  93. -- Setup Complete!
  94. tpt.register_step(particles)
  95. tpt.unregister_mouseevent(click)
  96. end
  97. end
  98.  
  99. tpt.register_mouseevent(click)
Add Comment
Please, Sign In to add comment