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

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

private alias object.value0 : object.timer

// States
private alias 0 : ORIGINALGEM_IDLE
private alias 1 : ORIGINALGEM_FADEOUT


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

event ObjectUpdate
	// Check interaction with players
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_SOLID, object.entityPos, -24, -16, 24, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)

		if checkResult == COL_TOP
			if object.state == ORIGINALGEM_IDLE
				// Start fading out to the level select
				PlaySfx(SfxName[Exit SS], false)
				object.timer = -384
				object.priority = PRIORITY_ACTIVE
				object.state++
			end if
		end if
	next

	switch object.state
	case ORIGINALGEM_FADEOUT
		music.volume -= 2
		
		if object.timer < 384
			object.timer += 8
		else
			starPostID = 0
			stage.activeList = PRESENTATION_STAGE
			stage.listPos = 5
			LoadStage()
		end if
		
		if object.timer > 0
			SetScreenFade(0, 0, 0, object.timer)
		end if
		break
		
	end switch

end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("HPZ/Objects.gif")
	SpriteFrame(-32, -16, 64, 32, 1, 223)
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("HPZ/Objects.gif")
	SpriteFrame(-32, -16, 64, 32, 1, 223)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
