// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Eggman Barrier Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 80 : TYPE_EGGMANBARRIER


// Static Values

// Tables

event ObjectMain
	switch object.state
	case 0
		GetTableValue(temp0, 10, StageSetup_table9)
		temp0 >>= 5
		temp0 += 128
		object.alpha += 4
		if object.alpha >= temp0
			object.state = 1
		end if
		break
	case 1
		GetTableValue(object.alpha, 10, StageSetup_table9)
		object.alpha >>= 5
		object.alpha += 128
		if object.value0 > 0
			object.value0--
			if object.value0 == 0
				object.state = 2
			end if
		end if
		break
	case 2
		object.alpha -= 4
		if object.alpha <= 0
			object.type = TypeName[Blank Object]
		end if
		break
	end switch
	if object.propertyValue == 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			temp0 = object[currentPlayer].collisionLeft
			temp0 <<= 16
			temp0 += object[currentPlayer].xpos
			temp1 = object.xpos
			temp1 += 0x80000
			if temp0 < temp1
				object[currentPlayer].xvel = 0
				object[currentPlayer].speed = 0
				object[currentPlayer].xpos = temp1
				temp0 = object[currentPlayer].collisionLeft
				temp0 <<= 16
				object[currentPlayer].xpos -= temp0
			end if
		next
	else
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			temp0 = object[currentPlayer].collisionRight
			temp0 <<= 16
			temp0 += object[currentPlayer].xpos
			temp1 = object.xpos
			temp1 -= 0x80000
			if temp0 > temp1
				object[currentPlayer].xvel = 0
				object[currentPlayer].speed = 0
				object[currentPlayer].xpos = temp1
				temp0 = object[currentPlayer].collisionRight
				temp0 <<= 16
				object[currentPlayer].xpos -= temp0
			end if
		next
	end if
end event


event ObjectDraw
	DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone11")
	if checkResult == 1
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(-8, -64, 16, 128, 294, 1)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-8, -64, 16, 128, 463, 1)
	end if
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
