AndrewofDoom

Untitled

Feb 14th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.65 KB | None | 0 0
  1.  
  2. --Main loop that begins once initShmup() is executed.
  3. if booleanInitScroll == true then
  4. if objectPlayer:isValid() then --Player Validity Check
  5. --Keep the play on the same X or y coordinate as the camera.
  6. if str_direcion == "h" then
  7. local posX = ship_central_camera.Position["x"]
  8. local constPos = ba.createVector(posX,objectPlayer.Position["y"],objectPlayer.Position["z"])
  9. objectPlayer.Position = constPos
  10. else --vertical mode
  11. local posY = ship_central_camera.Position["y"]
  12. local constPos = ba.createVector(objectPlayer.Position["x"],posY,objectPlayer.Position["z"])
  13. objectPlayer.Position = constPos
  14. end
  15. ft = ba.getFrametime(false)
  16.  
  17. --Horizontal Position Limit
  18. --AOD 2/13/13 Added Bounded Free Movement Mode.
  19.  
  20. if objectPlayer.Position["x"] > floatHLimit then
  21. local playPos = ba.createVector((floatHLimit - 1), objectPlayer.Position["y"], objectPlayer.Position["z"])
  22. objectPlayer.Position = playPos
  23. elseif objectPlayer.Position["x"] < floatHRLimit then
  24. local playPos = ba.createVector((floatHRLimit + 1), objectPlayer.Position["y"], objectPlayer.Position["z"])
  25. objectPlayer.Position = playPos
  26. end
  27. if bool_freeDepthMovement == true then
  28. if objectPlayer.Position["y"] < int_freeVertMoveUpperBound and objectPlayer.Position["y"] > int_freeVertMoveLowerBound then
  29. local temp = ba.createVector(ship_central_camera.Position["x"],objectPlayer.Position["y"],ship_central_camera.Position["z"])
  30. ship_central_camera.Position = temp
  31. if str_direction == "h" then
  32. floatHLimit = (ship_central_camera.Position["x"] + 155)
  33. floatVLimit = (ship_central_camera.Position["y"] + 88)
  34. floatFLimit = (ship_central_camera.Position["z"] + 155)
  35. floatHRLimit = (ship_central_camera.Position["x"] - 155)
  36. floatVRLimit = (ship_central_camera.Position["y"] - 88)
  37. floatFRLimit = (ship_central_camera.Position["z"] - 155)
  38. elseif str_direction == "v" then
  39. floatHLimit = (ship_central_camera.Position["x"] + 155)
  40. floatVLimit = (ship_central_camera.Position["y"] + 155)
  41. floatFLimit = (ship_central_camera.Position["z"] + 88)
  42. floatHRLimit = (ship_central_camera.Position["x"] - 155)
  43. floatVRLimit = (ship_central_camera.Position["y"] - 155)
  44. floatFRLimit = (ship_central_camera.Position["z"] - 88)
  45. end
  46. end
  47. end
  48.  
  49.  
  50.  
  51. --Vertical Position Limit
  52. --AOD 2/4/13 Added Bounded Free Movement Mode.
  53.  
  54. if objectPlayer.Position["y"] > floatVLimit then
  55. local playPos = ba.createVector(objectPlayer.Position["x"],(floatVLimit - 1), objectPlayer.Position["z"])
  56. objectPlayer.Position = playPos
  57. elseif objectPlayer.Position["y"] < floatVRLimit then
  58. local playPos = ba.createVector(objectPlayer.Position["x"],(floatVRLimit + 1), objectPlayer.Position["z"])
  59. objectPlayer.Position = playPos
  60. end
  61. if bool_freeVertMovement == true then
  62. if objectPlayer.Position["y"] < int_freeVertMoveUpperBound and objectPlayer.Position["y"] > int_freeVertMoveLowerBound then
  63. local temp = ba.createVector(ship_central_camera.Position["x"],objectPlayer.Position["y"],ship_central_camera.Position["z"])
  64. ship_central_camera.Position = temp
  65. --bounds are different based on scrolling mode.
  66. if str_direction == "h" then
  67. floatHLimit = (ship_central_camera.Position["x"] + 155)
  68. floatVLimit = (ship_central_camera.Position["y"] + 88)
  69. floatFLimit = (ship_central_camera.Position["z"] + 155)
  70. floatHRLimit = (ship_central_camera.Position["x"] - 155)
  71. floatVRLimit = (ship_central_camera.Position["y"] - 88)
  72. floatFRLimit = (ship_central_camera.Position["z"] - 155)
  73. elseif str_direction == "v" then
  74. floatHLimit = (ship_central_camera.Position["x"] + 155)
  75. floatVLimit = (ship_central_camera.Position["y"] + 155)
  76. floatFLimit = (ship_central_camera.Position["z"] + 88)
  77. floatHRLimit = (ship_central_camera.Position["x"] - 155)
  78. floatVRLimit = (ship_central_camera.Position["y"] - 155)
  79. floatFRLimit = (ship_central_camera.Position["z"] - 88)
  80. end
  81. end
  82. end
  83.  
  84. --Forward Position Limit
  85. --AOD 2/4/13 Added Bounded Free Movement Mode.
  86.  
  87. if objectPlayer.Position["z"] > floatFLimit then
  88. local playPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],(floatFLimit - 1))
  89. objectPlayer.Position = playPos
  90. elseif objectPlayer.Position["z"] < floatFRLimit then
  91. local playPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],(floatFRLimit + 1))
  92. objectPlayer.Position = playPos
  93. end
  94. if bool_freeHoriMovement == true then
  95. if objectPlayer.Position["z"] < int_freeHoriMoveUpperBound and objectPlayer.Position["z"] > int_freeHoriMoveLowerBound then
  96. local temp = ba.createVector(ship_central_camera.Position["x"],ship_central_camera.Position["y"],objectPlayer.Position["z"])
  97. ship_central_camera.Position = temp
  98. if str_direction == "h" then
  99. floatHLimit = (ship_central_camera.Position["x"] + 155)
  100. floatVLimit = (ship_central_camera.Position["y"] + 88)
  101. floatFLimit = (ship_central_camera.Position["z"] + 155)
  102. floatHRLimit = (ship_central_camera.Position["x"] - 155)
  103. floatVRLimit = (ship_central_camera.Position["y"] - 88)
  104. floatFRLimit = (ship_central_camera.Position["z"] - 155)
  105. elseif str_direction == "v" then
  106. floatHLimit = (ship_central_camera.Position["x"] + 155)
  107. floatVLimit = (ship_central_camera.Position["y"] + 155)
  108. floatFLimit = (ship_central_camera.Position["z"] + 88)
  109. floatHRLimit = (ship_central_camera.Position["x"] - 155)
  110. floatVRLimit = (ship_central_camera.Position["y"] - 155)
  111. floatFRLimit = (ship_central_camera.Position["z"] - 88)
  112. end
  113. end
  114. end
  115.  
  116. --AndrewofDoom's mod: addition of scrolling
  117. if booleanInitScroll == true then --double check to see if this still is really true.
  118.  
  119. --intSavedCamPosX = intSavedCamPosX + (floatScrollX*ft)
  120. --intSavedCamPosY = intSavedCamPosY + (floatScrollY*ft)
  121. --intSavedCamPosZ = intSavedCamPosZ + (floatScrollZ*ft)
  122. vectorCCameraPos = ba.createVector(ship_central_camera.Position["x"] + 250,ship_central_camera.Position["y"],ship_central_camera.Position["z"])
  123. objectCCamera:setPosition(vectorCCameraPos)
  124. gr.setCamera(objectCCamera)
  125. floatHLimit = floatHLimit + (floatScrollX*ft)
  126. floatVLimit = floatVLimit + (floatScrollY*ft)
  127. floatFLimit = floatFLimit + (floatScrollZ*ft)
  128. ---Set movement limits again for the rear. The original version makes the assumption that the player's postion will be along the origin and thus symmetrical, which will not be the case if the camera is scrolling.
  129. floatHRLimit = floatHRLimit + (floatScrollX*ft)
  130. floatVRLimit = floatVRLimit + (floatScrollY*ft)
  131. floatFRLimit = floatFRLimit + (floatScrollZ*ft)
  132.  
  133. --all scrolling related to slaved ships.
  134. if slaveShips ~= nil then
  135. for i=1,#slaveShips do
  136. local scrollS = slaveShips[i]
  137. if scrollS ~= nil then --If this ship is null, don't bother playing with it.
  138. local pos = scrollS.Position
  139. if slaveToX[i] == true then
  140. pos["x"] = pos["x"] + (floatScrollX*ft)
  141. end
  142. if slaveToY[i] == true then
  143. pos["y"] = pos["y"] + (floatScrollY*ft)
  144. end
  145. if slaveToZ[i] == true then
  146. pos["z"] = pos["z"] + (floatScrollZ*ft)
  147. end
  148. scrollS.Position = pos
  149. slaveShips[i] = scrollS
  150. end
  151. end
  152. end
  153.  
  154. ---enforce projectile positions relative to scrolling and cull offscreen projectiles firing from the player or targetting the player.
  155. local numWeps = #mn.Weapons
  156. for i=1,numWeps do
  157. local wep = mn.Weapons[i]
  158. local wPos = wep.Position
  159. if wep.Parent == hv.Player or wep.Target == hv.Player then
  160. --Check for out of bounds
  161. if (wPos["y"] > floatVLimit or wPos["y"] < floatVRLimit or wPos["z"] > floatFLimit or wPos["z"] < floatFRLimit or wPos["x"] > floatHLimit or wPos["x"] < floatHRLimit) and not(wep.Target == hv.Player and ((wep.Parent.Position["x"]+155) < hv.Player.Position["x"] or (wep.Parent.Position["x"]-155) > hv.Player.Position["x"])) then
  162. wep.LifeLeft = 0.0 --Terminate weapon
  163. end
  164. if wep.LifeLeft > 0 then
  165. --if still in bounds, apply scrolling.
  166.  
  167. wPos["x"] = wPos["x"] + (floatScrollX*ft)
  168. if wep.Parent == hv.Player then
  169. wPos["x"] = wPos["x"] + (floatScrollX*ft)
  170. wPos["y"] = wPos["y"] + (floatScrollY*ft)
  171. wPos["z"] = wPos["z"] + (floatScrollZ*ft)
  172. end
  173. wep.Position = wPos
  174. end
  175. end
  176. if wep.LifeLeft > 0 then --if this projectile is dead, then don't bother.
  177. --force these projectiles from these ships to have their scrolling force to player position and 0'd x component velocities.
  178. --May seem like an ugly O(n^2) algorithm, but this stuff is usually reserved for important enemies. Namely, bosses which are usually one, MAYBE two, in count.
  179. for j=1, #forcedProjShipsToPlayerAxis do
  180. if forcedProjShipsToPlayerAxis[j] ~= nil then --if there is no one here, then don't bother.
  181. if wep.Parent == forcedProjShipsToPlayerAxis[j] then
  182. local wepPos = ba.createVector(objectPlayer.Position["x"],wep.Position["y"],wep.Position["z"])
  183. wep.Position = wepPos
  184. local wepVel = ba.createVector(0,wep.Physics.Velocity["y"],wep.Physics.Velocity["z"])
  185. wep.Physics.Velocity = wepVel
  186. wep.Physics.VelocityDesired = wepVel
  187. wep.Physics.VelocityMax = wepVel
  188. local wepOrient = ba.createOrientation(wep.Orientation["p"],wep.Orientation["b"],0.0)
  189. wep.Orientation = wepOrient
  190. end
  191. end
  192. end
  193. end
  194. mn.Weapons[i] = wep --Apply weapon change
  195. end
  196.  
  197.  
  198. end
  199. --Force the player's "scroll speed" to be a minimum velocity because LOLCOLLISIONDETECTION requires at least one of the pair to have a velocity =/= 0
  200. local diffToApplyX = (floatScrollX*59*ft*(5/3))/(1-ft) --This equation is able to compensate for shitty computers. I've tested it at 20 FPS up to 60 FPS. If you get less than 20, you prolly shouldn't be playing this anyway.
  201. local diffToApplyY = (floatScrollY*59*ft*(5/3))/(1-ft)
  202. local diffToApplyZ = (floatScrollZ*59*ft*(5/3))/(1-ft)
  203. shmup_idle_pscroll_speed = ba.createVector((diffToApplyX),(diffToApplyY),(diffToApplyZ))
  204. local newSpeedX = objectPlayer.Physics.Velocity["x"] + diffToApplyX
  205. local newSpeedY = objectPlayer.Physics.Velocity["y"] + diffToApplyY
  206. local newSpeedZ = objectPlayer.Physics.Velocity["z"] + diffToApplyZ
  207. local play_Val = ba.createVector(newSpeedX,newSpeedY,newSpeedZ)
  208. objectPlayer.Physics.Velocity = play_Val
  209. objectPlayer.Physics.VelocityDesired = play_Val
  210.  
  211. --tilt the player model based on the vertical velocity of the ship wrt vertical scrolling.
  212. if tilt_model == nil then --should only happen once. Get the Ship for the external view
  213. tilt_model = mn.Ships['Tilter']
  214. ship_amount_tilted = 0
  215. if tilt_model ~= nil then
  216. tilt_model.CollisionGroups = 1
  217. end
  218. elseif isTilting then --if tilting mode is on, go to this.
  219. if tilt_model:isValid() then
  220. --first move the position of the model on top of the player.
  221. local newPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],objectPlayer.Position["z"])
  222. tilt_model.Position = newPos
  223.  
  224.  
  225. --Thruster strength
  226. if objectPlayer.Physics.Velocity["z"] > (shmup_idle_pscroll_speed["z"] + (0.75*objectPlayer.Physics.VelocityMax["z"])) then
  227. tilt_model.Physics.ForwardThrust = 1.0
  228. elseif objectPlayer.Physics.Velocity["z"] < (shmup_idle_pscroll_speed["z"] - (0.75*objectPlayer.Physics.VelocityMax["z"])) then
  229. tilt_model.Physics.ForwardThrust = 0.1
  230. else
  231. tilt_model.Physics.ForwardThrust = 0.5
  232. end
  233. --tilting amount
  234.  
  235. if (objectPlayer.Physics.Velocity["y"] > (shmup_idle_pscroll_speed["y"] + (0.5*objectPlayer.Physics.VelocityMax["y"])) or objectPlayer.Physics.Velocity["x"] > (shmup_idle_pscroll_speed["x"] + (0.5*objectPlayer.Physics.VelocityMax["x"]))) then
  236. if ship_amount_tilted < 1.0 then
  237. ship_amount_tilted = ship_amount_tilted + 1.5*ft
  238. local new_orient = ba.createOrientation(tilt_model.Orientation["p"],tilt_model.Orientation["b"] + (1.5*ft),tilt_model.Orientation["h"])
  239. tilt_model.Orientation = new_orient
  240. end
  241. elseif (objectPlayer.Physics.Velocity["y"] < (shmup_idle_pscroll_speed["y"] - (0.5*objectPlayer.Physics.VelocityMax["y"]) or objectPlayer.Physics.Velocity["x"] < (shmup_idle_pscroll_speed["x"] - (0.5*objectPlayer.Physics.VelocityMax["x"]))) then
  242. if ship_amount_tilted > -1.0 then
  243. ship_amount_tilted = ship_amount_tilted - 1.5*ft
  244. local new_orient = ba.createOrientation(tilt_model.Orientation["p"],tilt_model.Orientation["b"] - (1.5*ft),tilt_model.Orientation["h"])
  245. tilt_model.Orientation = new_orient
  246. end
  247. else
  248. if tilt_model.Orientation["b"] ~= 0.0 then --Player has stopped moving. Move the fighter to rest position.
  249. if (tilt_model.Orientation["b"] < 0.05 or tilt_model.Orientation["b"] > -0.05) then
  250. local new_orient = ba.createOrientation(tilt_model.Orientation["p"],0.0,tilt_model.Orientation["h"])
  251. tilt_model.Orientation = new_orient
  252. ship_amount_tilted = 0
  253. elseif tilt_model.Orientation["b"] > 0.05 then
  254. local new_orient = ba.createOrientation(tilt_model.Orientation["p"],tilt_model.Orientation["b"] - (1.5*ft),tilt_model.Orientation["h"])
  255. tilt_model.Orientation = new_orient
  256. ship_amount_tilted = ship_amount_tilted - 1.5*ft
  257. elseif tilt_model.Orientation["b"] < -0.05 then
  258. local new_orient = ba.createOrientation(tilt_model.Orientation["p"],tilt_model.Orientation["b"] + (1.5*ft),tilt_model.Orientation["h"])
  259. tilt_model.Orientation = new_orient
  260. ship_amount_tilted = ship_amount_tilted + 1.5*ft
  261. end
  262. end
  263. end
  264. end
  265. end
  266. end --Player Validity Check
  267. end
  268.  
  269.  
  270. --initializes all needed variables and then sets the camera. an object called Center MUST exist for it to start.
  271. --Next thing that MUST be done after calling this is to slave a Trip Line Trigger object called Center.
  272. function initShmup(str_direction)
  273. if str_direction == nil then --for backwards compatibility, it will default to horizontal
  274. str_direction = "h"
  275. end
  276. ship_central_camera = mn.Ships['Center'] --Look for a ship called Center to...well center the view on.
  277. objectPlayer = hv.Player
  278. if ship_central_camera ~= nil and ship_central_camera:isValid() then
  279. --These are the slaves to our scrolling system. Every ship and associated boolean must all be aligned to the same index!
  280. slaveShips = {}
  281. slaveToX = {}
  282. slaveToY = {}
  283. slaveToZ = {}
  284. forcedProjShipsToPlayerAxis = {}
  285. vect_zero_vel = ba.createVector(0,0,0)
  286.  
  287. ---Create 'blank' orientation
  288. ---these rotations are in RADIANS, not degrees.
  289.  
  290. if str_direction == "h" then
  291. orientationBlank = hv.Player.Orientation
  292. orientationBlank["p"] = 0
  293. orientationBlank["b"] = 0
  294. orientationBlank["h"] = -1.57
  295. intSavedCamPosX = ship_central_camera.Position["x"] + 250
  296. intSavedCamPosY = ship_central_camera.Position["y"]
  297. intSavedCamPosZ = ship_central_camera.Position["z"]
  298.  
  299. ---Set movement box limits
  300. floatHLimit = (ship_central_camera.Position["x"] + 155)
  301. floatVLimit = (ship_central_camera.Position["y"] + 88)
  302. floatFLimit = (ship_central_camera.Position["z"] + 155)
  303. --- Set movement limits again for the rear. The original version makes the assumption that the player's postion will be
  304. --- along the origin and thus symmetrical, which will not be the case if the camera is scrolling.
  305. floatHRLimit = (ship_central_camera.Position["x"] - 155)
  306. floatVRLimit = (ship_central_camera.Position["y"] - 88)
  307. floatFRLimit = (ship_central_camera.Position["z"] - 155)
  308. elseif str_direction == "v" then
  309. orientationBlank = hv.Player.Orientation
  310. orientationBlank["p"] = -1.57
  311. orientationBlank["b"] = 0
  312. orientationBlank["h"] = 0
  313. intSavedCamPosX = ship_central_camera.Position["x"]
  314. intSavedCamPosY = ship_central_camera.Position["y"] + 250
  315. intSavedCamPosZ = ship_central_camera.Position["z"]
  316.  
  317. ---Set movement box limits
  318. floatHLimit = (ship_central_camera.Position["x"] + 155)
  319. floatVLimit = (ship_central_camera.Position["y"] + 155)
  320. floatFLimit = (ship_central_camera.Position["z"] + 88)
  321. --- Set movement limits again for the rear. The original version makes the assumption that the player's postion will be
  322. --- along the origin and thus symmetrical, which will not be the case if the camera is scrolling.
  323. floatHRLimit = (ship_central_camera.Position["x"] - 155)
  324. floatVRLimit = (ship_central_camera.Position["y"] - 155)
  325. floatFRLimit = (ship_central_camera.Position["z"] - 88)
  326. else
  327. ba.error("Something went wrong in the init of the shmup.")
  328. end
  329.  
  330. ---Scroll rates for each axis
  331. floatScrollX = 0
  332. floatScrollY = 0
  333. floatScrollZ = 0
  334. shmup_idle_pscroll_speed = vect_zero_vel --just in case
  335. vectorCCameraPos = ba.createVector(intSavedCamPosX,intSavedCamPosY,intSavedCamPosZ)
  336. orientationCCamera = orientationBlank
  337.  
  338. --Use the player camera at the start and move it out of first person for a wonderful out-of-body experience.
  339. objectCCamera = gr.Cameras[1]
  340. objectCCamera:setPosition(vectorCCameraPos)
  341. objectCCamera:setOrientation(orientationBlank)
  342. ---Use the new chase camera
  343. gr.setCamera(objectCCamera)
  344. booleanInitScroll = true
  345. --Just in case the free move vars don't get initialized.
  346. bool_freeVertMovement = false
  347. int_freeVertMoveUpperBound = 0
  348. int_freeVertMoveLowerBound = 0
  349. bool_freeHoriMovement = false
  350. int_freeHoriMoveUpperBound = 0
  351. int_freeHoriMoveLowerBound = 0
  352. tilter() --turn on rotation model if availiable.
  353. else
  354. ba.error("No view was found to center on. Make sure there is a ship called Center to point the camera on.")
  355. end
  356. end
  357.  
  358. function tilter()
  359. isTilting = true
  360. end
  361.  
  362. function noTilter()
  363. isTilting = false
  364. end
  365.  
  366.  
  367. function fvm(int_vertupper,int_vertlower)
  368. floatScrollY = 0
  369. bool_freeVertMovement = true
  370. int_freeVertMoveUpperBound = int_vertupper
  371. int_freeVertMoveLowerBound = int_vertlower
  372. end
  373.  
  374. function dvm()
  375. bool_freeVertMovement = false
  376. int_freeVertMoveUpperBound = 0
  377. int_freeVertMoveLowerBound = 0
  378. end
  379.  
  380. function fhm(int_horiupper,int_horilower)
  381. floatScrollZ = 0
  382. bool_freeHoriMovement = true
  383. int_freeHoriMoveUpperBound = int_horiupper
  384. int_freeHoriMoveLowerBound = int_horilower
  385. end
  386.  
  387. function dhm()
  388. bool_freeHoriMovement = false
  389. int_freeHoriMoveUpperBound = 0
  390. int_freeHoriMoveLowerBound = 0
  391. end
  392.  
  393.  
  394. --Modifies the scroll speed of the camera on any axes a man desires..
  395. --Value is in meters/frame, but is converted to meters/60 frames by this function for use when it's multiplied by ba.getFrameTime in the main simulation loop.
  396. function setScrollSpeed(x,y,z)
  397. floatScrollX = (x*60)
  398. floatScrollY = (y*60)
  399. floatScrollZ = (z*60)
  400. end
  401.  
  402. --Sets the current Status of the camera scrolling. initShmup must be called first to avoid funny stuff from happening.
  403. --True turns it on, false to turn it off and resets the camera view to the player ship.
  404. function setSA(booleanSwitch)
  405. if booleanSwitch == true then
  406. vectorCCameraPos = ba.createVector((ship_central_camera.Position["x"]-250),ship_central_camera.Position["y"],ship_central_camera.Position["z"])
  407. objectCCamera:setPosition(vectorCCameraPos)
  408. gr.setCamera(objectCCamera)
  409.  
  410. --Do NOT assume the player's position hasn't changed, therefore reset the bounds.
  411. floatHLimit = ship_central_camera.Position["x"] + 30
  412. floatVLimit = ship_central_camera.Position["y"] + 88
  413. floatFLimit = ship_central_camera.Position["z"] + 160
  414. floatHRLimit = ship_central_camera.Position["x"] - 30
  415. floatVRLimit = ship_central_camera.Position["y"] - 90
  416. floatFRLimit = ship_central_camera.Position["z"] - 160
  417. --Everything's set. Time to start scrolling again.
  418. booleanInitScroll = true
  419. elseif booleanSwitch == false then
  420. --Disable camera and scrolling, probably for a cutscene or something of that matter.
  421. booleanInitScroll = false
  422. gr.setCamera()
  423. else
  424. --nothing
  425. end
  426. end
  427.  
  428. --This is specific to the player ship. Will slave the player ship to the right axes.
  429. function sp(player_name)
  430. sTSC(play_name,true,false,false) --Just call sTSC and fill what the player needs to be slaved to.
  431. end
  432.  
  433.  
  434. --Will cause the specified ship to be slaved to scrolling system and will move relative to the camera instead for the specified axes
  435. --Note that these ships still do not adhere to the boundary enclosure like the player is.
  436. function sTSC(shipToSlave,booleanSlaveXAxis,booleanSlaveYAxis,booleanSlaveZAxis)
  437. local toAdd = mn.Ships[shipToSlave]
  438. if toAdd ~= nil then --sanity check
  439. slaveShips[(#slaveShips+1)] = toAdd
  440. slaveToX[(#slaveToX+1)] = booleanSlaveXAxis
  441. slaveToY[(#slaveToY+1)] = booleanSlaveYAxis
  442. slaveToZ[(#slaveToZ+1)] = booleanSlaveZAxis
  443. end
  444. end
  445.  
  446. --removes a slaved ship.
  447. function rss(slavedShip)
  448. local toChange = mn.Ships[slavedShip]
  449. local intIndex = 0
  450. for i=1, #slaveShips do
  451. if slaveShips[i] == toChange then
  452. intIndex = i -- found the ship, assign the index and break out of the for loop.
  453. break
  454. end
  455. end
  456. if intIndex >= 1 then --if this number is >= 1 then I have found something.
  457. slaveShips[intIndex] = nil --this may be potentially dangerous, but any good man should always check for null when iterating an array.
  458. end
  459. end
  460.  
  461. --Forces this ships projectiles to be on the same axis on the player's (the x-axis)
  462. --Needs to be done before it starts shooting.
  463. --Seems to not work for now, as collision pairs are culled immediately because of it.
  464. function pgopx(pgopx_ship)
  465. local toAdd = mn.Ships[pgopx_ship]
  466. if toAdd ~= nil then
  467. forcedProjShipsToPlayerAxis[(#forcedProjShipsToPlayerAxis+1)] = toAdd
  468. end
  469. end
  470.  
  471. function enableScrollDebug()
  472. boolean_scroll_debug = true
  473. end
  474.  
  475. --Have the camera look at the player! true for yes, no to look back at the center of screen.
  476. function stareAtPlayer(boolean_face)
  477. if boolean_face == true then
  478. objectCCamera.Target = objectPlayer
  479. elseif boolean_face == false then
  480. objectCCamera.Target = mn.Ships['Center']
  481. if objectCCamera.Target == nil then
  482. ba.error("Center object does not exist!")
  483. end
  484. end
  485. end
  486.  
  487. --This function extend's the player's life count by one.
  488. function addLife()
  489. if plr_life_count == nil then
  490. if mn.SEXPVariables['plrLives'] ~= nil then
  491. plr_life_count = mn.SEXPVariables['plrLives']
  492. end
  493. --for i=1, #mn.SEXPVariables do
  494. -- if tostring(mn.SEXPVariables[i]) == "plrLives" then --Once we find the variable, it's time to break out.
  495. -- plr_life_count = mn.SEXPVariables[i]
  496. -- break
  497. -- end
  498. --end
  499. if plr_life_count == nil then --if still nil then there is no variable and we shall error the player out.
  500. ba.error("No sexpvariable handle named 'plrLives' could be found. Game will not function properly.")
  501. end
  502. end
  503. if plr_life_count ~= nil and plr_life_count:isValid() then
  504. plr_life_count.Value = plr_life_count.Value + 1
  505. end
  506. end
Advertisement
Add Comment
Please, Sign In to add comment