print("Gate_Spikes init") require "lua/entity.lua" require "lua/utilities.lua" require "lua/level_hub/ruinsstate.lua" -- Per-instance overrides spikemodel = "Gate_Spikes_Spike" holemodel = "Gate_Spikes_Base_Stone" startObjName = "Docks_Barrier_COL_Start" endObjName = "Docks_Barrier_COL_End" spikespacing = ft2m(4) verticalOffset = verticalOffset or 0 mySpikes = {} myHoles = {} holeFadeStart = math.huge holeFadeEnd = math.huge --Global -- Function function buildGate() if spikemodel and startObjName and endObjName then startObj = object(startObjName) endObj = object(endObjName) startPos = {startObj.position()} endPos = {endObj.position()} --print ("buildGate " , startObjName , endObjName ) --print ("gate start: ") --print ( startObj.position() ) --print ("gate end: ") --print ( endObj.position() ) gateWidth = getDistance2D(startPos,endPos) --print("gate width " .. gateWidth) numSpikes = math.floor( gateWidth / spikespacing) --print("numSpikes " .. numSpikes ) for i=0,numSpikes-1 do local x = 0.7 + startPos[1] + ( ( (endPos[1] - startPos[1]) / numSpikes) * i ) local y = 0.7 + startPos[2] + ( ( (endPos[2] - startPos[2] ) / numSpikes) * i ) local z = startPos[3] if landingPos( x,y,z ) then x,y,z = landingPos( x,y,z ) end z = z + verticalOffset --special case override for the first spike of the fairy barrier if startObjName=="Fairy_Barrier_COL_Start" and i==0 then z = z - 0.3 end local newSpike = spawn(spikemodel , x , y , z ) newSpike.scale( 1 , 1 , ( 90 + math.random(0,20) ) * 0.01 ) local rx,ry,rz = rotation() newSpike.rotation( rx,ry,math.random(0,720) / 2 ) --print("spawned spike " .. i) --print( newSpike.scale() ) --print( newSpike.position() ) --newSpike.position( landingPos( newSpike.position() ) ) --print( "pos:" , newSpike.position() ) --print( "rot:" , newSpike.rotation() ) mySpikes[#mySpikes+1] = newSpike newHole = spawn(holemodel, x , y , z) newHole.rotation( rx,ry,math.random(0,720) / 2 ) table.insert(myHoles,newHole) end else print("couldn't make gate, missing variables") end end function gateTick() if trigger.received(1,"open") then print("gate open") local toggle = 1 for k,v in pairs(mySpikes) do v.translateSmooth( nil , nil , -8 , math.random(10,30) * 0.1 , 1 , 0 ) v.rotateSmoothRelative( nil , nil , math.random(90,180) * toggle , 1 , 0.5 ) if toggle == 1 then toggle = -1 else toggle = 1 end end holeFadeStart = myTime + 2 end if holeFadeStart <= myTime then print("hole fade start") for k,v in pairs(myHoles) do v.setAlphaSmooth(1,0,2) end holeFadeStart = math.huge holeFadeEnd = myTime + 2 end if holeFadeEnd <= myTime then print("hole fade end") delete() end end function shutdown() for k,v in pairs(mySpikes) do v.delete() end for k,v in pairs(myHoles) do v.delete() end end