-- Doesn't work as intended

function main(self)

	self:AnimationStep()

	if self.State == 0 then
		self.ObjectTypeFlags = 0x80
		self.Flags.AlwaysActive = true
		if GetImgStr(self.Image) == "CUSTOM_PEG" then
			self.HitRect = {-25,-8,25,32}
			self.LastFrame = 12
			self.AppearSound = "CUSTOM_PEGSLIDE"
		elseif GetImgStr(self.Image) == "CUSTOM_SLIDERPEG" then
			self.HitRect = {-35,-6,25,32}
			self.LastFrame = 5
			self.AppearSound = "CUSTOM_PEGSLIDE2"
		end
		-- On/off:
		if self.Smarts ~= 0 then
			self.State = 1100 -- just a peg
		else
			self.State = 1 -- TogglePeg
		end
		-- Defaults: 
		if self.SpeedX == 0 then
			self.SpeedX = 1500
		end
		if self.SpeedY == 0 then
			self.SpeedY = 1500
		end
		-- Counter - works as different TogglePegs with numbers 2, 3, 4:
		if self.Counter == 2 then
			self.Speed = 1500
		elseif self.Counter == 3 then
			self.Speed = 3000
		elseif self.Counter == 4 then
			self.Speed = 4500
		end
	end
	-- visible:
	if self.State == 130 then
		-- hiding:
		if (GetTime() + self.Speed)%(self.SpeedX+self.SpeedY) > self.SpeedX then
			self:SetAnimation("GAME_FORWARD50")
			if GetClaw().X > self.X - 440 and GetClaw().X < self.X + 440 and GetClaw().Y > self.Y - 440 and GetClaw().Y < self.Y + 440 then
				PlaySound(self.AppearSound)
			end
			self.State = 131
		end
	end
	-- hiding:
	if self.State == 131 and self.I == 12 then
		self:SetFrame(self.LastFrame)
		self.CountTime = GetTime()
		self.State = 140
	end
	-- hidden:
	if self.State == 140 then
		-- appearing:
		if (GetTime() + self.Speed)%(self.SpeedX+self.SpeedY) < self.SpeedX then
			self:SetAnimation("GAME_BACKWARD50")
			if GetClaw().X > self.X - 440 and GetClaw().X < self.X + 440 and GetClaw().Y > self.Y - 440 and GetClaw().Y < self.Y + 440 then
				PlaySound(self.AppearSound)
			end
			self.State = 141
		end
	end
	-- appearing:
	if self.State == 141 and self.I == 1 then
		self:SetFrame(1)
		self.CountTime = GetTime()
		self.State = 130
	end
	-- standable:
	if self.State >= 1 and self.State <= 141 then
		self.BumpFlags.Platform = self.I <= 3
	end
	-- always on:
	if self.State == 1100 then
		self.State = 1101
	end
	if self.State == 1101 then
		self.State = 1100
	end
end
  