AndrewofDoom

Untitled

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