// ----------------------------------
// RSDK Project: Sonic 1
// Script Description: Special Finish 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.textPos
private alias object.value2  : object.rotateSpeed
private alias object.value3  : object.scorePos
private alias object.value4  : object.ringPos
private alias object.value5  : object.ringBonus
private alias object.value6  : object.emeraldAlpha
private alias object.value7  : object.continuePos
private alias object.value8  : object.hasContinue
private alias object.value9  : object.messageState
private alias object.value10 : object.specialListPos
private alias object.value11 : object.emeralds

// States
private alias  0 : SPECIALFINISH_SETUPSPIN
private alias  1 : SPECIALFINISH_SPINNING
private alias  2 : SPECIALFINISH_SETUPRESULTS
private alias  3 : SPECIALFINISH_FADEIN_DELAY
private alias  4 : SPECIALFINISH_SETUPTEXT
private alias  5 : SPECIALFINISH_ENTERTEXT
private alias  6 : SPECIALFINISH_ENTERRESULTS
private alias  7 : SPECIALFINISH_ENTEREMERALDS
private alias  8 : SPECIALFINISH_TALLYSCORE
private alias  9 : SPECIALFINISH_SHOWRESULTS
private alias 10 : SPECIALFINISH_FADEOUT
private alias 11 : SPECIALFINISH_SAVEANDRETURN
private alias 12 : SPECIALFINISH_HASCONTINUE
private alias 13 : SPECIALFINISH_SHOWCONTINUE
private alias 14 : SPECIALFINISH_SETUPTATTACK
private alias 15 : SPECIALFINISH_EXIT_TATTACK
private alias 16 : SPECIALFINISH_SUPERMSG_DELAY
private alias 17 : SPECIALFINISH_SHOW_SUPERMSG
private alias 18 : SPECIALFINISH_WAITFORCALLBACK

// Player aliases
private alias object.value0 : player.rings

// Music Events
private alias 25 : SLOT_MUSICEVENT_CHANGE

private alias 2 : MUSICEVENT_TRANSITION

private alias StageStatsUsabilityParam5 : stageStat.playerRings

// Achievement Aliases
private alias 9 : ACHIEVEMENT_CHAOSCONNOISSEUR


// ========================
// Function Declarations
// ========================

reserve function SpecialFinish_DisplaySuperMessage


// ========================
// Function Definitions
// ========================

private function SpecialFinish_DisplaySuperMessage
	switch object.messageState
	case 0
		temp0 = screen.xcenter
		FlipSign(temp0)
		temp0 -= 160
		object.textPos -= 16
		if object.textPos <= temp0
			object.textPos = temp0
			object.messageState++
		end if
		break
		
	case 1
		object.textPos += 16
		if object.textPos >= 0
			object.textPos = 0
			object.messageState++
		end if
		break
	end switch
end function


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

event ObjectUpdate
	switch object.state
	case SPECIALFINISH_SETUPSPIN
		object.rotation = Player_stageRotation
		Player_rotateSpeed = 2
		object.rotation <<= 2
		object.rotateSpeed = 8
		object.state = SPECIALFINISH_SPINNING
		break

	case SPECIALFINISH_SPINNING
		object.rotation -= object.rotateSpeed
		if object.rotation < 0
			object.rotation += 0x800
		end if

		object.rotateSpeed += 2
		Player_stageRotation = object.rotation
		Player_stageRotation >>= 2

		if object.rotateSpeed > 248
			if options.gameMode < MODE_TIMEATTACK
				object.state = SPECIALFINISH_SETUPRESULTS
			else
				object.state = SPECIALFINISH_SETUPTATTACK
			end if
		end if
		break

	case SPECIALFINISH_SETUPRESULTS
		object.rotation -= object.rotateSpeed
		if object.rotation < 0
			object.rotation += 0x800
		end if

		object.rotateSpeed += 2
		Player_stageRotation = object.rotation
		Player_stageRotation >>= 2

		if object.timer < 256
			object.timer += 8
			SetScreenFade(0xE0, 0xE0, 0xE0, object.timer)
		else
#platform: USE_ORIGINS
			object.specialListPos = specialStage.listPos
			object.emeralds = specialStage.emeralds
#endplatform

			if Player_isWinner == true
				temp0 = stage.actNum
				temp0--
#platform: USE_STANDALONE
				SetBit(specialStage.emeralds, temp0, true)
