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

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

private alias object.propertyValue : object.targetPlayer

// Player Aliases
private alias object.xpos : player.xpos
private alias object.ypos : player.ypos
private alias object.direction : player.direction
private alias object.animation : player.animation
private alias object.collisionBottom : player.collisionBottom


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

event ObjectUpdate
	// Update object movement
	object.xpos += object.xvel
	object.ypos += object.yvel

	switch object.frame
	case 0
	case 1
	case 2
		object.animationTimer++
		if object.animationTimer > 3
			object.frame++
			object.animationTimer = 0
		end if
		break

	case 3
		object.animationTimer++
		if object.animationTimer > 3
			object.type = TypeName[Blank Object]
		end if
		break

	case 4
	case 5
	case 6
	case 7
	case 8
	case 9
		object.animationTimer++
		if object.animationTimer > 1
			object.frame++
			object.animationTimer = 0
		end if
		break

	case 10
		object.animationTimer++
		if object.animationTimer > 1
			object.frame = 4
			object.animationTimer = 0
		end if
		break

	end switch

end event


event ObjectDraw
	if object.frame > 3
		// Spindash dust variant

		// Seek into this object's targeted player
		currentPlayer = object.targetPlayer

		// Make the values match
		object.direction = player[currentPlayer].direction
		object.xpos = player[currentPlayer].xpos
		object.iypos = player[currentPlayer].collisionBottom
		object.ypos += player[currentPlayer].ypos

		// Erase this object if the player isn't spindashing
		if player[currentPlayer].animation != ANI_SPINDASH
			object.type = TypeName[Blank Object]
		else
			DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
		end if
	else

		// Dust Puff variant (from skidding and etc.)
		DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)

	end if
end event


event ObjectStartup

	LoadSpriteSheet("Global/Items.gif")

	// Dust frames
	SpriteFrame(-7, -11, 13, 14, 85, 143)
	SpriteFrame(-7, -11, 13, 14, 99, 143)
	SpriteFrame(-6, -11, 13, 14, 113, 143)
	SpriteFrame(-7, -11, 13, 14, 127, 143)
	SpriteFrame(-32, -10, 32, 10, 58, 245)
	SpriteFrame(-32, -12, 32, 12, 91, 243)
	SpriteFrame(-32, -16, 32, 16, 124, 239)
	SpriteFrame(-32, -18, 32, 18, 157, 237)
	SpriteFrame(-32, -20, 32, 20, 190, 235)
	SpriteFrame(-32, -21, 32, 21, 223, 210)
	SpriteFrame(-32, -23, 32, 23, 223, 232)
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Global/Items.gif")
	SpriteFrame(-7, -11, 13, 14, 85, 143)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
