// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: Secret Door Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.value0 : object.offset.y


// ========================
// Events
// ========================

event ObjectUpdate
	if object.state == 0
		if object.offset.y > 0
			object.offset.y -= 0x80000
		end if
	else
		if object.offset.y < 0x400000
			object.offset.y += 0x80000
		else
			object.priority = PRIORITY_BOUNDS
		end if
	end if

	object.ypos -= object.offset.y
	if object.offset.y == 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_SOLID, object.entityPos, -8, -32, 8, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		next
	else
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_SOLID, object.entityPos, -8, -32, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		next
	end if
	object.ypos += object.offset.y
end event


event ObjectDraw
	temp0 = object.offset.y
	FlipSign(temp0)
	temp0 += object.ypos
	DrawSpriteFX(0, FX_FLIP, object.xpos, temp0)
end event


event ObjectStartup
	LoadSpriteSheet("MBZ/Objects.gif")
	SpriteFrame(-8, -32, 16, 64, 93, 312)
	
	foreach (TypeName[Secret Door], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 4
	next
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
end event


event RSDKLoad
	LoadSpriteSheet("MBZ/Objects.gif")
	SpriteFrame(-8, -32, 16, 64, 93, 312)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
