AndrewofDoom

Untitled

Jul 5th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. #Conditional Hooks
  2.  
  3. $State: GS_STATE_GAME_PLAY
  4.  
  5. $On Frame:
  6.  
  7. [
  8.  
  9. --start collecting the position of the parent once the signal is received
  10. if int_position_record_index ~= nil then
  11. vect_option_parent_current_pos = ship_optionParent.Position
  12. if int_position_record_index == 0 then -- it was initialized
  13. int_position_record_index = 1
  14. local temp = ship_optionParent.Position
  15. for i=1, const_int_bufferLength do --fill the array with the player's current position so that there is not an empty buffer positions
  16. list_position_buffer[i] = temp
  17. end
  18. else
  19. --If the player is in "idle" position don't bother updating the buffer.
  20. if (vect_option_parent_current_pos["y"] ~= (vect_option_parent_previous_pos["y"] + (ba.getFrametime(false)*floatScrollY)) or vect_option_parent_current_pos["z"] ~= (vect_option_parent_previous_pos["z"] + (ba.getFrametime(false)*floatScrollZ))) then
  21. if ship_optionParent.Physics.Velocity["z"] ~= shmup_idle_pscroll_speed["z"] or ship_optionParent.Physics.Velocity["y"] ~= shmup_idle_pscroll_speed["y"] then
  22. list_position_buffer[int_position_record_index] = ship_optionParent.Position
  23. int_position_record_index = int_position_record_index + 1
  24. if int_position_record_index == #list_position_buffer then
  25. int_position_record_index = 1 --restart the buffer
  26. end
  27. end
  28. end
  29. end
  30.  
  31. if #list_options > 0 then --if the guy has no options, don't even bother.
  32.  
  33. for i=1, #list_options do
  34. assignment_vector = getOptionCoordinate(i*10)
  35. if assignment_vector ~= nil then
  36. --if the player isn't moving, don't update the option's position at all.
  37. if (vect_option_parent_current_pos["y"] ~= (vect_option_parent_previous_pos["y"] + (ba.getFrametime(false)*floatScrollY)) or vect_option_parent_current_pos["z"] ~= (vect_option_parent_previous_pos["z"] + (ba.getFrametime(false)*floatScrollZ))) then
  38. if ship_optionParent.Physics.Velocity["z"] ~= shmup_idle_pscroll_speed["z"] or ship_optionParent.Physics.Velocity["y"] ~= shmup_idle_pscroll_speed["y"] then
  39. assignment_vector["x"] = ship_optionParent.Position["x"] --make sure the options are on the same x position as the player at all times.
  40. list_options[i].Position = assignment_vector
  41. end
  42. end
  43.  
  44. end
  45. end
  46. end
  47. vect_option_parent_previous_pos = vect_option_parent_current_pos
  48. gr.setColor(255, 255, 255)
  49. gr.drawString("Options Fired: " .. tostring(boolean_option_fired), 10, 130)
  50. gr.drawString("O1: " .. tostring(getOptionCoordinate((1*30))), 10, 150)
  51. gr.drawString("O2: " .. tostring(getOptionCoordinate((2*30))), 10, 160)
  52. gr.drawString("O3: " .. tostring(getOptionCoordinate((3*30))), 10, 170)
  53. gr.drawString("O4: " .. tostring(getOptionCoordinate((4*30))), 10, 180)
  54. end
  55.  
  56. --starts the buffer for collecting the player position
  57. function startPosCollect()
  58. int_position_record_index = 0 --zero means not used yet signal.
  59. list_options = {} --blank array at the start of the mission.
  60. list_position_buffer = {} --blank array for storing parent positions
  61. ship_optionParent = hv.Player --Can be changed to anything you want, but the player is prolly the best person for this.
  62. const_int_bufferLength = (60*4) --4 seconds at 60 FPS
  63. vect_option_parent_current_pos = ship_optionParent.Position
  64. vect_option_parent_previous_pos = ship_optionParent.LastPosition
  65. vect_option_no_speed = ba.createVector(0,0,0)
  66. boolean_option_fired = false
  67. end
  68.  
  69. --adds option to the man's collection.
  70. function addOption(optionName)
  71. ship_option_to_add = mn.Ships[optionName]
  72. if ship_option_to_add ~= nil then
  73. list_options[#list_options+1] = ship_option_to_add
  74. end
  75. end
  76.  
  77. --Some bastard Option Hunter stole my option(s)!
  78. function removeOption(optionName)
  79. option_to_remove = mn.Ships[optionName]
  80. local index_to_nil = 0
  81. if option_to_remove ~= nil then
  82. for i=1,#list_options do
  83. if list_options[i] == option_to_remove then --break out once the option is found.
  84. index_to_nil = i
  85. list_options[i] = nil
  86. break
  87. end
  88. end
  89. --since the nasty Option Hunter steals everything down the chain it catches, we are only going to rebuild the array up until the index before the option was stolen.
  90. local temp_array = {}
  91. for i=1,index_to_nil do
  92. if i == index_to_nil then --just in case
  93. break
  94. else
  95. temp_array[i] = list_options[i]
  96. end
  97. end
  98. list_options = temp_array --reassign the new array to this.
  99. end
  100.  
  101. end
  102.  
  103. --DO NOT CALL THIS IN FRED.
  104. --helper function for the for loop in the $On Frame section.
  105. --Determines the position of option
  106. --Returns a vector of the position the option should be.
  107. function getOptionCoordinate(int_distance_p)
  108. local int_idx = 0
  109. int_idx = int_position_record_index - int_distance_p
  110. if int_idx < 0 then
  111. int_idx = int_idx + #list_position_buffer
  112. elseif int_idx > (#list_position_buffer-5) then
  113. int_idx = (#list_position_buffer-5)
  114. end
  115. return list_position_buffer[int_idx]
  116. end
  117.  
  118. ]
  119.  
  120. $On Weapon Fired:
  121.  
  122. [
  123.  
  124. if hv.User == ship_optionParent and #list_options > 0 then --be sure the person firing is the parent of the options and that there are options there.
  125. for i=1, #list_options do
  126. list_options[i]:firePrimary()
  127. end
  128. boolean_option_fired = true
  129. else
  130. boolean_option_fired = false
  131. end
  132.  
  133. ]
  134.  
  135.  
  136. $On Death:
  137.  
  138. [
  139. local dyingShip = hv.Self
  140. if dyingShip == hv.Player then --Do not disable the options if it's not the player who's blowing up!!
  141. int_position_record_index = nil
  142. end
  143.  
  144. ]
  145.  
  146. $On Mission End:
  147. [
  148.  
  149. int_position_record_index = nil --force it off when a mission ends.
  150.  
  151. ]
  152.  
  153. #End
Advertisement
Add Comment
Please, Sign In to add comment