AndrewofDoom

Scroll scripte version watever

Jul 1st, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.72 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. wPos["x"] = wPos["x"] + (floatScrollX*ft)
  114. wPos["y"] = wPos["y"] + (floatScrollY*ft)
  115. wPos["z"] = wPos["z"] + (floatScrollZ*ft)
  116. wep.Position = wPos
  117. end
  118. end
  119. if wep.LifeLeft > 0 then --if this projectile is dead, then don't bother.
  120. --force these projectiles from these ships to have their scrolling force to player position and 0'd x component velocities.
  121. --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.
  122. for j=1, #forcedProjShipsToPlayerAxis do
  123. if forcedProjShipsToPlayerAxis[j] ~= nil then --if there is no one here, then don't bother.
  124. if wep.Parent == forcedProjShipsToPlayerAxis[j] then
  125. local wepPos = ba.createVector(wep.Position["x"],wep.Position["y"],objectPlayer.Position["z"])
  126. wep.Position = wepPos
  127. local wepVel = ba.createVector(wep.Physics.Velocity["x"],wep.Physics.Velocity["y"],0)
  128. wep.Physics.Velocity = wepVel
  129. wep.Physics.VelocityDesired = wepVel
  130. wep.Physics.VelocityMax = wepVel
  131. local wepOrient = ba.createOrientation(wep.Orientation["p"],wep.Orientation["b"],-1.57)
  132. wep.Orientation = wepOrient
  133. end
  134. end
  135. end
  136. end
  137. mn.Weapons[i] = wep --Apply weapon change
  138. end
  139.  
  140.  
  141. end
  142. local fudge_factor = (1/ft) --if somehow the speeds don't exactly line up, we'll need to adjust a tiny bit.
  143.  
  144. shmup_idle_pscroll_speed = ba.createVector((floatScrollX * fudge_factor),(floatScrollY * fudge_factor),(floatScrollZ * fudge_factor))
  145. local newSpeedX = objectPlayer.Physics.Velocity["x"] + (floatScrollX * fudge_factor)
  146. local newSpeedY = objectPlayer.Physics.Velocity["y"] + (floatScrollY * fudge_factor)
  147. local newSpeedZ = objectPlayer.Physics.Velocity["z"] + (floatScrollZ * fudge_factor)
  148. local play_Val = ba.createVector(newSpeedX,newSpeedY,newSpeedZ)
  149. objectPlayer.Physics.Velocity = play_Val
  150. objectPlayer.Physics.VelocityDesired = play_Val
  151. end --Player Validity Check
  152. end
  153.  
  154. ]
  155.  
  156. #End
  157.  
  158. #Conditional Hooks
  159.  
  160. $State: GS_STATE_GAME_PLAY
  161.  
  162. $On Frame:
  163.  
  164. [
  165.  
  166. if booleanInitScroll == true then
  167. gr.setColor(255, 255, 255)
  168. gr.drawString("Player Speed X: " .. tostring(objectPlayer.Physics.Velocity["x"]), 10, 190)
  169. gr.drawString("Player Speed Y: " .. tostring(objectPlayer.Physics.Velocity["y"]), 10, 200)
  170. gr.drawString("Player Speed Z: " .. tostring(objectPlayer.Physics.Velocity["z"]), 10, 210)
  171. gr.drawString("Player Speed Z: " .. tostring(var_key_pressed), 10, 220)
  172. end
  173.  
  174. --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.
  175. function initShmup()
  176. ship_central_camera = mn.Ships['Center'] --Look for a ship called Center to...well center the view on.
  177. objectPlayer = hv.Player
  178. if ship_central_camera ~= nil and ship_central_camera:isValid() then
  179. --These are the slaves to our scrolling system. Every ship and associated boolean must all be aligned to the same index!
  180. slaveShips = {}
  181. slaveToX = {}
  182. slaveToY = {}
  183. slaveToZ = {}
  184. forcedProjShipsToPlayerAxis = {}
  185.  
  186. ---Create 'blank' orientation
  187. ---these rotations are in RADIANS, not degrees.
  188. orientationBlank = hv.Player.Orientation
  189. orientationBlank["p"] = 0
  190. orientationBlank["b"] = 0
  191. orientationBlank["h"] = -1.57
  192. intSavedCamPosX = ship_central_camera.Position["x"] + 250
  193. intSavedCamPosY = ship_central_camera.Position["y"]
  194. intSavedCamPosZ = ship_central_camera.Position["z"]
  195.  
  196. ---Set movement box limits
  197. floatHLimit = (ship_central_camera.Position["x"] + 155)
  198. floatVLimit = (ship_central_camera.Position["y"] + 88)
  199. floatFLimit = (ship_central_camera.Position["z"] + 155)
  200. --- Set movement limits again for the rear. The original version makes the assumption that the player's postion will be
  201. --- along the origin and thus symmetrical, which will not be the case if the camera is scrolling.
  202. floatHRLimit = (ship_central_camera.Position["x"] - 155)
  203. floatVRLimit = (ship_central_camera.Position["y"] - 88)
  204. floatFRLimit = (ship_central_camera.Position["x"] - 155)
  205. ---Scroll rates for each axis
  206. floatScrollX = 0
  207. floatScrollY = 0
  208. floatScrollZ = 0
  209. shmup_idle_pscroll_speed = 0 --just in case
  210. vectorCCameraPos = ba.createVector(intSavedCamPosX,intSavedCamPosY,intSavedCamPosZ)
  211. orientationCCamera = orientationBlank
  212.  
  213. --Use the player camera at the start and move it out of first person for a wonderful out-of-body experience.
  214. objectCCamera = gr.Cameras[1]
  215. objectCCamera:setPosition(vectorCCameraPos)
  216. objectCCamera:setOrientation(orientationBlank)
  217. ---Use the new chase camera
  218. gr.setCamera(objectCCamera)
  219. booleanInitScroll = true
  220. else
  221. ba.error("No view was found to center on. Make sure there is a ship called Center to point the camera on.")
  222. end
  223. end
  224.  
  225. --Modifies the scroll speed of the camera on any axes a man desires..
  226. --Value is in meters/frame, but is converted to meters/60 frames by this function for use when it's multiplied by ba.getFrameTime.
  227. function setScrollSpeed(x,y,z)
  228. floatScrollX = (x*60)
  229. floatScrollY = (y*60)
  230. floatScrollZ = (z*60)
  231. end
  232.  
  233. --Sets the current Status of the camera scrolling. initShmup must be called first to avoid funny stuff from happening.
  234. --True turns it on, false to turn it off and rest the camera view to the player ship.
  235. function setScrollingActive(booleanSwitch)
  236. if booleanSwitch == true then
  237. vectorCCameraPos = ba.createVector((ship_central_camera.Position["x"]-250),ship_central_camera.Position["y"],ship_central_camera.Position["z"])
  238. objectCCamera:setPosition(vectorCCameraPos)
  239. gr.setCamera(objectCCamera)
  240.  
  241. --Do NOT assume the player's position hasn't changed, therefore reset the bounds.
  242. floatHLimit = ship_central_camera.Position["x"] + 30
  243. floatVLimit = ship_central_camera.Position["y"] + 88
  244. floatFLimit = ship_central_camera.Position["z"] + 160
  245. floatHRLimit = ship_central_camera.Position["x"] - 30
  246. floatVRLimit = ship_central_camera.Position["y"] - 90
  247. floatFRLimit = ship_central_camera.Position["z"] - 160
  248. --Everything's set. Time to start scrolling again.
  249. booleanInitScroll = true
  250. elseif booleanSwitch == false then
  251. --Disable camera and scrolling, probably for a cutscene or something of that matter.
  252. booleanInitScroll = false
  253. gr.setCamera()
  254. else
  255. --nothing
  256. end
  257. end
  258.  
  259.  
  260. --Will cause the specified ship to be slaved to scrolling system and will move relative to the camera instead for the specified axes
  261. --Note that these ships still do not adhere to the boundary enclosure like the player is.
  262. function sTSC(shipToSlave,booleanSlaveXAxis,booleanSlaveYAxis,booleanSlaveZAxis)
  263. local toAdd = mn.Ships[shipToSlave]
  264. if toAdd ~= nil then --sanity check
  265. slaveShips[(#slaveShips+1)] = toAdd
  266. slaveToX[(#slaveToX+1)] = booleanSlaveXAxis
  267. slaveToY[(#slaveToY+1)] = booleanSlaveYAxis
  268. slaveToZ[(#slaveToZ+1)] = booleanSlaveZAxis
  269. end
  270. end
  271.  
  272. --removes a slaved ship.
  273. function rss(slavedShip)
  274. local toChange = mn.Ships[slavedShip]
  275. local intIndex = 0
  276. for i=1, #slaveShips do
  277. if slaveShips[i] == toChange then
  278. intIndex = i -- found the ship, assign the index and break out of the for loop.
  279. break
  280. end
  281. end
  282. if intIndex >= 1 then --if this number is >= 1 then I have found something.
  283. slaveShips[intIndex] = nil --this may be potentially dangerous, but any good man should always check for null when iterating an array.
  284. end
  285. end
  286.  
  287. --Forces this ships projectiles to be on the same axis on the player's (the x-axis)
  288. --Needs to be done before it starts shooting.
  289. function pgopx(pgopx_ship)
  290. local toAdd = mn.Ships[pgopx_ship]
  291. if toAdd ~= nil then
  292. forcedProjShipsToPlayerAxis[(#forcedProjShipsToPlayerAxis+1)] = toAdd
  293. end
  294. end
  295.  
  296. --Have the camera look at the player! true for yes, no to look back at the center of screen.
  297. function stareAtPlayer(boolean_face)
  298. boolean_shmup_cam_face_player = boolean_face
  299. end
  300.  
  301. ]
  302.  
  303.  
  304. $On Death:
  305.  
  306. [
  307. local dyingShip = hv.Self
  308. if dyingShip == hv.Player then --Do not disable the scrolling system if it's not the player who's blowing up!!
  309. booleanInitScroll = false
  310. end
  311.  
  312. ]
  313.  
  314. $On Mission End:
  315. [
  316.  
  317. booleanInitScroll = false --force it off when a mission ends.
  318.  
  319. ]
  320.  
  321. #End
Advertisement
Add Comment
Please, Sign In to add comment