// ----------------------------------
// RSDK Project: Sonic 1
// 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("LZ/Objects.gif")

	// Sprite frames
	SpriteFrame(-2, -2, 4, 4, 61, 1)
	SpriteFrame(-3, -3, 6, 6, 61, 6)
	SpriteFrame(-4, -4, 8, 8, 68, 4)
	SpriteFrame(-6, -6, 12, 12, 77, 0)
	SpriteFrame(-8, -8, 16, 16, 90, 1)
	SpriteFrame(-8, -12, 16, 24, 136, 34)
	SpriteFrame(-8, -10, 16, 20, 204, 1)
	SpriteFrame(-8, -10, 0, 0, 204, 1)
	SpriteFrame(-8, -12, 16, 24, 170, 34)
	SpriteFrame(-8, -10, 16, 20, 221, 1)
	SpriteFrame(-8, -10, 0, 0, 221, 1)
	SpriteFrame(-8, -12, 16, 24, 153, 34)
	SpriteFrame(-8, -10, 16, 20, 238, 1)
	SpriteFrame(-8, -10, 0, 0, 238, 1)
	SpriteFrame(-8, -12, 16, 24, 153, 34)
	SpriteFrame(-8, -10, 16, 20, 187, 22)
	SpriteFrame(-8, -10, 0, 0, 187, 22)
	SpriteFrame(-8, -12, 16, 24, 170, 34)
	SpriteFrame(-8, -10, 16, 20, 204, 22)
	SpriteFrame(-8, -10, 0, 0, 204, 22)
	SpriteFrame(-8, -12, 16, 24, 119, 34)
	SpriteFrame(-8, -10, 16, 20, 187, 1)
	SpriteFrame(-8, -10, 0, 0, 187, 1)
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-2, -2, 4, 4, 61, 1)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
