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

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

private alias object.value0 : object.timer
private alias object.value1 : object.drawPos.x
private alias object.value2 : object.drawPos.y

private alias 0 : COUNTDOWNBUBBLE_SETUP
private alias 1 : COUNTDOWNBUBBLE_FRAME1
private alias 2 : COUNTDOWNBUBBLE_FRAME2
private alias 3 : COUNTDOWNBUBBLE_FRAME3
private alias 4 : COUNTDOWNBUBBLE_FRAME4
private alias 5 : COUNTDOWNBUBBLE_FRAME5
private alias 6 : COUNTDOWNBUBBLE_FRAME6
private alias 7 : COUNTDOWNBUBBLE_FRAME7
private alias 8 : COUNTDOWNBUBBLE_FRAME8


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

event ObjectUpdate
	switch object.state
	case COUNTDOWNBUBBLE_SETUP
		object.ypos += object.yvel
		object.timer++
		if object.timer > 6
			object.timer = 0
			object.frame++
		end if

		if object.frame < 5
			Sin(object.xpos, object.angle)
			object.xpos <<= 9
			object.xpos += object.drawPos.x
			object.angle += 4
			object.angle &= 0x1FF
		else
			temp0 = object.propertyValue
			temp0 *= 3
			object.frame += temp0
			object.drawPos.x = object.ixpos
			object.drawPos.x -= screen.xoffset
			object.drawPos.y = object.iypos
			object.drawPos.y -= screen.yoffset
			object.state++
		end if
		break

	case COUNTDOWNBUBBLE_FRAME1
		object.timer++
		if object.timer == 6
			object.timer = 0
			object.frame++
			object.state++
		end if
		break

	case COUNTDOWNBUBBLE_FRAME2
		object.timer++
		if object.timer == 6
			object.timer = 0
			object.frame++
			object.state++
		end if
		break

	case COUNTDOWNBUBBLE_FRAME3
		object.timer++
		if object.timer == 8
			object.timer = 0
			object.frame--
			object.state++
		end if
		break

	case COUNTDOWNBUBBLE_FRAME4
		object.timer++
		if object.timer == 8
			object.timer = 0
			object.frame++
			object.state++
		end if
		break

	case COUNTDOWNBUBBLE_FRAME5
		object.timer++
		if object.timer == 8
			object.timer = 0
			object.frame--
			object.state++
		end if
		break

	case COUNTDOWNBUBBLE_FRAME6
		object.timer++
		if object.timer == 8
			object.timer = 0
			object.frame++
			object.state++
		end if
		break

	case COUNTDOWNBUBBLE_FRAME7
		object.timer++
		if object.timer == 8
			object.timer = 0
			object.frame--
			object.state++
		end if
		break

	case COUNTDOWNBUBBLE_FRAME8
		object.timer++
		if object.timer == 9
			object.type = TypeName[Blank Object]
		end if
		break
		
	end switch
end event


event ObjectDraw
#platform: USE_ORIGINS
	if game.playMode == BOOT_PLAYMODE_MIRRORING
		object.direction = FLIP_X
		if object.state == COUNTDOWNBUBBLE_SETUP
			DrawSpriteFX(object.propertyValue, FX_FLIP, object.xpos, object.ypos)
		else
			DrawSpriteScreenFX(object.frame, FX_FLIP, object.drawPos.x, object.drawPos.y)
		end if
	else
		if object.state == COUNTDOWNBUBBLE_SETUP
			DrawSprite(object.frame)
		else
			DrawSpriteScreenXY(object.frame, object.drawPos.x, object.drawPos.y)
		end if
	end if
#endplatform

#platform: USE_STANDALONE
	if object.state == COUNTDOWNBUBBLE_SETUP
		DrawSprite(object.frame)
	else
		DrawSpriteScreenXY(object.frame, object.drawPos.x, object.drawPos.y)
	end if
#endplatform
end event


event ObjectStartup
	LoadSpriteSheet("CPZ/Objects3.gif")

	SpriteFrame(-2, -2, 4, 4, 157, 2)
	SpriteFrame(-3, -3, 6, 6, 156, 9)
	SpriteFrame(-4, -4, 8, 8, 155, 17)
	SpriteFrame(-6, -6, 12, 12, 209, 36)
	SpriteFrame(-8, -8, 16, 16, 207, 51)
	SpriteFrame(-8, -12, 16, 24, 1, 22)
	SpriteFrame(-8, -10, 16, 20, 1, 1)
	SpriteFrame(0, 0, 1, 1, 1, 1)
	SpriteFrame(-8, -12, 16, 24, 35, 22)
	SpriteFrame(-8, -10, 16, 20, 18, 1)
	SpriteFrame(0, 0, 1, 1, 1, 1)
	SpriteFrame(-8, -12, 16, 24, 18, 22)
	SpriteFrame(-8, -10, 16, 20, 35, 1)
	SpriteFrame(0, 0, 1, 1, 1, 1)
	SpriteFrame(-8, -12, 16, 24, 18, 22)
	SpriteFrame(-8, -10, 16, 20, 52, 1)
	SpriteFrame(0, 0, 1, 1, 1, 1)
	SpriteFrame(-8, -12, 16, 24, 35, 22)
	SpriteFrame(-8, -10, 16, 20, 69, 1)
	SpriteFrame(0, 0, 1, 1, 1, 1)
	SpriteFrame(-8, -12, 16, 24, 52, 22)
	SpriteFrame(-8, -10, 16, 20, 86, 1)
	SpriteFrame(0, 0, 1, 1, 1, 1)
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("CPZ/Objects3.gif")
	SpriteFrame(-2, -2, 4, 4, 157, 2)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