#endplatform
#platform: USE_ORIGINS
				SetBit(object.emeralds, temp0, true)
#endplatform
			end if

#platform: USE_ORIGINS
			stageStat.playerRings = player[0].rings
#endplatform
			object.ringBonus = player[0].rings
			object.ringBonus *= 100
			if player[0].rings >= 50
				object.hasContinue = true
			end if

// Due to Origins crashing if I try to wrap "switch <variable>"
// in a platform check, I'll have to use a temp value workaround.
// I am truly sorry.
#platform: USE_STANDALONE
			stage.listPos = specialStage.nextZone
			stage.activeList = REGULAR_STAGE
			temp2 = specialStage.emeralds
#endplatform
#platform: USE_ORIGINS
			temp2 = object.emeralds
#endplatform
			switch temp2
			case 63 // 6 emeralds
				if options.superStates == false
					object.frame = 3
#platform: USE_STANDALONE
					specialStage.listPos++
					specialStage.listPos %= 6
#endplatform
#platform: USE_ORIGINS
					object.specialListPos++
					object.specialListPos %= 6
#endplatform
					temp0 = true
				else
					object.frame = 2
#platform: USE_STANDALONE
					specialStage.listPos = 6
#endplatform
#platform: USE_ORIGINS
					object.specialListPos = 6
#endplatform
					temp0 = true
				end if
				break

			case 127 // 7 emeralds
				object.frame = 3
#platform: USE_STANDALONE
				specialStage.listPos++
				specialStage.listPos %= 7
#endplatform
#platform: USE_ORIGINS
				object.specialListPos++
				object.specialListPos %= 7
#endplatform
				temp0 = true
				break

			default
				object.frame = 2
				temp0 = false
				while temp0 == false
#platform: USE_STANDALONE
					specialStage.listPos++
					if specialStage.listPos > 5
						specialStage.listPos = 0
					end if

					GetBit(temp1, specialStage.emeralds, specialStage.listPos)
#endplatform
#platform: USE_ORIGINS
					object.specialListPos++
					if object.specialListPos > 5
						object.specialListPos = 0
					end if

					GetBit(temp1, object.emeralds, object.specialListPos)
#endplatform
					if temp1 == false
						temp0 = true
					end if
				loop
				break
			end switch

			if Player_isWinner == false
				object.frame = 1
			end if
			object.timer = 0

			temp0 = 0
			while temp0 < 20
				ResetObjectEntity(temp0, TypeName[Blank Object], 0, 0, 0)
				temp0++
			loop
			temp0++
			while temp0 < 0x4A0
				ResetObjectEntity(temp0, TypeName[Blank Object], 0, 0, 0)
				temp0++
			loop

			stage.activeLayer[0] = 9
			stage.activeLayer[1] = 9
			stage.activeLayer[2] = 9
			stage.activeLayer[3] = 9
			object.controlMode = CONTROLMODE_P1
			keyDown[1].left  = false
			keyDown[1].right = false
			object.direction = FLIP_NONE

#platform: USE_ORIGINS
			game.callbackResult = -1
			CallNativeFunction4(NotifyCallback, NOTIFY_SPECIAL_RETRY, Player_isWinner, object.specialListPos, object.emeralds)
			object.state = SPECIALFINISH_WAITFORCALLBACK
#endplatform

#platform: USE_STANDALONE
			if options.gameMode == MODE_SAVEGAME
				arrayPos1 = options.saveSlot
				arrayPos1 <<= 3
				if stage.player2Enabled == true
					saveRAM[arrayPos1] = PLAYER_SONIC_AND_TAILS
				else
					saveRAM[arrayPos1] = stage.playerListPos
				end if
				arrayPos1++
				saveRAM[arrayPos1] = player.lives
				arrayPos1++
				saveRAM[arrayPos1] = player.score
				arrayPos1++
				saveRAM[arrayPos1] = player.scoreBonus
				arrayPos1++
				temp0 = stage.listPos
				temp0++
				if temp0 > saveRAM[arrayPos1]
					saveRAM[arrayPos1] = temp0
				else
					if saveRAM[arrayPos1] >= 0x80
						saveRAM[arrayPos1] = temp0
					end if
				end if
				arrayPos1++
				saveRAM[arrayPos1] = specialStage.emeralds
				arrayPos1++
				saveRAM[arrayPos1] = specialStage.listPos
				WriteSaveRAM()
			end if
			object.state = SPECIALFINISH_FADEIN_DELAY
