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

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

private alias object.value0 : object.frameTablePos

// States
private alias 0 : GRABPANELPART_DELAYED
private alias 1 : GRABPANELPART_ACTIVE


// ========================
// Tables
// ========================

private table GrabPanelPart_frameTable
	5, 4, 2, 1, 3, 1, 2, 4, 5, 0
end table

private table GrabPanelPart_directionTable
	1, 1, 1, 1, 0
	0, 0, 0, 0, 0
end table

// Just the standard direction table, but flipped
private table GrabPanelPart_missionDirTable
	0, 0, 0, 0, 0
	1, 1, 1, 1, 0
end table


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

event ObjectUpdate
	if object.state == GRABPANELPART_ACTIVE
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.yvel += 0x800

		object.animationTimer++
		if object.animationTimer == 4
			object.animationTimer = 0

			object.frameTablePos++
			if object.frameTablePos >= 10
				object.frameTablePos = 0
			end if
			GetTableValue(object.frame, object.frameTablePos, GrabPanelPart_frameTable)
#platform: USE_STANDALONE
			GetTableValue(object.direction, object.frameTablePos, GrabPanelPart_directionTable)
#endplatform
#platform: USE_ORIGINS
			if game.playMode != BOOT_PLAYMODE_MISSION
				GetTableValue(object.direction, object.frameTablePos, GrabPanelPart_directionTable)
			else
				GetTableValue(object.direction, object.frameTablePos, GrabPanelPart_missionDirTable)
			end if
#endplatform
		end if
	else
		object.propertyValue--
		if object.propertyValue == 0
			object.state = GRABPANELPART_ACTIVE
		end if
	end if

	if object.outOfBounds == true
		object.type = TypeName[Blank Object]
	end if
end event


event ObjectDraw
	DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
end event


event ObjectStartup
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 69)
	SpriteFrame(-8, -16, 16, 32, 66, 92)
	SpriteFrame(-4, -16, 8, 32, 83, 92)
	SpriteFrame(-16, -16, 32, 32, 66, 125)
	SpriteFrame(-4, -16, 8, 32, 92, 92)
	SpriteFrame(-8, -16, 16, 32, 101, 92)
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 69)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "delay")
end event
