AndrewofDoom

Untitled

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