#endplatform

			SetScreenFade(0xF4, 0xF4, 0xF4, 0xFF)
		end if
		break

	case SPECIALFINISH_FADEIN_DELAY
		if object.timer < 45
			object.timer++
		else
			object.timer = 0
			object.state++
#platform: USE_ORIGINS
			stage.activeList = REGULAR_STAGE
			stage.listPos = specialStage.nextZone
#endplatform
		end if
		SetScreenFade(0xF4, 0xF4, 0xF4, 0xFF)
		break

	case SPECIALFINISH_SETUPTEXT
		PlayMusic(1)
		object.drawOrder = 6
		object.priority = PRIORITY_ACTIVE
		object.inkEffect = INK_ALPHA
		object.alpha = 0

		object.xpos = screen.xcenter
		object.xpos += 128

		object.textPos = screen.xcenter
		FlipSign(object.textPos)
		object.textPos -= 160

		object.scorePos = screen.xcenter
		object.scorePos += 192

		object.ringPos = object.scorePos
		object.ringPos += 32

		object.continuePos = object.ringPos
		object.continuePos += 32

		if stage.debugMode == false
			if specialStage.emeralds >= 0x3F
				CallNativeFunction2(SetAchievement, ACHIEVEMENT_CHAOSCONNOISSEUR, 100)
			end if
		end if
		object.state++
		break

	case SPECIALFINISH_ENTERTEXT
		if object.xpos > 0
			object.xpos -= 16
			if object.xpos < 0
				object.xpos = 0
			end if
		end if

		if object.textPos < 0
			object.textPos += 16
			if object.textPos > 0
				object.textPos = 0
			end if
		else
			object.state++
		end if
		break

	case SPECIALFINISH_ENTERRESULTS
		if object.emeraldAlpha < 0x100
			object.emeraldAlpha += 8
		end if

		if object.scorePos > 0
			object.scorePos -= 16
			if object.scorePos < 0
				object.scorePos = 0
			end if
		end if

		if object.ringPos > 0
			object.ringPos -= 16
			if object.ringPos < 0
				object.ringPos = 0
			end if
		end if

		if object.continuePos > 0
			object.continuePos -= 16
			if object.continuePos < 0
				object.continuePos = 0
			end if
		else
			object.state++
		end if
		break

	case SPECIALFINISH_ENTEREMERALDS
		if object.emeraldAlpha < 0x100
			object.emeraldAlpha += 8
		end if

		object.timer++
		if object.timer > 299
			object.timer = 0
			object.state++
		end if
		break

	case SPECIALFINISH_TALLYSCORE
		if object.ringBonus > 0
			object.ringBonus -= 100
			player.score += 100
		end if

		if player.score >= player.scoreBonus
#platform: USE_STANDALONE
			player.lives++
#endplatform
#platform: USE_ORIGINS
			if game.coinMode == false
				player.lives++
			else
				CallNativeFunction2(NotifyCallback, NOTIFY_ADD_COIN, 1)
			end if
#endplatform
			player.scoreBonus += 50000
			PlaySfx(SfxName[Life], false)
			PauseMusic()
			ResetObjectEntity(SLOT_MUSICEVENT_CHANGE, TypeName[Music Event], MUSICEVENT_TRANSITION, 0, 0)
			object[SLOT_MUSICEVENT_CHANGE].priority = PRIORITY_ACTIVE
		end if

		if object.ringBonus > 0
			object.timer++
			if object.timer == 2
				PlaySfx(SfxName[Score Add], false)
				object.timer = 0
			end if
		else
			if object.hasContinue == false
				object.state++
				if Player_isWinner == true
#platform: USE_ORIGINS
					if specialStage.emeralds >= 63
						// Bug Details(?):
						// - There's something about this callback that causes a crash when
						//    playing as Sonic & Tails with the emerald count set to 7
						// - Since the code responsible for this is in the HE2 side of Origins,
						//    it isn't a bug with Sonic 1 per se, but it's at least worth mentioning
						CallNativeFunction2(NotifyCallback, NOTIFY_STATS_PARAM_2, 0)
					end if
