function init()
	motors = FindJoints("motor")
	
	dir = 0
	speed = 0.95
	accelerationTime = 1

	startbutton = FindShape("startbutton")
	reversebutton = FindShape("reversebutton")
	stopbutton = FindShape("stopbutton")
	
	SetTag(startbutton, "interact", "Òöãôö")
	SetTag(reversebutton, "interact", "Ñéåéôõ")
	SetTag(stopbutton, "interact", "Àåãôìíñºí õöòó")	
	
	buttonClick = LoadSound("clickup.ogg")
	motorSound = LoadLoop("vehicle/hydraulic-loop.ogg")
	oldMotorPos = GetJointMovement(motor)
	body = FindBody("body")
end


function tick(dt)
	local current = GetJointMovement(motor)
	if GetPlayerInteractShape() == startbutton then
		if InputPressed("interact") then
			SetValue("dir", 1, "linear", accelerationTime)
			PlaySound(buttonClick,GetShapeWorldTransform(startbutton).pos)
		end
	end
	if GetPlayerInteractShape() == reversebutton then
		if InputPressed("interact") then
			SetValue("dir", -1, "linear", accelerationTime)
			PlaySound(buttonClick,GetShapeWorldTransform(reversebutton).pos)
		end
	end
	if GetPlayerInteractShape() == stopbutton then
		if InputPressed("interact") then
			dir = 0
			PlaySound(buttonClick,GetShapeWorldTransform(stopbutton).pos)
		end
	end

	if dir ~= 0 then
		PlayLoop(motorSound,GetBodyTransform(body).pos)
	end

	oldMotorPos = GetJointMovement(motor)

	for i=1,#motors do
		tagValue = 1
		if GetTagValue(motors[i], "motor") ~= "" then
			tagValue = GetTagValue(motors[i],"motor")
		end
		
		SetJointMotor(motors[i], dir*speed*tagValue)
	end
end

