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

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

private alias object.value0 : object.timer

// States
private alias 0 : HPZEGGMANHORN_IDLE
private alias 1 : HPZEGGMANHORN_PLAYINGNOISE
private alias 2 : HPZEGGMANHORN_FINISHEDNOISE
private alias 3 : HPZEGGMANHORN_DEBRIS


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

event ObjectUpdate
	switch object.state
	default
	case HPZEGGMANHORN_IDLE
		break

	case HPZEGGMANHORN_PLAYINGNOISE
		object.frame = object.timer
		object.frame &= 3
		if object.frame == 0
			screen.shakeY = 2
		end if
		
		object.frame >>= 1
		if object.timer > 0
			object.timer--
		else
			object.state = HPZEGGMANHORN_IDLE
		end if
		break

	case HPZEGGMANHORN_FINISHEDNOISE
		if object.timer > 0
			object.frame = 1
			object.timer--
		else
			object.frame = 0
			object.state = HPZEGGMANHORN_IDLE
		end if
		break
		
	case HPZEGGMANHORN_DEBRIS
		object.frame = 0
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.yvel += 0x3800

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

	end switch

end event


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


event ObjectStartup
	LoadSpriteSheet("HPZ/Objects.gif")
	SpriteFrame(-32, -60, 32, 40, 451, 214)
	SpriteFrame(-34, -64, 34, 48, 449, 165)
	SpriteFrame(0, -44, 20, 20, 430, 132)
end event


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

event RSDKDraw
	DrawSprite(2)
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("HPZ/Objects.gif")
	SpriteFrame(-32, -60, 32, 40, 451, 214)
	SpriteFrame(-34, -64, 34, 48, 449, 165)
	SpriteFrame(0, -44, 20, 20, 430, 132)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