#endplatform
					if specialStage.emeralds == 127
						object.state = SPECIALFINISH_SUPERMSG_DELAY
					end if
				end if
			else
				object.state = SPECIALFINISH_HASCONTINUE
			end if
			object.timer = 0
			PlaySfx(SfxName[Score Total], false)
		end if
		break

	case SPECIALFINISH_SHOWRESULTS
		object.timer++
		if object.timer == 160
			object.timer = 0
			object.state++
			PlaySfx(SfxName[Warp], false)
		end if
		break

	case SPECIALFINISH_FADEOUT
		if object.timer < 400
			object.timer += 8
			SetScreenFade(0xF8, 0xF8, 0xF8, object.timer)
		else
			object.timer = 248
			object.state++
			SetScreenFade(0xF8, 0xF8, 0xF8, 0xFF)
		end if
		break

	case SPECIALFINISH_SAVEANDRETURN
		if object.timer > 0
			object.timer -= 8
		else
			if options.gameMode == MODE_SAVEGAME
				arrayPos1 = options.saveSlot
				arrayPos1 <<= 3
				if stage.player2Enabled == true
					saveRAM[arrayPos1] = PLAYER_SONIC_AND_TAILS
				else
					saveRAM[arrayPos1] = stage.playerListPos
				end if
				arrayPos1++

				saveRAM[arrayPos1] = player.lives
				arrayPos1++

				saveRAM[arrayPos1] = player.score
				arrayPos1++

				saveRAM[arrayPos1] = player.scoreBonus
				arrayPos1++

				temp0 = stage.listPos
				temp0++
				if temp0 > saveRAM[arrayPos1]
					saveRAM[arrayPos1] = temp0
				else
					if saveRAM[arrayPos1] >= 0x80
						saveRAM[arrayPos1] = temp0
					end if
				end if
				arrayPos1++

				saveRAM[arrayPos1] = specialStage.emeralds
				arrayPos1++

				saveRAM[arrayPos1] = specialStage.listPos

				WriteSaveRAM()

#platform: USE_ORIGINS
				recScore = player.score
#endplatform
			end if

			fadeColor = 0x000000

#platform: USE_ORIGINS
			CallNativeFunction2(NotifyCallback, NOTIFY_STATS_RING, stageStat.playerRings)
			stageStat.playerRings = 0
#endplatform

			if stage.listPos < stage.listSize
				LoadStage()
			else
				stage.activeList = PRESENTATION_STAGE
				stage.listPos = 0
				LoadStage()
			end if
		end if
		SetScreenFade(object.timer, object.timer, object.timer, 0xFF)
		break

	case SPECIALFINISH_HASCONTINUE
		object.timer++
		if object.timer == 120
			object.timer = 0
			object.hasContinue++
			object.state++

#platform: USE_ORIGINS
			if game.coinMode != false
				CallNativeFunction2(NotifyCallback, NOTIFY_ADD_COIN, 3)
			end if
#endplatform

			PlaySfx(SfxName[Continue], false)
		end if
		break

	case SPECIALFINISH_SHOWCONTINUE
		if specialStage.emeralds == 127
			CallFunction(SpecialFinish_DisplaySuperMessage)
		end if

		object.timer++
		if object.timer == 360
			object.timer = 0
			object.state = SPECIALFINISH_FADEOUT
			PlaySfx(SfxName[Warp], false)
		end if
		break

	case SPECIALFINISH_SETUPTATTACK
		object.rotation -= object.rotateSpeed
		if object.rotation < 0
			object.rotation += 0x800
		end if

		object.rotateSpeed += 2
		Player_stageRotation = object.rotation
		Player_stageRotation >>= 2
		if object.timer < 480
			object.timer += 8
			music.volume -= 2
		else
			object.timer = 248
			object.state++

			temp0 = 0
			while temp0 < 20
				ResetObjectEntity(temp0, TypeName[Blank Object], 0, 0, 0)
				temp0++
			loop

			temp0++
			while temp0 < 0x4A0
				ResetObjectEntity(temp0, TypeName[Blank Object], 0, 0, 0)
				temp0++
			loop

			stage.activeLayer[0] = 9
			stage.activeLayer[1] = 9
			stage.activeLayer[2] = 9
			stage.activeLayer[3] = 9

			StopMusic()
		end if
		SetScreenFade(0xF8, 0xF8, 0xF8, object.timer)
		break

	case SPECIALFINISH_EXIT_TATTACK
		if object.timer > 0
			object.timer -= 8
		else
			if Player_isWinner == true
				timeAttack.result = stage.seconds
				timeAttack.result *= 100
				temp0 = stage.minutes
				temp0 *= 6000
				timeAttack.result += temp0
				timeAttack.result += stage.milliSeconds
			else
				timeAttack.result = 100000
			end if

			engine.state = 8
		end if
		SetScreenFade(object.timer, object.timer, object.timer, 0xFF)
		break

	case SPECIALFINISH_SUPERMSG_DELAY
		object.timer++
		if object.timer == 120
			object.timer = 0
			object.state++
		end if
		break

	case SPECIALFINISH_SHOW_SUPERMSG
		CallFunction(SpecialFinish_DisplaySuperMessage)
		object.timer++
		if object.timer == 480
			object.timer = 0
			object.state = SPECIALFINISH_FADEOUT
			PlaySfx(SfxName[Warp], false)
		end if
		break

