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

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

private alias -1 : DRAWORDER_PLAYER

// Player aliases
private alias object.state   : player.state
private alias object.xpos    : player.xpos
private alias object.ypos    : player.ypos
private alias object.value7  : player.invincibleTimer
private alias object.value38 : player.hitboxTop
private alias object.value39 : player.hitboxBottom
private alias object.value40 : player.hitboxLeft
private alias object.value41 : player.hitboxRight

// Super States
private alias 1 : SUPERSTATE_SUPER


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

event ObjectUpdate
	// Dead player shouldn't have an insta-shield
	if player[-playerCount].state == Player_State_Death
		object.type = TypeName[Blank Object]
	end if

	if player[-playerCount].state == Player_State_Drown
		object.type = TypeName[Blank Object]
	end if

	// Draw right below the player
	object.drawOrder = DRAWORDER_PLAYER

	object.frame++
	if object.frame >= 7
		object.frame = 0
		object.type = TypeName[Blank Object]
	else
		player[-playerCount].invincibleTimer = 1
	end if

	if object.type == TypeName[Insta Shield]
		player[-playerCount].hitboxTop = -24
		player[-playerCount].hitboxBottom = 24
		player[-playerCount].hitboxLeft = -24
		player[-playerCount].hitboxRight = 24
	else
		player[-playerCount].hitboxTop = C_BOX
		player[-playerCount].hitboxBottom = C_BOX
		player[-playerCount].hitboxLeft = C_BOX
		player[-playerCount].hitboxRight = C_BOX
	end if

end event


event ObjectDraw
	if Player_superState != SUPERSTATE_SUPER
		DrawSpriteXY(object.frame, object[-playerCount].xpos, object[-playerCount].ypos)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("Global/Items3.gif")
	
	SpriteFrame(0, 0, 1, 1, 1, 1)
	SpriteFrame(-12, -19, 19, 19, 148, 155)
	SpriteFrame(0, -16, 18, 21, 94, 231)
	SpriteFrame(-3, 2, 27, 24, 113, 228)
	SpriteFrame(-24, -16, 31, 38, 141, 214)
	SpriteFrame(-16, -24, 40, 40, 173, 214)
	SpriteFrame(-24, -16, 41, 40, 214, 214)
end event


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

event RSDKDraw
	DrawSprite(0)
end event


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