Advertisement
Berserk88

scr_convert_build_to_physical

Aug 11th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. /// @description Create the player ship and destroy the build objects
  2. // This script takes no inputs
  3.  
  4. // initialize owner, cannot be local var as other objects will access it
  5. owner = noone;
  6.  
  7.  
  8. // every type of build object need to be accounted for
  9.  
  10. // ship is the first thing that needs to be converted
  11. with (obj_build_ship) {
  12.  
  13. // create ship object
  14. inst = instance_create(x,y,obj_ship);
  15.  
  16. // this script is only used for the player ship
  17. inst.controller = HUMAN;
  18.  
  19. // player faction is 1, enemy is 2
  20. inst.faction = 1;
  21.  
  22. // set the ship sprite equal to the build ship sprite
  23. inst.sprite_index = sprite_index;
  24.  
  25. // assign this ship as owner for future converted objects
  26. other.owner = inst;
  27.  
  28. // destroy obj_build_ship
  29. instance_destroy();
  30. }
  31.  
  32. with (obj_build_block) {
  33.  
  34. // spawn object
  35. inst = instance_create(x,y,obj_block);
  36.  
  37. // get owner to pass through to new object
  38. owner = other.owner;
  39.  
  40. with(inst) {
  41.  
  42. // initialize scale
  43. image_xscale = other.image_xscale;
  44. image_yscale = other.image_yscale;
  45.  
  46. // assign object owner to the associated ship
  47. owner = other.owner;
  48.  
  49. // Set offsets, how far components are from the center of the ship
  50. X_offset = x-owner.x;
  51. Y_offset = y-owner.y;
  52.  
  53. // create physics fixture
  54. scr_add_fixture(1, owner);
  55. }
  56.  
  57. // destroy obj_build_block
  58. instance_destroy();
  59. }
  60.  
  61. with (obj_build_turbine) {
  62.  
  63. // spawn object
  64. inst = instance_create(x,y,obj_turbine);
  65.  
  66. // set owner to pass through to object
  67. owner = other.owner;
  68.  
  69. with(inst) {
  70.  
  71. // set owner to associated ship
  72. owner = other.owner;
  73.  
  74. // Set offsets, how far components are from the center of the ship
  75. X_offset = x-owner.x;
  76. Y_offset = y-owner.y;
  77.  
  78. // create physics fixture, turbines weigh more than blocks
  79. scr_add_fixture(3, owner);
  80.  
  81. // with obj_ship ------ this code is outdated, turbines no longer act like engines
  82. with(owner) {
  83.  
  84. // assign turbine a reference number
  85. other.engine_number = engine_count;
  86.  
  87. // add turbine to obj_ship's list of engines
  88. engine_array[engine_count] = other.id;
  89.  
  90. // increase obj_ship's engine count (starts at 0)
  91. engine_count += 1;
  92. }
  93. }
  94.  
  95. // destroy obj_build_turbine
  96. instance_destroy();
  97. }
  98.  
  99. with (obj_build_wind_catcher) {
  100.  
  101. // get owner to pass through to object
  102. owner = other.owner;
  103.  
  104. // spawn object
  105. inst = instance_create(x,y,obj_wind_catcher);
  106.  
  107. with(inst) {
  108.  
  109. // set owner to associated ship
  110. owner = other.owner;
  111.  
  112. // Set offsets, how far components are from the center of the ship
  113. X_offset = x-owner.x;
  114. Y_offset = y-owner.y;
  115.  
  116. // create physics fixture
  117. scr_add_fixture(1, owner);
  118. }
  119.  
  120. // destroy (obj_build_wind_catcher)
  121. instance_destroy();
  122. }
  123.  
  124. with (obj_build_rudder) {
  125.  
  126. // get owner to pass through to object
  127. owner = other.owner;
  128.  
  129. // spawn object
  130. inst = instance_create(x,y,obj_rudder);
  131.  
  132. with(inst) {
  133.  
  134. // set owner to associated ship
  135. owner = other.owner;
  136.  
  137. // Set offsets, how far components are from the center of the ship
  138. X_offset = x-owner.x;
  139. Y_offset = y-owner.y;
  140.  
  141. // create physics fixture
  142. scr_add_fixture(1, owner);
  143. }
  144.  
  145. // destroy obj_build_rudder
  146. instance_destroy();
  147. }
  148.  
  149. with (obj_build_slot_weapon_med) {
  150.  
  151. // get owner to pass through to object
  152. owner = other.owner;
  153.  
  154. // get sprite assigned to build slot, convert into map key, get associated object
  155. key = string_delete(sprite_get_name(sprite_index), 1, 4);
  156.  
  157.  
  158. // check if an item has been placed
  159. if (key != "build_slot_weapon_med") { // if no item has been chosen for slot then create nothing
  160.  
  161. /// the key serves as general reference, if you want the objects cost then add "_cost" to the key
  162. // example key_temp = "gun_med_2_object"
  163. key_temp = key + "_object";
  164.  
  165. // use the key to spawn corresponding object in weapon list
  166. inst = instance_create(x,y, global.weapon_info[? key_temp]);
  167.  
  168. // with the weapon
  169. with(inst) {
  170.  
  171. // other refers to the build_slot, assign gun to instance of obj_ship
  172. owner = other.owner;
  173.  
  174. /// all cannons have 'gun' within their key
  175. // if buildable is a gun then add to ship gun array
  176. if (string_pos("gun", other.key)) {
  177.  
  178. with(owner) {
  179.  
  180. // gun_count is total amount of guns generated for the ship
  181. // gun_number is this guns particular index value in the array of all guns
  182.  
  183. // assign gun a reference number
  184. other.gun_number = gun_count;
  185.  
  186. // update gun array
  187. gun_array[gun_count] = other.id;
  188.  
  189. // increase gun count, starts at 0
  190. gun_count += 1;
  191.  
  192. }
  193.  
  194. // these three values are currently redundant. They are overwritten in scr_gun_common_values
  195. home_angle = other.home_angle;
  196. max_angle = other.max_angle;
  197. current_angle = home_angle;
  198. }
  199.  
  200. // Set offsets, how far components are from the center of the ship
  201. X_offset = x-owner.x;
  202. Y_offset = y-owner.y;
  203.  
  204. // create physics fixture
  205. scr_add_fixture(3, owner);
  206. }
  207. }
  208.  
  209. // destroy build slot
  210. instance_destroy();
  211. }
  212.  
  213. instance_destroy();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement