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

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

private alias object.value0 : object.timer

private alias 0 : INVINCIBILITY_SPAWNER
private alias 1 : INVINCIBILITY_SPARKLES

// Player Aliases
private alias object.value18 : player.sortedDrawOrder


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

event ObjectUpdate
	if object.state == INVINCIBILITY_SPAWNER
		// Bug Details:
		// - In the original 2013 release of S1 this was meant to be an invalid Draw Order,
		//    separate from the -1 of DRAWORDER_PLAYER
		// - In Origins however, they turned Draw Order 7 into a real thing, retroactively turning this into an actually valid thing...
		//    It's nothing too major at all, but just something interesting of note
		object.drawOrder = 7
		
		object.timer++
		if object.timer > 3
			object.timer = 0
			CreateTempObject(TypeName[Invincibility], 0, object[-playerCount].xpos, object[-playerCount].ypos)
			object[tempObjectPos].state = INVINCIBILITY_SPARKLES
			object[tempObjectPos].inkEffect = INK_ALPHA
			object[tempObjectPos].alpha = 256
			object[tempObjectPos].drawOrder = player[-playerCount].sortedDrawOrder
		end if

		object.frame = ringFrame
		object.frame &= 3
	else
		object.frame = ringFrame
		object.frame &= 3
		object.alpha -= 8
		if object.alpha == 120
			object.type = TypeName[Blank Object]
		end if
	end if
end event


event ObjectDraw
	switch object.state
	case INVINCIBILITY_SPAWNER
		if object.timer == 0
			DrawSpriteXY(object.frame, object[-playerCount].xpos, object[-playerCount].ypos)
		end if
		break
		
	case INVINCIBILITY_SPARKLES
		object.alpha += 8
		DrawSpriteFX(object.frame, FX_INK, object.xpos, object.ypos)
		object.alpha -= 8
		break
		
	end switch
end event


event ObjectStartup
	LoadSpriteSheet("Global/Items.gif")
	
	SpriteFrame(-24, -24, 48, 48, 207, 1)
	SpriteFrame(-24, -24, 48, 48, 207, 50)
	SpriteFrame(-24, -24, 48, 48, 207, 99)
	SpriteFrame(-24, -24, 48, 48, 207, 148)
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Global/Items.gif")
	SpriteFrame(-24, -24, 48, 48, 207, 1)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
