function init()
	intercom = FindShape("intercom")
	exit_button = FindShape("exit_button")
	screen = FindShape("screen")
	magnet = FindShape("magnet")
	hinge = FindJoint("hinge")
	open = LoadSound("MOD/sounds/domofon/open.ogg")
	loc = FindLocation("sound")
	u = GetLocationTransform(loc)
	pos = u.pos
	SetShapeEmissiveScale(screen, 0)
end

interval = GetIntParam("interval", 60)
frame = 0
t = 0
g = 0

function Blink()
	frame = frame + 1
	if frame % interval < interval/2 == true then
		SetShapeEmissiveScale(screen, 1)
		SetShapeEmissiveScale(exit_button, 1)
	else
		SetShapeEmissiveScale(screen, 0)
		SetShapeEmissiveScale(exit_button, 0)
	end
end

function tick(dt)
	if IsShapeBroken(intercom) == true then
		RemoveTag(intercom, "interact")
	end
	angle = GetJointMovement(hinge)
	function Close()
		if angle < 10 then
			SetJointMotor(hinge, 1)
		else
			SetJointMotor(hinge, 0, 0)
		end
	end
	if GetPlayerInteractShape() == intercom and InputPressed("interact") then
		PlaySound(open, pos, 1.0)
		RemoveTag(intercom, "interact")
		RemoveTag(exit_button, "interact")
		SetJointMotor(hinge, 0, 0)
		g = 1
	end

	if g == 1 then
		t = t + dt
		Blink()
		if t > 3 then
			SetShapeEmissiveScale(screen, 0)
			SetShapeEmissiveScale(exit_button, 1)
			SetTag(intercom, "interact", "Open")
			SetTag(exit_button, "interact", "Open")
			g = 0
			t = 0
		end
	end

	if GetPlayerInteractShape() == exit_button and InputPressed("interact") then
		PlaySound(open, pos, 1.0)
		RemoveTag(intercom, "interact")
		RemoveTag(exit_button, "interact")
		SetJointMotor(hinge, 0, 0)
		g = 1
	end

	if g == 1 then
		t = t + dt
		Blink()
		if t > 3 then
			SetShapeEmissiveScale(screen, 0)
			SetShapeEmissiveScale(exit_button, 1)
			SetTag(intercom, "interact", "Open")
			SetTag(exit_button, "interact", "Open")
			g = 0
			t = 0
		end
	end

	if g == 0 then
		Close()
	end
	if IsShapeBroken(magnet) == true then
		RemoveTag(intercom, "interact")
		RemoveTag(exit_button, "interact")
		SetJointMotor(hinge, 0, 0)
		SetShapeEmissiveScale(exit_button, 0)
	end
end