DanielGalrito

Terraformer Ship (The Space Toy)

Aug 28th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. --Terraformer
  2. terraformer = elements.allocate("JosephMA", "TFRM");
  3. elements.element(terraformer, elements.element(elements.DEFAULT_PT_PROT));
  4. elements.property(terraformer, "HighTemperature", 1273.15);
  5. elements.property(terraformer, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  6. elements.property(terraformer, "Name", "TFRM");
  7. elements.property(terraformer, "Description", "Terraforming ship, makes planets more suitable for life.");
  8. elements.property(terraformer, "MenuSection", elem.SC_SPECIAL);
  9.  
  10. local function terraformerUpdate(i, x, y, s, n)
  11. --tmp is current team
  12. local life = tpt.get_property("life", i);
  13. if life == 0 then
  14. tpt.set_property("life", mothershipLife, i);
  15. life = mothershipLife;
  16. end
  17. local rand = math.random(1, 30);
  18. if rand <= 15 then
  19. for r in sim.neighbors(x,y,1,1) do
  20. local partType = sim.partProperty(r, "type");
  21. if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  22. sim.partKill(r);
  23. tpt.set_property("life", life - 1, i);
  24. life = life - 1;
  25. if life - 1 <= -1 then
  26. sim.partKill(i);
  27. return 1;
  28. end
  29. elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  30. tpt.set_property("life", life - 1, i);
  31. if life - 1 <= -1 then
  32. sim.partKill(i);
  33. return 1;
  34. end
  35. end
  36. end
  37. end
  38. --Movement
  39. if math.random(1, 100) == 1 then
  40. if math.random(1, 2) == 1 then
  41. tpt.set_property("vx", math.random(-1, 1), i);
  42. else
  43. tpt.set_property("vy", math.random(-1, 1), i);
  44. end
  45. end
  46. --Shooting
  47. if math.random(1, 50) == 1 then
  48. for r in sim.neighbors(x,y,10,10) do
  49. local partType = sim.partProperty(r, "type");
  50. local partcType = sim.partProperty(r, "ctype");
  51. local tmp = tpt.get_property("tmp", i);
  52. if partType == rock and sim.partProperty(r, "temp") < 400 then
  53. sim.partChangeType(r, continent);
  54. sim.partProperty(r, "tmp", tmp);
  55. sim.partProperty(r, "tmp2", 1);
  56. end
  57. if partType == desert and sim.partProperty(r, "temp") < 400 then
  58. sim.partChangeType(r, ocean);
  59. end
  60. if partType == rock or partType == desert or partcType == rock or partcType == desert and sim.partProperty(r, "temp") > 400 and sim.partProperty(r, "temp") < 3273 then
  61. sim.partProperty(r, "temp", sim.partProperty(r, "temp")-500);
  62. end
  63. end
  64. end
  65. end
  66.  
  67. elements.property(terraformer, "Update", terraformerUpdate);
  68.  
  69. local function terraformerGraphics(i, colr, colg, colb)
  70. local r;
  71. local g;
  72. local b;
  73. local tmp = tpt.get_property("tmp", i);
  74. if tmp == 0 then
  75. r = 255;
  76. g = 0;
  77. b = 0;
  78. elseif tmp == 1 then
  79. r = 0;
  80. g = 255;
  81. b = 0;
  82. elseif tmp == 2 then
  83. r = 0;
  84. g = 0;
  85. b = 255;
  86. elseif tmp == 3 then
  87. r = 255;
  88. g = 204;
  89. b = 0;
  90. elseif tmp == 4 then
  91. r = 255;
  92. g = 255;
  93. b = 255;
  94. elseif tmp == 5 then
  95. r = 153;
  96. g = 153;
  97. b = 153;
  98. end
  99. -- local x = tpt.get_property("x",i);
  100. -- local y = tpt.get_property("y",i);
  101. -- graphics.fillRect(x - 4, y - 4, 9, 9, r, g, b);
  102. end
  103.  
  104. elements.property(terraformer, "Graphics", terraformerGraphics);
Advertisement
Add Comment
Please, Sign In to add comment