AndrewofDoom

Untitled

Sep 15th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.25 KB | None | 0 0
  1. --Main loop that begins once initShmup() is executed.
  2. if booleanInitScroll == true then
  3. if objectPlayer:isValid() then --Player Validity Check
  4. hv.Player.CollisionGroups = 1
  5. --Keep the play on the same X coordinate as the camera.
  6. local posX = ship_central_camera.Position["x"]
  7. local constPos = ba.createVector(posX,objectPlayer.Position["y"],objectPlayer.Position["z"])
  8. objectPlayer.Position = constPos
  9. ft = ba.getFrametime(false)
  10.  
  11. --Horizontal Position Limit
  12. if objectPlayer.Position["x"] > floatHLimit then
  13. local playPos = ba.createVector((floatHLimit - 1), objectPlayer.Position["y"], objectPlayer.Position["z"])
  14. objectPlayer.Position = playPos
  15. elseif objectPlayer.Position["x"] < floatHRLimit then
  16. local playPos = ba.createVector((floatHRLimit + 1), objectPlayer.Position["y"], objectPlayer.Position["z"])
  17. objectPlayer.Position = playPos
  18. end
  19.  
  20. --Vertical Position Limit
  21. if objectPlayer.Position["y"] > floatVLimit then
  22. local playPos = ba.createVector(objectPlayer.Position["x"],(floatVLimit - 1), objectPlayer.Position["z"])
  23. objectPlayer.Position = playPos
  24. elseif objectPlayer.Position["y"] < floatVRLimit then
  25. local playPos = ba.createVector(objectPlayer.Position["x"],(floatVRLimit + 1), objectPlayer.Position["z"])
  26. objectPlayer.Position = playPos
  27. end
  28.  
  29. --Forward Position Limit
  30.  
  31. if objectPlayer.Position["z"] > floatFLimit then
  32. local playPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],(floatFLimit - 1))
  33. objectPlayer.Position = playPos
  34. elseif objectPlayer.Position["z"] < floatFRLimit then
  35. local playPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],(floatFRLimit + 1))
  36. objectPlayer.Position = playPos
  37. end
  38.  
  39. --AndrewofDoom's mod: addition of scrolling
  40. if booleanInitScroll == true then --double check to see if this still is really true.
  41.  
  42. intSavedCamPosX = intSavedCamPosX + (floatScrollX*ft)
  43. intSavedCamPosY = intSavedCamPosY + (floatScrollY*ft)
  44. intSavedCamPosZ = intSavedCamPosZ + (floatScrollZ*ft)
  45. vectorCCameraPos = ba.createVector(intSavedCamPosX,intSavedCamPosY,intSavedCamPosZ)
  46. objectCCamera:setPosition(vectorCCameraPos)
  47. gr.setCamera(objectCCamera)
  48. floatHLimit = floatHLimit + (floatScrollX*ft)
  49. floatVLimit = floatVLimit + (floatScrollY*ft)
  50. floatFLimit = floatFLimit + (floatScrollZ*ft)
  51. ---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.
  52. floatHRLimit = floatHRLimit + (floatScrollX*ft)
  53. floatVRLimit = floatVRLimit + (floatScrollY*ft)
  54. floatFRLimit = floatFRLimit + (floatScrollZ*ft)
  55.  
  56. --all scrolling related to slaved ships.
  57. if slaveShips ~= nil then
  58. for i=1,#slaveShips do
  59. local scrollS = slaveShips[i]
  60. if scrollS ~= nil then --If this ship is null, don't bother playing with it.
  61. local pos = scrollS.Position
  62. if slaveToX[i] == true then
  63. pos["x"] = pos["x"] + (floatScrollX*ft)
  64. end
  65. if slaveToY[i] == true then
  66. pos["y"] = pos["y"] + (floatScrollY*ft)
  67. end
  68. if slaveToZ[i] == true then
  69. pos["z"] = pos["z"] + (floatScrollZ*ft)
  70. end
  71. scrollS.Position = pos
  72. slaveShips[i] = scrollS
  73. end
  74. end
  75. end
  76.  
  77. ---enforce projectile positions relative to scrolling and cull offscreen projectiles firing from the player or targetting the player.
  78. local numWeps = #mn.Weapons
  79. for i=1,numWeps do
  80. local wep = mn.Weapons[i]
  81. local wPos = wep.Position
  82. if wep.Parent == hv.Player or wep.Target == hv.Player then
  83. --Check for out of bounds
  84. if (wPos["y"] > floatVLimit or wPos["y"] < floatVRLimit or wPos["z"] > floatFLimit or wPos["z"] < floatFRLimit) and not(wep.Target == hv.Player and ((wep.Parent.Position["x"]+100) < hv.Player.Position["x"] or (wep.Parent.Position["x"]-100) > hv.Player.Position["x"])) then
  85. wep.LifeLeft = 0.0 --Terminate weapon
  86. end
  87. if wep.LifeLeft > 0 then
  88. --if still in bounds, apply scrolling.
  89.  
  90. wPos["x"] = wPos["x"] + (floatScrollX*ft)
  91. if wep.Parent == hv.Player then
  92. wPos["y"] = wPos["y"] + (floatScrollY*ft)
  93. wPos["z"] = wPos["z"] + (floatScrollZ*ft)
  94. end
  95. wep.Position = wPos
  96. end
  97. end
  98. if wep.LifeLeft > 0 then --if this projectile is dead, then don't bother.
  99. --force these projectiles from these ships to have their scrolling force to player position and 0'd x component velocities.
  100. --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.
  101. for j=1, #forcedProjShipsToPlayerAxis do
  102. if forcedProjShipsToPlayerAxis[j] ~= nil then --if there is no one here, then don't bother.
  103. if wep.Parent == forcedProjShipsToPlayerAxis[j] then
  104. local wepPos = ba.createVector(objectPlayer.Position["x"],wep.Position["y"],wep.Position["z"])
  105. wep.Position = wepPos
  106. local wepVel = ba.createVector(0,wep.Physics.Velocity["y"],wep.Physics.Velocity["z"])
  107. wep.Physics.Velocity = wepVel
  108. wep.Physics.VelocityDesired = wepVel
  109. wep.Physics.VelocityMax = wepVel
  110. local wepOrient = ba.createOrientation(wep.Orientation["p"],wep.Orientation["b"],0.0)
  111. wep.Orientation = wepOrient
  112. end
  113. end
  114. end
  115. end
  116. mn.Weapons[i] = wep --Apply weapon change
  117. end
  118.  
  119.  
  120. end
  121. --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
  122. 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.
  123. local diffToApplyY = (floatScrollY*59*ft*(5/3))/(1-ft)
  124. local diffToApplyZ = (floatScrollZ*59*ft*(5/3))/(1-ft)
  125. shmup_idle_pscroll_speed = ba.createVector((diffToApplyX),(diffToApplyY),(diffToApplyZ))
  126. local newSpeedX = objectPlayer.Physics.Velocity["x"] + diffToApplyX
  127. local newSpeedY = objectPlayer.Physics.Velocity["y"] + diffToApplyY
  128. local newSpeedZ = objectPlayer.Physics.Velocity["z"] + diffToApplyZ
  129. local play_Val = ba.createVector(newSpeedX,newSpeedY,newSpeedZ)
  130. objectPlayer.Physics.Velocity = play_Val
  131. --objectPlayer.Physics.VelocityDesired = play_Val
  132.  
  133.  
  134. --tilt the player model based on the vertical velocity of the ship wrt vertical scrolling.
  135. if tilt_model == nil then --should only happen once. Get the Subsystem for the "ship" model
  136. tilt_model = objectPlayer["hull"]
  137. else
  138. if tilt_model:isValid() then
  139. if objectPlayer.Velocity["y"] > (shmup_idle_pscroll_speed["y"] + (shmup_idle_pscroll_speed["y"]*0.05)) then
  140. tilt_model.Orientation["p"] = tilt_model.Orientation["p"] + (0.05*ft)
  141. elseif objectPlayer.Velocity["y"] < (shmup_idle_pscroll_speed["y"] - (shmup_idle_pscroll_speed["y"]*0.05)) then
  142. tilt_model.Orientation["p"] = tilt_model.Orientation["p"] - (0.05*ft)
  143. else
  144. --if player is not fast enough, return model to normal position
  145.  
  146. end
  147. else
  148. ba.error("Tilting model does not exist!")
  149. end
  150. end
  151. end --Player Validity Check
  152. end
Advertisement
Add Comment
Please, Sign In to add comment