#platform: USE_ORIGINS
	case SPECIALFINISH_WAITFORCALLBACK
		if game.callbackResult >= 0
			object.state = SPECIALFINISH_FADEIN_DELAY
			object.timer = 0
			specialStage.listPos = object.specialListPos
			specialStage.emeralds = object.emeralds
			if options.gameMode == MODE_SAVEGAME
				arrayPos1 = options.saveSlot
				arrayPos1 <<= 3
				if stage.player2Enabled == true
					saveRAM[arrayPos1] = PLAYER_SONIC_AND_TAILS
				else
					saveRAM[arrayPos1] = stage.playerListPos
				end if
				arrayPos1++
				saveRAM[arrayPos1] = player.lives
				arrayPos1++
				saveRAM[arrayPos1] = player.score
				arrayPos1++
				saveRAM[arrayPos1] = player.scoreBonus
				arrayPos1++
				temp0 = stage.listPos
				temp0++
				if temp0 > saveRAM[arrayPos1]
					saveRAM[arrayPos1] = temp0
				else
					if saveRAM[arrayPos1] >= 0x80
						saveRAM[arrayPos1] = temp0
					end if
				end if
				arrayPos1++
				saveRAM[arrayPos1] = specialStage.emeralds
				arrayPos1++
				saveRAM[arrayPos1] = specialStage.listPos
				WriteSaveRAM()
				recScore = player.score
			end if
		end if
		SetScreenFade(0xD0, 0xFF, 0xE0, 0xFF)
		break
#endplatform
	end switch
end event


event ObjectDraw
	switch object.state
	default
	case SPECIALFINISH_SETUPSPIN
	case SPECIALFINISH_SPINNING
	case SPECIALFINISH_SETUPRESULTS
	case SPECIALFINISH_FADEIN_DELAY
	case SPECIALFINISH_SETUPTATTACK
	case SPECIALFINISH_EXIT_TATTACK
#platform: USE_ORIGINS
	case SPECIALFINISH_WAITFORCALLBACK
#endplatform
		break

	case SPECIALFINISH_SETUPTEXT
	case SPECIALFINISH_ENTERTEXT
	case SPECIALFINISH_ENTERRESULTS
	case SPECIALFINISH_ENTEREMERALDS
	case SPECIALFINISH_TALLYSCORE
	case SPECIALFINISH_SHOWRESULTS
	case SPECIALFINISH_FADEOUT
	case SPECIALFINISH_SAVEANDRETURN
	case SPECIALFINISH_HASCONTINUE
	case SPECIALFINISH_SHOWCONTINUE
	case SPECIALFINISH_SUPERMSG_DELAY
	case SPECIALFINISH_SHOW_SUPERMSG
		// BG
		DrawRect(0, 0, screen.xsize, screen.ysize, 0xE0, 0xE0, 0xE0, 0xFF)

		// Message
		temp0 = screen.xcenter
		temp0 += object.xpos
		DrawSpriteScreenXY(0, temp0, 48)
		if object.messageState == 0
			temp0 = screen.xcenter
			temp0 += object.textPos
			DrawSpriteScreenXY(object.frame, temp0, 68)
		else
			temp0 = screen.xcenter
			temp0 += object.textPos
			DrawSpriteScreenXY(26, temp0, 68)
			DrawSpriteScreenXY(27, temp0, 68)
			DrawSpriteScreenXY(28, temp0, 68)
			temp0 = screen.xcenter
			temp0 -= object.textPos
			DrawSpriteScreenXY(29, temp0, 68)
			DrawSpriteScreenXY(30, temp0, 68)
		end if

		// Score
		temp0 = screen.xcenter
		temp0 -= 79
		temp0 += object.scorePos
		DrawSpriteScreenXY(4, temp0, 151)
		temp0 += 151
		DrawNumbers(9, temp0, 153, player.score, 6, 8, 0)

		// Ring Bonus
		temp0 = screen.xcenter
		temp0 -= 79
		temp0 += object.ringPos
		DrawSpriteScreenXY(5, temp0, 167)
		temp0 += 151
		DrawNumbers(9, temp0, 169, object.ringBonus, 5, 8, 0)

		// Continues/Coins
		if object.hasContinue != false
			temp0 = screen.xcenter
			temp0 -= 79
			temp0 += object.continuePos
