 ObjectData = 
{
	MotionModel = 
	{
		DefaultAnimation = [[normal]],
		Motions = 
		{
			motion4 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\bob\bob_toolbar.anim]],
						Name = [[default]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[toolbar]],
			},
			motion1 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\bob\bob_teleport_start.anim]],
						Name = [[bob_teleport_start]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[teleport_start]],
			},
			motion5 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\bob\bob_teleport_middle.anim]],
						Name = [[bob_teleport_middle]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[teleport_middle]],
			},
			motion3 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\bob\bob_blink.anim]],
						Name = [[bob_blink]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
					anim2 = 
					{
						Path = [[DATA:Animations\bob\bob_looking.anim]],
						Name = [[bob_looking]],
						MinFreq = 2.000000,
						MaxFreq = 5.000000,
					},
				},
				Name = [[normal]],
			},
			motion2 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\bob\bob_teleport_end.anim]],
						Name = [[bob_teleport_end]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[teleport_end]],
			},
		},
	},
	Extensions = 
	{
		PhysicsExtension = 
		{
		},
		LevelEditorExtension = 
		{
		},
		PositionExtension = 
		{
		},
	},
}-- Begin Scripting --

help_text_header = "$00601"
help_text = "$00602"

function OnInit()

	turned_on = false
	ANTI_GRAV_TIME = 24 * 2
	count = 0
	
	this:EnablePhysics( false )

end

function Update()

	Profile_Start("bob")

	if turned_on then
		local motion_model = this:GetMotionModel()
		
		count = count - 1
		if count == 0 then
			motion_model:PopMotion()
			motion_model:PushMotion( "teleport_end", false, false )
			turned_on = false
			this:KillMe()
			FX_SpawnEffect( "bob/explode", this:GetPosition() )
			for object in World_GetObjects() do
				local we = object:GetWalkingExtension()
				if we then
					we:SetActive(true)
				end
			end
		else
			-- Get the gravity force.
			local gravity_force = World_GetGravity().y * -750
		
			Sound_CreateSound( "Bob Activation", false, 0, this:GetPosition() )
			
			-- Apply a force to all objects.
			for object in World_GetObjects() do

				-- Detaches walkers if they've somehow reattached to a platform.
				local we = object:GetWalkingExtension()
				if we and we:GetState() ~= WalkingExtension.WES_Inactive then
					we:SetActive(false)
				end

				-- Makes inflated Balloon Marshmallows sink instead of rise.
				if (object:GetBlueprintHash() == World_HashString("giant_marshmallow_balloon") ) and ( object:GetMotionModel():GetCurrentMotionName() == "inflated" ) then
					object:ApplyImpulse( Vector2(0, gravity_force*-1) )
				else
					object:ApplyImpulse( Vector2(0, gravity_force) )
				end
			end
		end
	else
		for report in this:GetCollisionReports() do
			if not turned_on then
				OnHit()
			end
		end
	end
	
	Profile_Stop("bob")
end

function OnHit()

	turned_on = true
	count = ANTI_GRAV_TIME
	
	local motion_model = this:GetMotionModel()

	motion_model:PushMotion( "teleport_middle", true, false )
	motion_model:PushMotion( "teleport_start", false, false )
	
	World_CreateEffect("bob/telekenesis", this:GetPosition())
	
	for object in World_GetObjects() do
		local we = object:GetWalkingExtension()
		if we then
			we:SetActive(false)
		end
	end
	
end

