-- -------------------------------------------------------------------------------- -- FILE: ice_prison.lua -- DESCRIPTION: -- AUTHOR: Benny Yang (), -- CREATED: 2010/12/21 -------------------------------------------------------------------------------- -- require "lua/entity.lua" require "lua/utilities.lua" curTime = 0 bInitialized = false -- ice prison life time IcePrison_LifeTime = 2 IcePrison_MeltTime = 0.1 IcePrison_ActivateTime = 0 IcePrison_Melt_Started = false ------------------------------------------------------------------------ -- FUNCTIONS ------------------------------------------------------------------------ function Init ( ) -- random facing local ranAng = math.random(0,359) rotation(nil,nil, ranAng) -- smooth scale to the original size scaleSmooth(1,1,1, 0.2) -- set alpha setAlphaSmooth(255/255, 192/255, 0.2) bInitialized = true return end ---------- end of function Init ---------- function updateIcePrisonState ( dt ) IcePrison_ActivateTime = IcePrison_ActivateTime + dt if IcePrison_Melt_Started == true then return end if IcePrison_ActivateTime > IcePrison_LifeTime-IcePrison_MeltTime then trigger.send(1,"ICE_PRISON_START_MELT") scaleSmoothLocal( 1, 1, 0.1, IcePrison_MeltTime ) setAlphaSmooth(255/255, 0, 1) IcePrison_Melt_Started = true end return end ---------- end of function updateIcePrisonState ---------- function updateIcePrison ( dt ) return end ---------- end of function updateIcePrison ---------- function shutdown ( ) -- delete self if delete then delete() end return end ---------- end of function shutdown ---------- function checkEvents ( ) if trigger.received() then if trigger.received(1,"FORCE_TO_MELT") then if IcePrison_ActivateTime < IcePrison_LifeTime-IcePrison_MeltTime then IcePrison_ActivateTime = IcePrison_LifeTime-IcePrison_MeltTime end end end return end ---------- end of function checkEvents ---------- ------------------------------------------------------------------------ -- MAIN LOOP ------------------------------------------------------------------------ while tick() do curTime = curTime + dt if bInitialized == false then Init() end -- check events checkEvents() -- update ice prison updateIcePrisonState(dt) -- check life time if(IcePrison_ActivateTime >= IcePrison_LifeTime) then trigger.send(1,"ICE_PRISON_TIME_UP") break; end end ------------------------------------------------------------------------ -- SHUT DOWN SECTION ------------------------------------------------------------------------ -- delete will be handled by IcePrison component --shutdown()