ObjectData = 
{
	MotionModel = 
	{
		DefaultAnimation = [[normal]],
		Motions = 
		{
			motion4 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_smack.anim]],
						Name = [[marsh_bud_gravity_smack]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[hit]],
			},
			motion1 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_being_eaten_half_frame.anim]],
						Name = [[marsh_bud_gravity_being_eaten]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[eaten]],
			},
			motion3 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_toolbar.anim]],
						Name = [[marsh_bud_gravity_toolbar]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[toolbar]],
			},
			motion2 = 
			{
				Animations = 
				{
					anim4 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_shifty_eyed.anim]],
						Name = [[marsh_bud_gravity_shifty_eyed]],
						MinFreq = 16.000000,
						MaxFreq = 24.000000,
					},
					anim5 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_look_left.anim]],
						Name = [[marsh_bud_gravity_look_left]],
						MinFreq = 5.000000,
						MaxFreq = 8.000000,
					},
					anim1 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_look_down.anim]],
						Name = [[marsh_bud_gravity_look_down]],
						MinFreq = 5.000000,
						MaxFreq = 8.000000,
					},
					anim8 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_look_up.anim]],
						Name = [[marsh_bud_gravity_look_up]],
						MinFreq = 5.000000,
						MaxFreq = 8.000000,
					},
					anim6 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_shake.anim]],
						Name = [[marsh_bud_gravity_shake]],
						MinFreq = 16.000000,
						MaxFreq = 24.000000,
					},
					anim7 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_look_blink.anim]],
						Name = [[marsh_bud_gravity_look_blink]],
						MinFreq = 2.000000,
						MaxFreq = 4.000000,
					},
					anim3 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_look_right.anim]],
						Name = [[marsh_bud_gravity_look_right]],
						MinFreq = 5.000000,
						MaxFreq = 8.000000,
					},
					anim2 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_eyebrow_lift.anim]],
						Name = [[marsh_bud_gravity_eyebrow_lift]],
						MinFreq = 10.000000,
						MaxFreq = 15.000000,
					},
				},
				Name = [[normal]],
			},
			motion5 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Marshmallow Bud\marsh_bud_gravity_look_up.anim]],
						Name = [[marsh_bud_gravity_look_up]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[alt_collision]],
			},
		},
	},
	Extensions = 
	{
		EdibleExtension = 
		{
			Eaters =
			{
				"whale",
				"eets_angry",
				"eets_happy",
				"eets_scared",
				"squirrel",
			},
		},
		PhysicsExtension = 
		{
			mass = 1.000000,
			static_friction = 0.300000,
			restitution = 0.400000,
			kinetic_friction = 0.050000,
		},
		LevelEditorExtension = 
		{
			rotate_icon_offset = {-60,-40},
			trash_icon_offset = {-41,26},
			rotate_divisions = 8.000000,
			teleportable = true,
		},
		PositionExtension = 
		{
		},
		SuckableExtension = 
		{
		},
		ThwackableExtension = 
		{
		},
		AltCollisionExtension = 
		{
		},
	},
}

-- Begin Scripting --
help_text_header = "$00645"
help_text = "$00646"

function OnInit()

	gravity_new = -33
	this:SetAltCollision("marsh_bud_gravity_look_up")

end

function UpdateEffects()
	if not alien_dash or not alien_dash:IsValid() then
		current_position = this:GetPosition()

		alien_dash = this:CreateEffect( "marshmallow_bud/alien_dash" )

		return
	end
end

function Update()

	Profile_Start("marsh_bug_gravity")
	UpdateEffects()
	
	local suckable_ext = this:GetSuckableExtension()
	local motion_model = this:GetMotionModel()

	if suckable_ext then
	
		if suckable_ext:WasRecentlySucked() then
			if motion_model:GetCurrentMotionName() ~= "eaten" then
				motion_model:PushMotion( "eaten", false, true )
			end
		else
			--go back to default
			if motion_model:GetCurrentMotionName() == "eaten" then
				motion_model:PopMotion()
			end
		end
	end
	
	Profile_Stop("marsh_bug_gravity")
	
end

function OnDestroy()

	local edible_ext = this:GetEdibleExtension()

	if edible_ext:GetEaten() then
		World_SetGravity(World_GetGravity() * -500, -1)
		
		for object in World_GetObjects() do
			if (object:IsPhysicsEnabled()) then
				
				local facing = object:GetFacing()
				if object:GetFlipped() then facing = facing * -1 end
				
				object:ForceFacing( Vector2( facing.x * -1, facing.y ))
				object:SetFlipped(not object:GetFlipped())
			end
		end
	end
	
end