Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Global Hooks
- $Simulation:
- [
- --Main loop that begins once initShmup() is executed.
- if booleanInitScroll == true then
- if objectPlayer:isValid() then --Player Validity Check
- --Get Position and Orientation and Speed
- vectorCurrentPos = objectPlayer.Position
- vectorPlayerVelocity = objectPlayer.Physics.Velocity
- --Horizontal Position Limit
- if objectPlayer.Position["x"] > floatHLimit then
- local playPos = ba.createVector((ship_central_camera.Position["x"] + (floatHLimit - 1)), objectPlayer.Position["y"], objectPlayer.Position["z"])
- objectPlayer.Position = playPos
- elseif objectPlayer.Position["x"] < floatHRLimit then
- local playPos = ba.createVector((ship_central_camera.Position["x"] - (floatHRLimit + 1)), objectPlayer.Position["y"], objectPlayer.Position["z"])
- objectPlayer.Position = playPos
- end
- --Vertical Position Limit
- if objectPlayer.Position["y"] > floatVLimit then
- local playPos = ba.createVector(objectPlayer.Position["x"],(ship_central_camera.Position["y"] + (floatVLimit - 1)), objectPlayer.Position["z"])
- objectPlayer.Position = playPos
- elseif objectPlayer.Position["y"] < floatVRLimit then
- local playPos = ba.createVector(objectPlayer.Position["x"],(ship_central_camera.Position["y"] - (floatVRLimit + 1)), objectPlayer.Position["z"])
- objectPlayer.Position = playPos
- end
- --Forward Position Limit
- if objectPlayer.Position["z"] > floatFLimit then
- local playPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],(ship_central_camera.Position["z"] + (floatFLimit - 1)))
- objectPlayer.Position = playPos
- elseif vectorCurrentPos["z"] < floatFRLimit then
- local playPos = ba.createVector(objectPlayer.Position["x"],objectPlayer.Position["y"],(ship_central_camera.Position["z"] - (floatFRLimit + 1)))
- objectPlayer.Position = playPos
- 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"]) --Use the screen view to determine if the player is in bounds.
- --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.
- 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
- local wepPos = ba.createVector(objectPlayer.Position["x"],wep.Position["y"],wep.Position["z"])
- wep.Position = wepPos
- local wepVel = ba.createVector(0,wep.Physics.Velocity["y"],wep.Physics.Velocity["z"])
- wep.Physics.Velocity = wepVel
- wep.Physics.VelocityDesired = wepVel
- wep.Physics.VelocityMax = wepVel
- local wepOrient = ba.createOrientation(wep.Orientation["p"],wep.Orientation["b"],0)
- wep.Orientation = wepOrient
- end
- end
- end
- end
- mn.Weapons[i] = wep --Apply weapon change
- end
- end
- end --Player Validity Check
- end
- ]
- #End
- #Conditional Hooks
- $State: GS_STATE_GAME_PLAY
- $On Frame:
- [
- --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.
- function initShmup()
- ship_central_camera = mn.Ships['Center'] --Look for a ship called Center to...well center the view on.
- objectPlayer = hv.Player
- if ship_central_camera ~= nil then
- --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 = (ship_central_camera.Position["x"] + 250)
- intSavedCamPosY = ship_central_camera.Position["y"]
- intSavedCamPosZ = ship_central_camera.Position["z"]
- ---Set movement box limits
- floatHLimit = (ship_central_camera.Position["x"] + 30)
- floatVLimit = (ship_central_camera.Position["y"] + 88)
- floatFLimit = (ship_central_camera.Position["z"] + 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 = (ship_central_camera.Position["x"] - 30)
- floatVRLimit = (ship_central_camera.Position["y"] - 88)
- floatFRLimit = (ship_central_camera.Position["x"] - 155)
- ---Scroll rates for each axis
- floatScrollX = 0
- floatScrollY = 0
- floatScrollZ = 0
- vectorCCameraPos = ba.createVector(intSavedCamPosX,intSavedCamPosY,intSavedCamPosZ)
- orientationCCamera = orientationBlank
- --Use the player camera at the start and move it out of first person for a wonderful out-of-body experience.
- objectCCamera = gr.Cameras[1]
- objectCCamera:setPosition(vectorCCameraPos)
- objectCCamera:setOrientation(orientationBlank)
- ---Use the new chase camera
- gr.setCamera(objectCCamera)
- booleanInitScroll = true
- else
- ba.error("No view was found to center on. Make sure there is a ship called Center to point the camera on.")
- end
- end
- --Modifies the scroll speed of the camera on any axes a man desires..
- --Value is in meters/frame, but is converted to meters/60 frames by this function for use when it's multiplied by ba.getFrameTime.
- 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