function onDied()stopLoopedSounds()sDied:Play()end local B=0 local d=0 function onStateFall(Y,g)B=B+1 if Y then g.Volume=0 g:Play()Spawn(function()local d=0 local Y=B while d<1.5 and B==Y do local B=math.max(d-.3,0)g.Volume=B wait(.1)d=d+.1 end end)else g:Stop()end d=math.max(d,math.abs(Head.Velocity.Y))end function onStateNoStop(B,d)if B then d:Play()end end function onRunning(B)sClimbing:Stop()sSwimming:Stop()if prevState=="\070\114\101\101\070\097\108\108"and d>.1 then local B=math.min(1.0,math.max(.0,(d-50)/110))sLanding.Volume=B sLanding:Play()d=0 end if B>.5 then sRunning:Play()sRunning.Pitch=B/8.0 else sRunning:Stop()end prevState="\082\117\110"end function onSwimming(B)if prevState~="\083\119\105\109"and B>.1 then local d=math.min(1.0,B/350)sSplash.Volume=d sSplash:Play()prevState="\083\119\105\109"end sClimbing:Stop()sRunning:Stop()sSwimming.Pitch=1.6 sSwimming:Play()end function onClimbing(B)sRunning:Stop()sSwimming:Stop()if B>.01 then sClimbing:Play()sClimbing.Pitch=B/5.5 else sClimbing:Stop()end prevState="\067\108\105\109\098"end
-- functions

function onDied()
	stopLoopedSounds()
	sDied:Play()
end

local fallCount = 0
local fallSpeed = 0
function onStateFall(state, sound)
	fallCount = fallCount + 1
	if state then
		sound.Volume = 0
		sound:Play()
		Spawn(function()
			local t = 0
			local thisFall = fallCount
			while t < 1.5 and fallCount == thisFall do
				local vol = math.max(t - 0.3, 0)
				sound.Volume = vol
				wait(0.1)
				t = t + 0.1
			end
		end)
	else
		sound:Stop()
	end
	fallSpeed = math.max(fallSpeed, math.abs(Head.Velocity.Y))
end

function onStateNoStop(state, sound)
	if state then
		sound:Play()
	end
end

function onRunning(speed)
	sClimbing:Stop()
	sSwimming:Stop()
	if prevState == "FreeFall" and fallSpeed > 0.1 then
		local vol = math.min(1.0, math.max(0.0, (fallSpeed - 50) / 110))
		sLanding.Volume = vol
		sLanding:Play()
		fallSpeed = 0
	end
	if speed > 0.5 then
		sRunning:Play()
		sRunning.Pitch = speed / 8.0
	else
		sRunning:Stop()
	end
	prevState = "Run"
end

function onSwimming(speed)
	if prevState ~= "Swim" and speed > 0.1 then
		local volume = math.min(1.0, speed / 350)
		sSplash.Volume = volume
		sSplash:Play()
		prevState = "Swim"
	end
	sClimbing:Stop()
	sRunning:Stop()
	sSwimming.Pitch = 1.6
	sSwimming:Play()
end

function onClimbing(speed)
	sRunning:Stop()
	sSwimming:Stop()
	if speed > 0.01 then
		sClimbing:Play()
		sClimbing.Pitch = speed / 5.5
	else
		sClimbing:Stop()
	end
	prevState = "Climb"
end
