-- -------------------------------------------------------------------------------- -- FILE: snowball.lua -- DESCRIPTION: -- AUTHOR: Benny Yang (), -- CREATED: 2010/12/30 -------------------------------------------------------------------------------- -- require "lua/entity.lua" require "lua/utilities.lua" curTime = 0 bInitialized = false SnowBall_IncScale = 0.5 SnowBall_IncFreq = 0.5 SnowBall_MaxScale = 3 SnowBall_CurScale = 0 SnowBall_TimeToScale = 0 SnowBall_onGround = false SnowBall_onGroundThreshold = 0.8 m_bStartUpdate = false ------------------------------------------------------------------------ -- FUNCTIONS ------------------------------------------------------------------------ function Init ( ) SnowBall_TimeToScale = SnowBall_IncFreq; bInitialized = true return end ---------- end of function Init ---------- function updateSnowBall ( dt ) if m_bStartUpdate == false then return end -- get snow ball's position x, y, z = position() -- check snow ball on the ground yet lx, ly, lz = landingPos(x, y, z) local zDiff = 10 if lz ~= nil then zDiff = math.abs(z-lz) end if zDiff <= SnowBall_onGroundThreshold then SnowBall_onGround = true else SnowBall_onGround = false return end SnowBall_TimeToScale = SnowBall_TimeToScale - dt if SnowBall_TimeToScale <= 0 and SnowBall_CurScale <= SnowBall_MaxScale then -- get current scale x, y, z = scale() scaleSmooth(x+SnowBall_IncScale,y+SnowBall_IncScale,z+SnowBall_IncScale, 0.1) SnowBall_TimeToScale = SnowBall_IncFreq; SnowBall_CurScale = SnowBall_CurScale + 1 end return end ---------- end of function updateSnowBall ---------- 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,"fire_snow_ball") then m_bStartUpdate = true 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 updateSnowBall(dt) end ------------------------------------------------------------------------ -- SHUT DOWN SECTION ------------------------------------------------------------------------ shutdown()