AndrewofDoom

Untitled

Jun 26th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. #Global Hooks
  2.  
  3. $Simulation:
  4.  
  5. [
  6. --Main loop that begins once initShmup() is executed.
  7. if booleanInitScroll == true then
  8. if objectPlayer:isValid() then --Player Validity Check
  9.  
  10. --Get Position and Orientation and Speed
  11. vectorCurrentPos = objectPlayer.Position
  12. vectorPlayerVelocity = objectPlayer.Physics.Velocity
  13.  
  14. --Horizontal Position Limit
  15. if objectPlayer.Position["x"] > floatHLimit then
  16. local playPos = ba.createVector((floatHLimit - 1), objectPlayer.Position["y"], objectPlayer.Position["z"])
  17. objectPlayer.Position = playPos
  18. elseif objectPlayer.Position["x"] < floatHRLimit then
  19. local playPos = ba.createVector((floatHRLimit + 1), objectPlayer.Position["y"], objectPlayer.Position["z"])
  20. objectPlayer.Position = playPos
  21. end
  22.  
  23. --Vertical Position Limit
  24. if objectPlayer.Position["y"] > floatVLimit then
  25. local playPos = ba.createVector(objectPlayer.Position["x"],(floatVLimit - 1), objectPlayer.Position["z"])
  26. objectPlayer.Position = playPos
  27. elseif objectPlayer.Position["y"] < floatVRLimit then
  28. local playPos = ba.createVector(objectPlayer.Position["x"],(floatVRLimit + 1), objectPlayer.Position["z"])
  29. objectPlayer.Position = playPos
  30. end
  31.  
  32. --Forward Position Limit
  33.  
  34. if objectPlayer.Position["z"] > floatFLimit then
  35. local playPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],(floatFLimit - 1))
  36. objectPlayer.Position = playPos
  37. elseif vectorCurrentPos["z"] < floatFRLimit then
  38. local playPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],(floatFRLimit + 1))
  39. objectPlayer.Position = playPos
  40. end
  41.  
  42.  
  43. forceOrient = ba.createOrientation(0,0,0)
  44. --Update Player Rotational Velocity, Position
  45. objectPlayer.Physics.Orientation = forceOrientation
  46.  
  47. --AndrewofDoom's mod: addition of scrolling
  48. if booleanInitScroll == true then --double check to see if this still is really true.
  49. ft = ba.getFrametime(false)
  50. intSavedCamPosX = intSavedCamPosX + (floatScrollX*ft)
  51. intSavedCamPosY = intSavedCamPosY + (floatScrollY*ft)
  52. intSavedCamPosZ = intSavedCamPosZ + (floatScrollZ*ft)
  53. vectorCCameraPos = ba.createVector(intSavedCamPosX,intSavedCamPosY,intSavedCamPosZ)
  54. objectCCamera:setPosition(vectorCCameraPos)
  55. floatHLimit = floatHLimit + (floatScrollX*ft)
  56. floatVLimit = floatVLimit + (floatScrollY*ft)
  57. floatFLimit = floatFLimit + (floatScrollZ*ft)
  58. ---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.
  59. floatHRLimit = floatHRLimit + (floatScrollX*ft)
  60. floatVRLimit = floatVRLimit + (floatScrollY*ft)
  61. floatFRLimit = floatFRLimit + (floatScrollZ*ft)
  62.  
  63. --all scrolling related to slaved ships.
  64. for i=1,#slaveShips do
  65. if slaveShips[i] ~= nil then
  66. local scrollS = slaveShips[i]
  67. if scrollS ~= nil then --If this ship is null, don't bother playing with it.
  68. local pos = scrollS.Position
  69. if slaveToX[i] == true then
  70. pos["x"] = pos["x"] + (floatScrollX*ft)
  71. end
  72. if slaveToY[i] == true then
  73. pos["y"] = pos["y"] + (floatScrollY*ft)
  74. end
  75. if slaveToZ[i] == true then
  76. pos["z"] = pos["z"] + (floatScrollZ*ft)
  77. end
  78. scrollS.Position = pos
  79. slaveShips[i] = scrollS
  80. end
  81. end
  82. end
  83.  
  84. ---enforce projectile positions relative to scrolling and cull offscreen projectiles.
  85. local numWeps = #mn.Weapons
  86. for i=1,numWeps do
  87. local wep = mn.Weapons[i]
  88. local wPos = wep.Position
  89. if wep.Parent == hv.Player or wep.Target == hv.Player then
  90. --Check for out of bounds
  91. if wPos["y"] > floatVLimit or wPos["y"] < floatVRLimit or wPos["z"] > floatFLimit or wPos["z"] < floatFRLimit then
  92. wep.LifeLeft = 0.0 --Terminate weapon
  93. end
  94. if wep.LifeLeft > 0 then
  95. --if still in bounds, apply scrolling.
  96. wPos["x"] = wPos["x"] + (floatScrollX*ft)
  97. wPos["y"] = wPos["y"] + (floatScrollY*ft)
  98. wPos["z"] = wPos["z"] + (floatScrollZ*ft)
  99. wep.Position = wPos
  100. end
  101. end
  102. if wep.LifeLeft > 0 then --if this projectile is dead, then don't bother.
  103. --force these projectiles from these ships to have their scrolling force to player position and 0'd x component velocities.
  104. --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.
  105. for j=1, #forcedProjShipsToPlayerAxis do
  106. if forcedProjShipsToPlayerAxis[j] ~= nil then --if there is no one here, then don't bother.
  107. if wep.Parent == forcedProjShipsToPlayerAxis[j] then
  108. local wepPos = ba.createVector(objectPlayer.Position["x"],wep.Position["y"],wep.Position["z"])
  109. wep.Position = wepPos
  110. local wepVel = ba.createVector(0,wep.Physics.Velocity["y"],wep.Physics.Velocity["z"])
  111. wep.Physics.Velocity = wepVel
  112. wep.Physics.VelocityDesired = wepVel
  113. wep.Physics.VelocityMax = wepVel
  114. local wepOrient = ba.createOrientation(wep.Orientation["p"],wep.Orientation["b"],0)
  115. wep.Orientation = wepOrient
  116. end
  117. end
  118. end
  119. end
  120. mn.Weapons[i] = wep --Apply weapon change
  121. end
  122.  
  123.  
  124. end
  125. end --Player Validity Check
  126. end
  127.  
  128. ]
  129.  
  130. #End
Advertisement
Add Comment
Please, Sign In to add comment