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

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

private alias 0 : EGGMANWINDOWANI_WINDOWCLOSED
private alias 1 : EGGMANWINDOWANI_OPENWINDOW
private alias 2 : EGGMANWINDOWANI_IDLE
private alias 3 : EGGMANWINDOWANI_LAUGH
private alias 4 : EGGMANWINDOWANI_STUNNED
private alias 5 : EGGMANWINDOWANI_CLOSEWINDOW

// Player Aliases
private alias object.animation : player.animation


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

event ObjectUpdate
	// This event exists in the code, but it's empty...
	
	// Perhaps animation was originally done here, before being moved to ObjectDraw instead?
	// Normally you wouldn't want animation in an ObjectDraw, but it seems to be intentional here so that Eggman keeps laughing after Sonic dies
end event


event ObjectDraw
	switch object.animation
	case EGGMANWINDOWANI_WINDOWCLOSED
		DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
		break

	case EGGMANWINDOWANI_OPENWINDOW
		object.animationTimer++
		if object.animationTimer == 4
			object.animationTimer = 0
			object.frame++
			if object.frame == 4
				object.animation = EGGMANWINDOWANI_IDLE
			end if
		end if
		
		DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
		break

	case EGGMANWINDOWANI_IDLE
		DrawSpriteFX(4, FX_FLIP, object.xpos, object.ypos)
		break

	case EGGMANWINDOWANI_LAUGH
		temp0 = object.animationTimer
		temp0 &= 15
		temp0 >>= 3
		temp0 += 5
		object.animationTimer++
		if object.animationTimer == 50
			object.animationTimer = 0
			if player[0].animation != ANI_DYING
				object.animation = EGGMANWINDOWANI_IDLE
			end if
		end if

		DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
		break

	case EGGMANWINDOWANI_STUNNED
		temp0 = object.animationTimer
		object.animationTimer++
		if object.animationTimer == 50
			object.animationTimer = 0
			object.animation = EGGMANWINDOWANI_IDLE
		end if

		DrawSpriteFX(7, FX_FLIP, object.xpos, object.ypos)
		break

	case EGGMANWINDOWANI_CLOSEWINDOW
		object.animationTimer++
		if object.animationTimer == 4
			object.animationTimer = 0
			object.frame--
			if object.frame == 0
				object.animation = EGGMANWINDOWANI_WINDOWCLOSED
			end if
		end if

		DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
		break

	end switch
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone12")
	if checkResult == true
		LoadSpriteSheet("DEZ/Objects.gif")

		// 0 - 3: Opening Window Frames (played in reverse order for closing)
		SpriteFrame(-16, -12, 32, 24, 133, 114)
		SpriteFrame(-16, -12, 32, 24, 100, 114)
		SpriteFrame(-16, -12, 32, 24, 67, 114)
		SpriteFrame(-16, -12, 32, 24, 34, 114)

		// 4: Normal Frame
		SpriteFrame(-16, -12, 32, 24, 1, 114)

		// 5 - 6: Laughing Frames
		SpriteFrame(-16, -12, 32, 24, 166, 114)
		SpriteFrame(-16, -12, 32, 24, 199, 114)

		// 7: Stunned Frame
		SpriteFrame(-16, -12, 32, 24, 232, 114)
	else
		LoadSpriteSheet("MBZ/Objects.gif")

		// 0 - 3: Opening Window Frames (played in reverse order for closing)
		SpriteFrame(-16, -12, 32, 24, 645, 114)
		SpriteFrame(-16, -12, 32, 24, 612, 114)
		SpriteFrame(-16, -12, 32, 24, 579, 114)
		SpriteFrame(-16, -12, 32, 24, 546, 114)

		// 4: Normal Frame
		SpriteFrame(-16, -12, 32, 24, 513, 114)

		// 5 - 6: Laughing Frames
		SpriteFrame(-16, -12, 32, 24, 678, 114)
		SpriteFrame(-16, -12, 32, 24, 711, 114)

		// 7: Stunned Frame
		SpriteFrame(-16, -12, 32, 24, 744, 114)
	end if
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone12")
	if checkResult == true
		LoadSpriteSheet("DEZ/Objects.gif")
		SpriteFrame(-16, -12, 32, 24, 133, 114) // peekin'
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-16, -12, 32, 24, 645, 114)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