#platform: USE_ORIGINS
			if game.coinMode == false
#endplatform
				DrawSpriteScreenXY(6, temp0, 183)
				if object.hasContinue == 2
					temp0 += 151
					GetBit(temp1, object.timer, 4)
					temp1 += 7
					if object.state != SPECIALFINISH_SHOWCONTINUE
						temp1 = 7
					end if
					DrawSpriteScreenXY(temp1, temp0, 196)
				end if
#platform: USE_ORIGINS
			else
				DrawSpriteScreenXY(31, temp0, 183)
				DrawSpriteScreenXY(32, temp0, 183)
				if object.hasContinue == 2
					temp0 += 124
					DrawSpriteScreenXY(33, temp0, 183)
					temp2 = object.timer
					temp2 &= 15
					temp2 >>= 2
					temp2 += 34
					DrawSpriteScreenXY(temp2, temp0, 183)
				end if
			end if
#endplatform
		end if

		// Emerald Opacity
		object.animationTimer += 16
		object.animationTimer &= 0x1FF
		Sin(temp0, object.animationTimer)
		temp0 >>= 3
		temp0 += 190
		temp0 *= object.emeraldAlpha
		temp0 >>= 8
		object.alpha = temp0

		temp0 = 0
		temp1 = 19
		temp3 = screen.xcenter
		if specialStage.emeralds == 127
			temp3 += 12
		end if

		// Draw Emeralds
		while temp0 < 7
			GetBit(temp2, specialStage.emeralds, temp0)
			if temp2 == true
				DrawSpriteScreenFX(temp1, FX_INK, temp3, 112)
			end if
			temp0++
			temp1++
		loop
		break
	end switch
end event


