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

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

private alias -1 : DRAWORDER_PLAYER

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 players shouldn't have insta-shields
	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/Items3.gif")
	SpriteFrame(-16, -24, 40, 40, 173, 214)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
