Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Conditional Hooks
- $State: GS_STATE_GAME_PLAY
- $On Frame:
- [
- if booleanInitScroll == true then
- objectPlayer = hv.Player
- if objectPlayer:isValid() then --Player Validity Check
- --Get Position and Orientation and Speed
- vectorCurrentPos = objectPlayer.Position
- --floatPlayerSpeed = objectPlayer.Physics:getSpeed()
- vectorPlayerVelocity = objectPlayer.Physics.Velocity
- --Horizontal Position Limit
- if objectPlayer.Position["x"] > floatHLimit then
- vectorPlayerVelocity["x"] = 300
- elseif vectorCurrentPos["x"] < floatHRLimit then
- vectorPlayerVelocity["x"] = -300
- end
- --Vertical Position Limit
- if objectPlayer.Position["y"] > floatVLimit then
- vectorPlayerVelocity["y"] = -300
- elseif vectorCurrentPos["y"] < floatVRLimit then
- vectorPlayerVelocity["y"] = 300
- end
- --Forward Position Limit
- if objectPlayer.Position["z"] > floatFLimit then
- objectPlayer.Physics.Velocity["z"] = -300
- if objectPlayer.HitpointsLeft <= 5 then --if the poor sod has not enough hitpoint to chop off, just kill the guy.
- objectPlayer:kill(objectPlayer)
- else
- objectPlayer.HitpointsLeft = (objectPlayer.HitpointsLeft - 5)
- end
- elseif vectorCurrentPos["z"] < floatFRLimit then
- objectPlayer.Physics.Velocity["z"] = 300
- if objectPlayer.HitpointsLeft <= 5 then --if the poor sod has not enough hitpoint to chop off, just kill the guy.
- objectPlayer:kill(objectPlayer)
- else
- objectPlayer.HitpointsLeft = (objectPlayer.HitpointsLeft - 5)
- end
- end
- forceOrient = ba.createOrientation(0,0,0)
- --Update Player Rotational Velocity, Position
- objectPlayer.Physics.Velocity = vectorPlayerVelocity
- objectPlayer.Physics.Orientation = forceOrientation
- --The ideal code that doesn't work...
- --local x = gr.getVectorFromCoords(vectorCurrentPos["x"],vectorCurrentPos["y"])
- --local lx,ly = x:getScreenCoords()
- --ba.error(type(x:getScreenCoords()))
- --if lx < 0 then
- -- x = gr.getVectorFromCoords(0,0)
- -- vectorCurrentPos["z"] = x["x"]+10
- --elseif lx > gr.getScreenWidth() then
- -- x = gr.getVectorFromCoords(gr.getScreenWidth(),0)
- -- vectorCurrentPos["z"] = x["x"]-10
- --else
- --Do nothing
- --end
- --if ly < 0 or ly == false then
- -- x = gr.getVectorFromCoords(0,0)
- -- vectorCurrentPos["y"] = x["y"]
- --elseif ly > gr.getScreenHeight() then
- -- x = gr.getVectorFromCoords(0,gr.getScreenHeight())
- -- vectorCurrentPos["y"] = x["y"]
- --else
- --nothing
- --end
- --AndrewofDoom's mod: addition of scrolling
- if booleanInitScroll == true then --double check to see if this still is really true.
- local ft = ba.getFrametime(false)
- intSavedCamPosX = intSavedCamPosX + (floatScrollX*ft)
- intSavedCamPosY = intSavedCamPosY + (floatScrollY*ft)
- intSavedCamPosZ = intSavedCamPosZ + (floatScrollZ*ft)
- vectorCCameraPos = ba.createVector(intSavedCamPosX,intSavedCamPosY,intSavedCamPosZ)
- objectCCamera:setPosition(vectorCCameraPos)
- floatHLimit = floatHLimit + (floatScrollX*ft)
- floatVLimit = floatVLimit + (floatScrollY*ft)
- floatFLimit = floatFLimit + (floatScrollZ*ft)
- ---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.
- floatHRLimit = floatHRLimit + (floatScrollX*ft)
- floatVRLimit = floatVRLimit + (floatScrollY*ft)
- floatFRLimit = floatFRLimit + (floatScrollZ*ft)
- --all scrolling related to slaved ships.
- for i=1,#slaveShips do
- if slaveShips[i] ~= nil then
- local scrollS = slaveShips[i]
- if scrollS ~= nil then --If this ship is null, don't bother playing with it.
- local pos = scrollS.Position
- if slaveToX[i] == true then
- pos["x"] = pos["x"] + (floatScrollX*ft)
- end
- if slaveToY[i] == true then
- pos["y"] = pos["y"] + (floatScrollY*ft)
- end
- if slaveToZ[i] == true then
- pos["z"] = pos["z"] + (floatScrollZ*ft)
- end
- scrollS.Position = pos
- slaveShips[i] = scrollS
- end
- end
- end
- ---enforce projectile positions relative to scrolling and cull offscreen projectiles.
- local numWeps = #mn.Weapons
- for i=1,numWeps do
- local wep = mn.Weapons[i]
- local wPos = wep.Position
- if wep.Parent == hv.Player or wep.Target == hv.Player then
- --Check for out of bounds
- if wPos["y"] > floatVLimit or wPos["y"] < floatVRLimit or wPos["z"] > floatFLimit or wPos["z"] < floatFRLimit then
- wep.LifeLeft = 0.0 --Terminate weapon
- end
- if wep.LifeLeft > 0 then
- --if still in bounds, apply scrolling.
- wPos["x"] = wPos["x"] + (floatScrollX*ft)
- wPos["y"] = wPos["y"] + (floatScrollY*ft)
- wPos["z"] = wPos["z"] + (floatScrollZ*ft)
- wep.Position = wPos
- end
- end
- if wep.LifeLeft > 0 then --if this projectile is dead, then don't bother.
- --force these projectiles from these ships to have their scrolling force to player position and 0'd x component velocities.
- --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.
- for j=1, #forcedProjShipsToPlayerAxis do
- if forcedProjShipsToPlayerAxis[j] ~= nil then --if there is no one here, then don't bother.
- if wep.Parent == forcedProjShipsToPlayerAxis[j] then
- wPos["x"] = objectPlayer.Position["x"]
- wep.Position = wPos
- end
- end
- end
- end
- mn.Weapons[i] = wep --Apply weapon change
- end
- ---Keep player moving relative to camera
- --vectorCurrentPos["x"] = vectorCurrentPos["x"] + (floatScrollX)
- --vectorCurrentPos["y"] = vectorCurrentPos["y"] + (floatScrollY)
- --vectorCurrentPos["z"] = vectorCurrentPos["z"] + (floatScrollZ)
- --objectPlayer.Position = vectorCurrentPos
- end
- end --Player Validity Check
- end
- --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.
- function initShmup()
- --These are the slaves to our scrolling system. Every ship and associated boolean must all be aligned to the same index!
- slaveShips = {}
- slaveToX = {}
- slaveToY = {}
- slaveToZ = {}
- forcedProjShipsToPlayerAxis = {}
- ---Create 'blank' orientation
- ---these rotations are in RADIANS, not degrees.
- orientationBlank = hv.Player.Orientation
- orientationBlank["p"] = 0
- orientationBlank["b"] = 0
- orientationBlank["h"] = -1.57
- intSavedCamPosX = 250
- intSavedCamPosY = 0
- intSavedCamPosZ = 0
- ---Set movement box limits
- floatHLimit = 30
- floatVLimit = 88
- floatFLimit = 155
- --- 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.
- floatHRLimit = -30
- floatVRLimit = -88
- floatFRLimit = -155
- ---Scroll rates for each axis
- floatScrollX = 0
- floatScrollY = 0
- floatScrollZ = 0
- vectorCCameraPos = ba.createVector(intSavedCamPosX,intSavedCamPosY,intSavedCamPosZ)
- orientationCCamera = orientationBlank
- ---Create chase camera
- objectCCamera = gr.createCamera("Chase Camera",vectorCCameraPos,orientationCCamera)
- --objectCCamera = gr.Cameras[1]
- --objectCCamera:setPosition(vectorCCameraPos)
- --objectCCamera:setOrientation(orientationBlank)
- ---Use the new chase camera
- gr.setCamera(objectCCamera)
- booleanInitScroll = true
- end
- ---Modifies the scroll speed of the camera on any axes a man desires..
- function setScrollSpeed(x,y,z)
- floatScrollX = (x*60)
- floatScrollY = (y*60)
- floatScrollZ = (z*60)
- end
- ---Sets the current Status of the camera scrolling. initShmup must be called first to avoid funny stuff from happening.
- ---True turns it on, false to turn it off and rest the camera view to the player ship.
- function setScrollingActive(booleanSwitch)
- if booleanSwitch == true then
- vectorCCameraPos = ba.createVector((objectPlayer.Position["x"]-250),objectPlayer.Position["y"],objectPlayer.Position["z"])
- objectCCamera:setPosition(vectorCCameraPos)
- gr.setCamera(objectCCamera)
- --Do NOT assume the player's position hasn't changed, therefore reset the bounds.
- floatHLimit = objectPlayer.Position["x"] + 30
- floatVLimit = objectPlayer.Position["y"] + 88
- floatFLimit = objectPlayer.Position["z"] + 160
- floatHRLimit = objectPlayer.Position["x"] - 30
- floatVRLimit = objectPlayer.Position["y"] - 90
- floatFRLimit = objectPlayer.Position["z"] - 160
- --Everything's set. Time to start scrolling again.
- booleanInitScroll = true
- elseif booleanSwitch == false then
- --Disable camera and scrolling, probably for a cutscene or something of that matter.
- booleanInitScroll = false
- gr.setCamera()
- else
- --nothing
- end
- end
- --Will cause the specified ship to be slaved to scrolling system and will move relative to the camera instead for the specified axes
- --Note that these ships still do not adhere to the boundary enclosure like the player is.
- function sTSC(shipToSlave,booleanSlaveXAxis,booleanSlaveYAxis,booleanSlaveZAxis)
- local toAdd = mn.Ships[shipToSlave]
- if toAdd ~= nil then --sanity check
- slaveShips[(#slaveShips+1)] = toAdd
- slaveToX[(#slaveToX+1)] = booleanSlaveXAxis
- slaveToY[(#slaveToY+1)] = booleanSlaveYAxis
- slaveToZ[(#slaveToZ+1)] = booleanSlaveZAxis
- end
- end
- --removes a slaved ship.
- function rss(slavedShip)
- local toChange = mn.Ships[slavedShip]
- local intIndex = 0
- for i=1, #slaveShips do
- if slaveShips[i] == toChange then
- intIndex = i -- found the ship, assign the index and break out of the for loop.
- break
- end
- end
- if intIndex >= 1 then --if this number is >= 1 then I have found something.
- slaveShips[intIndex] = nil --this may be potentially dangerous, but any good man should always check for null when iterating an array.
- end
- end
- --Forces this ships projectiles to be on the same axis on the player's (the x-axis)
- --Needs to be done before it starts shooting.
- function pgopx(pgopx_ship)
- local toAdd = mn.Ships[pgopx_ship]
- if toAdd ~= nil then
- forcedProjShipsToPlayerAxis[(#forcedProjShipsToPlayerAxis+1)] = toAdd
- end
- end
- --This crap won't work if the camera isn't the player's
- --Guess I gotta use subtitles now. =|
- --function drawPlayerHP()
- -- local ship = mn.Ships[1]
- -- local shipHP = ship.HitpointsLeft
- -- if shipHP <= 30 then
- -- gr.setColor(255,0,0)
- -- else
- -- gr.setColor(0,255,0)
- -- end
- -- gr.drawString(shipHP,200,100)
- --end
- ]
- $On Death:
- [
- local dyingShip = hv.Self
- if dyingShip == hv.Player then --Do not disable the scrolling system if it's not the player who's blowing up!!
- booleanInitScroll = false
- end
- ]
- $On Mission End:
- [
- booleanInitScroll = false --force it off when a mission ends.
- ]
- #End
Advertisement
Add Comment
Please, Sign In to add comment