event ObjectStartup
	LoadSpriteSheet("Special/Objects.gif")

	SpriteFrame(-32, 0, 56, 56, 63, 401)    // 0  - Oval
	SpriteFrame(-99, 0, 197, 16, 120, 401)  // 1  - "SPECIAL STAGE" large text
	SpriteFrame(-112, 0, 223, 16, 156, 418) // 2  - "CHAOS EMERALDS" large text

	switch stage.playerListPos
	case PLAYER_SONIC_ALONE
	case PLAYER_SONIC_AND_TAILS
		SpriteFrame(-127, 0, 254, 16, 156, 435) // 3  - "SONIC GOT THEM ALL"
		break

	case PLAYER_TAILS_ALONE
		if options.region == false
			SpriteFrame(-127, 0, 254, 16, 156, 452) // 3  - "TAILS GOT THEM ALL"
		else
			SpriteFrame(-127, 0, 254, 16, 156, 469) // 3  - "MILES GOT THEM ALL"
		end if
		break

	case PLAYER_KNUX_ALONE
		SpriteFrame(-149, 0, 298, 16, 156, 486) // 3  - "KNUCKLES GOT THEM ALL"
		break

	end switch

	SpriteFrame(0, 0, 44, 16, 35, 458) // 4  - "SCORE" small text
	SpriteFrame(0, 0, 85, 16, 35, 475) // 5  - "RING BONUS" small text
	SpriteFrame(0, 0, 69, 16, 35, 492) // 6  - "CONTINUE" small text

	// 7-8 - Character icons, dependant on the main character
	switch stage.playerListPos
	case PLAYER_SONIC_ALONE
	case PLAYER_SONIC_AND_TAILS
		SpriteFrame(-8, -11, 16, 23, 399, 376)
		SpriteFrame(-8, -11, 16, 23, 416, 376)
		break

	case PLAYER_TAILS_ALONE
		SpriteFrame(-8, -11, 16, 23, 433, 376)
		SpriteFrame(-8, -11, 16, 23, 450, 376)
		break

	case PLAYER_KNUX_ALONE
		SpriteFrame(-8, -11, 16, 23, 467, 376)
		SpriteFrame(-8, -11, 16, 23, 484, 376)
		break

	end switch

	// 9-18 - Numbers
	SpriteFrame(0, 0, 8, 11, 120, 418)
	SpriteFrame(0, 0, 8, 11, 129, 418)
	SpriteFrame(0, 0, 8, 11, 138, 418)
	SpriteFrame(0, 0, 8, 11, 147, 418)
	SpriteFrame(0, 0, 8, 11, 120, 430)
	SpriteFrame(0, 0, 8, 11, 129, 430)
	SpriteFrame(0, 0, 8, 11, 138, 430)
	SpriteFrame(0, 0, 8, 11, 147, 430)
	SpriteFrame(0, 0, 8, 11, 120, 442)
	SpriteFrame(0, 0, 8, 11, 129, 442)

	// 19-24 - Chaos Emeralds
	SpriteFrame(-28, -4, 24, 24, 176, 276)
	SpriteFrame(-4, -4, 24, 24, 201, 276)
	if options.superStates == false
		SpriteFrame(-52, -4, 24, 24, 226, 276)
	else
		SpriteFrame(-52, -4, 24, 24, 426, 276)
	end if
	SpriteFrame(20, -4, 24, 24, 251, 276)
	SpriteFrame(-76, -4, 24, 24, 276, 276)
	SpriteFrame(44, -4, 24, 24, 301, 276)
	SpriteFrame(-100, -4, 24, 24, 401, 276)

	// Texts
	switch stage.playerListPos
	case PLAYER_SONIC_ALONE
	case PLAYER_SONIC_AND_TAILS
		SpriteFrame(-113, -12, 53, 16, 411, 435) // "NOW"
		SpriteFrame(-51, -12, 70, 16, 156, 435)  // "SONIC"
		SpriteFrame(28, -12, 85, 16, 411, 452)   // "CAN BE"
		SpriteFrame(-77, 12, 76, 16, 411, 469)   // "SUPER"
		SpriteFrame(8, 12, 70, 16, 156, 435)     // "SONIC" (different offset)
		break
		
	case PLAYER_TAILS_ALONE
		if options.region == false
			SpriteFrame(-113, -12, 53, 16, 411, 435) // "NOW"
			SpriteFrame(-51, -12, 70, 16, 156, 452) // "TAILS"
			SpriteFrame(28, -12, 85, 16, 411, 452)  // "CAN BE"
			SpriteFrame(-77, 12, 76, 16, 411, 469)  // "SUPER"
			SpriteFrame(8, 12, 70, 16, 156, 452)    // "TAILS" (different offset)
		else
			SpriteFrame(-113, -12, 53, 16, 411, 435) // "NOW"
			SpriteFrame(-51, -12, 70, 16, 156, 469)  // "MILES"
			SpriteFrame(28, -12, 85, 16, 411, 452)   // "CAN BE"
			SpriteFrame(-77, 12, 76, 16, 411, 469)   // "SUPER"
			SpriteFrame(8, 12, 70, 16, 156, 469)     // "MILES" (different offset)
		end if
		break
		
	case PLAYER_KNUX_ALONE
		SpriteFrame(-134, -12, 53, 16, 411, 435) // "NOW"
		SpriteFrame(-73, -12, 113, 16, 156, 486) // "KNUCKLES"
		SpriteFrame(50, -12, 85, 16, 411, 452)   // "CAN BE"
		SpriteFrame(-99, 12, 76, 16, 411, 469)   // "SUPER"
		SpriteFrame(-14, 12, 113, 16, 156, 486)  // "KNUCKLES" (different offset)
		break
		
	end switch

#platform: USE_ORIGINS
	SpriteFrame(0, 0, 32, 16, 1, 489)    // "COIN"
	SpriteFrame(32, 0, 53, 16, 67, 475)  // " BONUS"
	SpriteFrame(0, 0, 50, 16, 80, 458)   // Coin x 3
	SpriteFrame(-4, -4, 24, 24, 401, 76) // Coin Sparkle 1
	SpriteFrame(-4, -4, 24, 24, 426, 76) // Coin Sparkle 2
	SpriteFrame(-4, -4, 24, 24, 451, 76) // Coin Sparkle 3
	SpriteFrame(-4, -4, 24, 24, 476, 76) // Coin Sparkle 4
#endplatform
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
