Advertisement
AndrewofDoom

Untitled

Jun 22nd, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 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. -- x = gr.getVectorFromCoords(0,0)
  37. -- vectorCurrentPos["z"] = x["x"]+10
  38. objectPlayer:kill(objectPlayer)
  39. elseif vectorCurrentPos["z"] < floatFRLimit then
  40. vectorPlayerVelocity["z"] = 300
  41. objectPlayer:kill(objectPlayer)
  42. end
  43.  
  44.  
  45.  
  46. --Update Player Rotational Velocity, Position
  47. objectPlayer.Physics.Velocity = vectorPlayerVelocity
  48.  
  49. --The ideal code that doesn't work...
  50. --local x = gr.getVectorFromCoords(vectorCurrentPos["x"],vectorCurrentPos["y"])
  51. --local lx,ly = x:getScreenCoords()
  52. --ba.error(type(x:getScreenCoords()))
  53. --if lx < 0 then
  54. -- x = gr.getVectorFromCoords(0,0)
  55. -- vectorCurrentPos["z"] = x["x"]+10
  56. --elseif lx > gr.getScreenWidth() then
  57. -- x = gr.getVectorFromCoords(gr.getScreenWidth(),0)
  58. -- vectorCurrentPos["z"] = x["x"]-10
  59. --else
  60. --Do nothing
  61. --end
  62. --if ly < 0 or ly == false then
  63. -- x = gr.getVectorFromCoords(0,0)
  64. -- vectorCurrentPos["y"] = x["y"]
  65. --elseif ly > gr.getScreenHeight() then
  66. -- x = gr.getVectorFromCoords(0,gr.getScreenHeight())
  67. -- vectorCurrentPos["y"] = x["y"]
  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. for i=1, #slaveShips do
  87. local scrollS = slaveShips[i]
  88. if scrollS ~= nil then --If this ship is null, don't bother playing with it.
  89. local pos = scrollS.Position
  90. if slaveToX[i] == true then
  91. pos["x"] = pos["x"] + (floatScrollX)
  92. end
  93. if slaveToY[i] == true then
  94. pos["y"] = pos["y"] + (floatScrollY)
  95. end
  96. if slaveToZ[i] == true then
  97. pos["z"] = pos["z"] + (floatScrollZ)
  98. end
  99. scrollS.Position = pos
  100. slaveShips[i] = scrollS
  101. end
  102. end
  103. ---enforce projectile positions relative to scrolling.
  104. for i=1, mn.#Weapons do
  105. local wep = mn.Weapons[i]
  106. local wPos = wep.Position
  107. wPos["x"] = wPos["x"] + (floatScrollX)
  108. wPos["y"] = wPos["y"] + (floatScrollY)
  109. wPos["z"] = wPos["z"] + (floatScrollZ)
  110. wep.Position = wPos
  111. mn.Weapons[i] = wep
  112. end
  113.  
  114.  
  115. ---Keep player moving relative to camera
  116. --vectorCurrentPos["x"] = vectorCurrentPos["x"] + (floatScrollX)
  117. --vectorCurrentPos["y"] = vectorCurrentPos["y"] + (floatScrollY)
  118. --vectorCurrentPos["z"] = vectorCurrentPos["z"] + (floatScrollZ)
  119. --objectPlayer.Position = vectorCurrentPos
  120. end
  121. end --Player Validity Check
  122. end
  123.  
  124. function initShmup()
  125.  
  126. --These are the slaves to our scrolling system. Every ship and associated boolean must all be aligned to the same index!
  127. slaveShips = {}
  128. slaveToX = {}
  129. slaveToY = {}
  130. slaveToZ = {}
  131.  
  132. ---Create 'blank' orientation
  133. ---these rotations are in RADIANS, not degrees.
  134. orientationBlank = mn.Ships[1].Orientation
  135. orientationBlank["p"] = 0
  136. orientationBlank["b"] = 0
  137. orientationBlank["h"] = -1.57
  138.  
  139. intSavedCamPosX = 250
  140. intSavedCamPosY = 0
  141. intSavedCamPosZ = 0
  142. ---Set movement box limits
  143. floatHLimit = 30
  144. floatVLimit = 88
  145. floatFLimit = 160
  146. --- Set movement limits again for the rear. The original version makes the assumption that the player's postion will be
  147. --- along the origin and thus symmetrical, which will not be the case if the camera is scrolling.
  148. floatHRLimit = -30
  149. floatVRLimit = -88
  150. floatFRLimit = -160
  151. ---Scroll rates for each axis
  152. floatScrollX = 0
  153. floatScrollY = 0
  154. floatScrollZ = 0
  155. vectorCCameraPos = ba.createVector(intSavedCamPosX,intSavedCamPosY,intSavedCamPosZ)
  156. orientationCCamera = orientationBlank
  157.  
  158. ---Create chase camera
  159. objectCCamera = gr.createCamera("Chase Camera",vectorCCameraPos,orientationCCamera)
  160.  
  161. ---Use the new chase camera
  162. gr.setCamera(objectCCamera)
  163.  
  164. booleanInitScroll = true
  165. end
  166.  
  167. ---Modifies the scroll speed of the camera on any axes a man desires..
  168. function setScrollSpeed(x,y,z)
  169. floatScrollX = x
  170. floatScrollY = y
  171. floatScrollZ = z
  172. end
  173.  
  174. ---Sets the current Status of the camera scrolling. initShmup must be called first to avoid funny stuff from happening.
  175. ---True turns it on, false to turn it off and rest the camera view to the player ship.
  176. function setScrollingActive(booleanSwitch)
  177. if booleanSwitch == true then
  178. vectorCCameraPos = ba.createVector((objectPlayer.Position["x"]-250),objectPlayer.Position["y"],objectPlayer.Position["z"])
  179. objectCCamera:setPosition(vectorCCameraPos)
  180. gr.setCamera(objectCCamera)
  181.  
  182. --Do NOT assume the play's position hasn't changed, therefore reset the bounds.
  183. floatHLimit = objectPlayer.Position["x"] + 30
  184. floatVLimit = objectPlayer.Position["y"] + 88
  185. floatFLimit = objectPlayer.Position["z"] + 160
  186. floatHRLimit = objectPlayer.Position["x"] - 30
  187. floatVRLimit = objectPlayer.Position["y"] - 90
  188. floatFRLimit = objectPlayer.Position["z"] - 160
  189. --Everything's set. Time to start scrolling again.
  190. booleanInitScroll = true
  191. elseif booleanSwitch == false then
  192. --Disable camera and scrolling, probably for a cutscene or something of that matter.
  193. booleanInitScroll = false
  194. gr.setCamera()
  195. else
  196. --nothing
  197. end
  198. end
  199.  
  200.  
  201.  
  202. --This crap won't work if the camera isn't the player's
  203. --Guess I gotta use subtitles now. =|
  204. --function drawPlayerHP()
  205. -- local ship = mn.Ships[1]
  206. -- local shipHP = ship.HitpointsLeft
  207. -- if shipHP <= 30 then
  208. -- gr.setColor(255,0,0)
  209. -- else
  210. -- gr.setColor(0,255,0)
  211. -- end
  212. -- gr.drawString(shipHP,200,100)
  213. --end
  214.  
  215. --Will cause the specified ship to be slaved to scrolling system and will move relative to the camera instead for the specified axes
  216. --Note that these ships still do not adhere to the boundary enclosure like the player is.
  217. function sTSC(shipToSlave,booleanSlaveXAxis,booleanSlaveYAxis,booleanSlaveZAxis)
  218. local toAdd = mn.Ships[shipToSlave]
  219. slaveShips[(#slaveShips+1)] = toAdd
  220. slaveToX[(#slaveToX+1)] = booleanSlaveXAxis
  221. slaveToY[(#slaveToY+1)] = booleanSlaveYAxis
  222. slaveToZ[(#slaveToZ+1)] = booleanSlaveZAxis
  223.  
  224. end
  225.  
  226. ]
  227.  
  228. $On Death:
  229.  
  230. [
  231. local dyingShip = hv.Self
  232. if dyingShip == hv.Player then --Do not disable the scrolling system if it's not the player who's blowing up!!
  233. booleanInitScroll = false
  234. end
  235.  
  236. ]
  237.  
  238. #End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement