on = false

function init()	

	radio = FindShape("radio")
	
	SetShapeEmissiveScale(radio, 0)
	SetTag(radio, "interact", "loc@TURN_ON")
	
	clickSound = LoadSound("clickdown.ogg")
	musicLoop = LoadLoop("MOD/snd/pc1.ogg")
	
end

function tick(dt)
	if IsShapeBroken(radio) then
		RemoveTag(radio, "interact")
		return
	end

	if GetPlayerInteractShape() == radio and InputPressed("interact") then
		PlaySound(clickSound)
		if on then
			on = false
			SetShapeEmissiveScale(radio, 0)
			SetTag(radio, "interact", "loc@TURN_ON")
		else
			on = true
			SetShapeEmissiveScale(radio, 1)
			SetTag(radio, "interact", "loc@TURN_OFF")
		end
	end

	if on then 
		local pos = GetShapeWorldTransform(radio).pos
		PlayLoop(musicLoop, pos)
	end
end


