AndrewofDoom

Untitled

Jul 1st, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.89 KB | None | 0 0
  1. #Global Hooks
  2.  
  3. $Simulation:
  4.  
  5. [
  6.  
  7. --Main loop that begins once initShmup() is executed.
  8. if booleanInitScroll == true then
  9. if objectPlayer:isValid() then --Player Validity Check
  10. ft = ba.getFrametime(false)
  11.  
  12. --Horizontal Position Limit
  13. if objectPlayer.Position["x"] > floatHLimit then
  14. local playPos = ba.createVector((floatHLimit - 1), objectPlayer.Position["y"], objectPlayer.Position["z"])
  15. objectPlayer.Position = playPos
  16. elseif objectPlayer.Position["x"] < floatHRLimit then
  17. local playPos = ba.createVector((floatHRLimit + 1), objectPlayer.Position["y"], objectPlayer.Position["z"])
  18. objectPlayer.Position = playPos
  19. end
  20.  
  21. --Vertical Position Limit
  22. if objectPlayer.Position["y"] > floatVLimit then
  23. local playPos = ba.createVector(objectPlayer.Position["x"],(floatVLimit - 1), objectPlayer.Position["z"])
  24. objectPlayer.Position = playPos
  25. elseif objectPlayer.Position["y"] < floatVRLimit then
  26. local playPos = ba.createVector(objectPlayer.Position["x"],(floatVRLimit + 1), objectPlayer.Position["z"])
  27. objectPlayer.Position = playPos
  28. end
  29.  
  30. --Forward Position Limit
  31.  
  32. if objectPlayer.Position["z"] > floatFLimit then
  33. local playPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],(floatFLimit - 1))
  34. objectPlayer.Position = playPos
  35. elseif objectPlayer.Position["z"] < floatFRLimit then
  36. local playPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],(floatFRLimit + 1))
  37. objectPlayer.Position = playPos
  38. end
  39.  
  40. --The ideal code that doesn't work...
  41. --local x = gr.getVectorFromCoords(vectorCurrentPos["x"],vectorCurrentPos["y"]) --Use the screen view to determine if the player is in bounds.
  42. --local lx,ly = x:getScreenCoords()
  43. --ba.error(type(x:getScreenCoords()))
  44. --if lx < 0 then
  45. -- x = gr.getVectorFromCoords(0,0)
  46. -- vectorCurrentPos["z"] = x["x"]+10
  47. --elseif lx > gr.getScreenWidth() then
  48. -- x = gr.getVectorFromCoords(gr.getScreenWidth(),0)
  49. -- vectorCurrentPos["z"] = x["x"]-10
  50. --else
  51. --Do nothing
  52. --end
  53. --if ly < 0 or ly == false then
  54. -- x = gr.getVectorFromCoords(0,0)
  55. -- vectorCurrentPos["y"] = x["y"]
  56. --elseif ly > gr.getScreenHeight() then
  57. -- x = gr.getVectorFromCoords(0,gr.getScreenHeight())
  58. -- vectorCurrentPos["y"] = x["y"]
  59. --else
  60. --nothing
  61. --end
  62.  
  63. --AndrewofDoom's mod: addition of scrolling
  64. if booleanInitScroll == true then --double check to see if this still is really true.
  65.  
  66. intSavedCamPosX = intSavedCamPosX + (floatScrollX*ft)
  67. intSavedCamPosY = intSavedCamPosY + (floatScrollY*ft)
  68. intSavedCamPosZ = intSavedCamPosZ + (floatScrollZ*ft)
  69. vectorCCameraPos = ba.createVector(intSavedCamPosX,intSavedCamPosY,intSavedCamPosZ)
  70. objectCCamera:setPosition(vectorCCameraPos)
  71. gr.setCamera(objectCCamera)
  72. floatHLimit = floatHLimit + (floatScrollX*ft)
  73. floatVLimit = floatVLimit + (floatScrollY*ft)
  74. floatFLimit = floatFLimit + (floatScrollZ*ft)
  75. ---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.
  76. floatHRLimit = floatHRLimit + (floatScrollX*ft)
  77. floatVRLimit = floatVRLimit + (floatScrollY*ft)
  78. floatFRLimit = floatFRLimit + (floatScrollZ*ft)
  79.  
  80. --all scrolling related to slaved ships.
  81. for i=1,#slaveShips do
  82. if slaveShips[i] ~= nil then
  83. local scrollS = slaveShips[i]
  84. if scrollS ~= nil then --If this ship is null, don't bother playing with it.
  85. local pos = scrollS.Position
  86. if slaveToX[i] == true then
  87. pos["x"] = pos["x"] + (floatScrollX*ft)
  88. end
  89. if slaveToY[i] == true then
  90. pos["y"] = pos["y"] + (floatScrollY*ft)
  91. end
  92. if slaveToZ[i] == true then
  93. pos["z"] = pos["z"] + (floatScrollZ*ft)
  94. end
  95. scrollS.Position = pos
  96. slaveShips[i] = scrollS
  97. end
  98. end
  99. end
  100.  
  101. ---enforce projectile positions relative to scrolling and cull offscreen projectiles firing from the player or targetting the player.
  102. local numWeps = #mn.Weapons
  103. for i=1,numWeps do
  104. local wep = mn.Weapons[i]
  105. local wPos = wep.Position
  106. if wep.Parent == hv.Player or wep.Target == hv.Player then
  107. --Check for out of bounds
  108. if wPos["y"] > floatVLimit or wPos["y"] < floatVRLimit or wPos["z"] > floatFLimit or wPos["z"] < floatFRLimit then
  109. wep.LifeLeft = 0.0 --Terminate weapon
  110. end
  111. if wep.LifeLeft > 0 then
  112. --if still in bounds, apply scrolling.
  113.  
  114. wPos["x"] = wPos["x"] + (floatScrollX*ft)
  115. if wep.Parent == hv.Player then
  116. wPos["y"] = wPos["y"] + (floatScrollY*ft)
  117. wPos["z"] = wPos["z"] + (floatScrollZ*ft)
  118. end
  119. wep.Position = wPos
  120. end
  121. end
  122. if wep.LifeLeft > 0 then --if this projectile is dead, then don't bother.
  123. --force these projectiles from these ships to have their scrolling force to player position and 0'd x component velocities.
  124. --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.
  125. for j=1, #forcedProjShipsToPlayerAxis do
  126. if forcedProjShipsToPlayerAxis[j] ~= nil then --if there is no one here, then don't bother.
  127. if wep.Parent == forcedProjShipsToPlayerAxis[j] then
  128. local wepPos = ba.createVector(wep.Position["x"],wep.Position["y"],objectPlayer.Position["z"])
  129. wep.Position = wepPos
  130. local wepVel = ba.createVector(0,wep.Physics.Velocity["y"],wep.Physics.Velocity["z"])
  131. wep.Physics.Velocity = wepVel
  132. wep.Physics.VelocityDesired = wepVel
  133. wep.Physics.VelocityMax = wepVel
  134. local wepOrient = ba.createOrientation(wep.Orientation["p"],wep.Orientation["b"],0)
  135. wep.Orientation = wepOrient
  136. end
  137. end
  138. end
  139. end
  140. mn.Weapons[i] = wep --Apply weapon change
  141. end
  142.  
  143.  
  144. end
  145. local fudge_factor = (5/3) --if somehow the speeds don't exactly line up, we'll need to adjust a tiny bit.
  146.  
  147. shmup_idle_pscroll_speed = ba.createVector((floatScrollX * fudge_factor),(floatScrollY * fudge_factor),(floatScrollZ * fudge_factor))
  148. local newSpeedX = objectPlayer.Physics.Velocity["x"] + (floatScrollX * fudge_factor)
  149. local newSpeedY = objectPlayer.Physics.Velocity["y"] + (floatScrollY * fudge_factor)
  150. local newSpeedZ = objectPlayer.Physics.Velocity["z"] + (floatScrollZ * fudge_factor)
  151. local play_Val = ba.createVector(newSpeedX,newSpeedY,newSpeedZ)
  152. objectPlayer.Physics.Velocity = play_Val
  153. objectPlayer.Physics.VelocityDesired = play_Val
  154. end --Player Validity Check
  155. end
  156.  
  157. --DO NOT CALL THIS IN FRED
  158. function fudge_lookup(float_val)
  159.  
  160. end
  161.  
  162. ]
  163.  
  164. #End
  165.  
  166. #Conditional Hooks
  167.  
  168. $State: GS_STATE_GAME_PLAY
  169.  
  170. $On Frame:
  171.  
  172. [
  173.  
  174. if booleanInitScroll == true then
  175. if boolean_scroll_debug == true then
  176. gr.setColor(255, 255, 255)
  177. gr.drawString("Player Speed X: " .. tostring(objectPlayer.Physics.Velocity["x"]), 10, 190)
  178. gr.drawString("Player Speed Y: " .. tostring(objectPlayer.Physics.Velocity["y"]), 10, 200)
  179. gr.drawString("Player Speed Z: " .. tostring(objectPlayer.Physics.Velocity["z"]), 10, 210)
  180. gr.drawString("Player Speed Z: " .. tostring(var_key_pressed), 10, 220)
  181. end
  182. end
  183.  
  184. --initializes all needed variables and then sets the camera. an object called Center MUST exist for it to start. Next thing that MUST be done is to slave the player ship first and then a Trip Line Trigger object at the origin.
  185. function initShmup()
  186. ship_central_camera = mn.Ships['Center'] --Look for a ship called Center to...well center the view on.
  187. objectPlayer = hv.Player
  188. if ship_central_camera ~= nil and ship_central_camera:isValid() then
  189. --These are the slaves to our scrolling system. Every ship and associated boolean must all be aligned to the same index!
  190. slaveShips = {}
  191. slaveToX = {}
  192. slaveToY = {}
  193. slaveToZ = {}
  194. forcedProjShipsToPlayerAxis = {}
  195.  
  196. ---Create 'blank' orientation
  197. ---these rotations are in RADIANS, not degrees.
  198. orientationBlank = hv.Player.Orientation
  199. orientationBlank["p"] = 0
  200. orientationBlank["b"] = 0
  201. orientationBlank["h"] = -1.57
  202. intSavedCamPosX = ship_central_camera.Position["x"] + 250
  203. intSavedCamPosY = ship_central_camera.Position["y"]
  204. intSavedCamPosZ = ship_central_camera.Position["z"]
  205.  
  206. ---Set movement box limits
  207. floatHLimit = (ship_central_camera.Position["x"] + 155)
  208. floatVLimit = (ship_central_camera.Position["y"] + 88)
  209. floatFLimit = (ship_central_camera.Position["z"] + 155)
  210. --- Set movement limits again for the rear. The original version makes the assumption that the player's postion will be
  211. --- along the origin and thus symmetrical, which will not be the case if the camera is scrolling.
  212. floatHRLimit = (ship_central_camera.Position["x"] - 155)
  213. floatVRLimit = (ship_central_camera.Position["y"] - 88)
  214. floatFRLimit = (ship_central_camera.Position["x"] - 155)
  215. ---Scroll rates for each axis
  216. floatScrollX = 0
  217. floatScrollY = 0
  218. floatScrollZ = 0
  219. shmup_idle_pscroll_speed = 0 --just in case
  220. vectorCCameraPos = ba.createVector(intSavedCamPosX,intSavedCamPosY,intSavedCamPosZ)
  221. orientationCCamera = orientationBlank
  222.  
  223. --Use the player camera at the start and move it out of first person for a wonderful out-of-body experience.
  224. objectCCamera = gr.Cameras[1]
  225. objectCCamera:setPosition(vectorCCameraPos)
  226. objectCCamera:setOrientation(orientationBlank)
  227. ---Use the new chase camera
  228. gr.setCamera(objectCCamera)
  229. booleanInitScroll = true
  230. else
  231. ba.error("No view was found to center on. Make sure there is a ship called Center to point the camera on.")
  232. end
  233. end
  234.  
  235. --Modifies the scroll speed of the camera on any axes a man desires..
  236. --Value is in meters/frame, but is converted to meters/60 frames by this function for use when it's multiplied by ba.getFrameTime.
  237. function setScrollSpeed(x,y,z)
  238. floatScrollX = (x*60)
  239. floatScrollY = (y*60)
  240. floatScrollZ = (z*60)
  241. end
  242.  
  243. --Sets the current Status of the camera scrolling. initShmup must be called first to avoid funny stuff from happening.
  244. --True turns it on, false to turn it off and rest the camera view to the player ship.
  245. function setScrollingActive(booleanSwitch)
  246. if booleanSwitch == true then
  247. vectorCCameraPos = ba.createVector((ship_central_camera.Position["x"]-250),ship_central_camera.Position["y"],ship_central_camera.Position["z"])
  248. objectCCamera:setPosition(vectorCCameraPos)
  249. gr.setCamera(objectCCamera)
  250.  
  251. --Do NOT assume the player's position hasn't changed, therefore reset the bounds.
  252. floatHLimit = ship_central_camera.Position["x"] + 30
  253. floatVLimit = ship_central_camera.Position["y"] + 88
  254. floatFLimit = ship_central_camera.Position["z"] + 160
  255. floatHRLimit = ship_central_camera.Position["x"] - 30
  256. floatVRLimit = ship_central_camera.Position["y"] - 90
  257. floatFRLimit = ship_central_camera.Position["z"] - 160
  258. --Everything's set. Time to start scrolling again.
  259. booleanInitScroll = true
  260. elseif booleanSwitch == false then
  261. --Disable camera and scrolling, probably for a cutscene or something of that matter.
  262. booleanInitScroll = false
  263. gr.setCamera()
  264. else
  265. --nothing
  266. end
  267. end
  268.  
  269.  
  270. --Will cause the specified ship to be slaved to scrolling system and will move relative to the camera instead for the specified axes
  271. --Note that these ships still do not adhere to the boundary enclosure like the player is.
  272. function sTSC(shipToSlave,booleanSlaveXAxis,booleanSlaveYAxis,booleanSlaveZAxis)
  273. local toAdd = mn.Ships[shipToSlave]
  274. if toAdd ~= nil then --sanity check
  275. slaveShips[(#slaveShips+1)] = toAdd
  276. slaveToX[(#slaveToX+1)] = booleanSlaveXAxis
  277. slaveToY[(#slaveToY+1)] = booleanSlaveYAxis
  278. slaveToZ[(#slaveToZ+1)] = booleanSlaveZAxis
  279. end
  280. end
  281.  
  282. --removes a slaved ship.
  283. function rss(slavedShip)
  284. local toChange = mn.Ships[slavedShip]
  285. local intIndex = 0
  286. for i=1, #slaveShips do
  287. if slaveShips[i] == toChange then
  288. intIndex = i -- found the ship, assign the index and break out of the for loop.
  289. break
  290. end
  291. end
  292. if intIndex >= 1 then --if this number is >= 1 then I have found something.
  293. slaveShips[intIndex] = nil --this may be potentially dangerous, but any good man should always check for null when iterating an array.
  294. end
  295. end
  296.  
  297. --Forces this ships projectiles to be on the same axis on the player's (the x-axis)
  298. --Needs to be done before it starts shooting.
  299. function pgopx(pgopx_ship)
  300. local toAdd = mn.Ships[pgopx_ship]
  301. if toAdd ~= nil then
  302. forcedProjShipsToPlayerAxis[(#forcedProjShipsToPlayerAxis+1)] = toAdd
  303. end
  304. end
  305.  
  306. --Have the camera look at the player! true for yes, no to look back at the center of screen.
  307. function stareAtPlayer(boolean_face)
  308. if boolean_face == true then
  309. objectCCamera.
  310. end
  311.  
  312. ]
  313.  
  314.  
  315. $On Death:
  316.  
  317. [
  318. local dyingShip = hv.Self
  319. if dyingShip == hv.Player then --Do not disable the scrolling system if it's not the player who's blowing up!!
  320. booleanInitScroll = false
  321. end
  322.  
  323. ]
  324.  
  325. $On Mission End:
  326. [
  327.  
  328. booleanInitScroll = false --force it off when a mission ends.
  329.  
  330. ]
  331.  
  332. #End
Advertisement
Add Comment
Please, Sign In to add comment