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

//-------Aliases-------//
private alias 22 : TYPE_SPECIALRING


// Static Values

// Tables

event ObjectMain
	if object.state == 0
		if object[0].value0 > 49
			BoxCollisionTest(C_TOUCH, object.entityPos, -16, -16, 16, 16, 0, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[0].type = TypeName[Blank Object]
				object[playerCount].type = TypeName[Blank Object]
				object[0].controlMode = -1
				object[0].direction = FLIP_NONE
				ResetObjectEntity(4, TypeName[Blank Object], 0, 0, 0)
				object.drawOrder = 4
				object.state = 1
				object.frame = 32
				StopSfx(SfxName[Flying])
				StopSfx(SfxName[Tired])
				StopSfx(SfxName[RayDive])
				StopSfx(SfxName[RaySwoop])
				PlaySfx(SfxName[Special Ring], 0)
				object[0].left = 0
				object[0].right = 0
				if stage.player2Enabled == 1
					if object[1].value16 == 1
						object[1].controlMode = -1
						object[1].up = 0
						object[1].down = 0
						object[1].left = 0
						object[1].right = 0
						object[1].jumpPress = 0
						object[1].jumpHold = 0
					end if
				end if
			end if
		end if
	end if
	if PlayerObject_SuperState == 1
		ResetObjectEntity(object.entityPos, TypeName[Blank Object], 0, 0, 0)
	end if
end event


event ObjectDraw
	switch object.state
	case 0
		if object[0].value0 > 49
			temp0 = object.frame
			temp0 >>= 2
			if temp0 > 3
				object.direction = FLIP_X
			else
				object.direction = FLIP_NONE
			end if
			DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
			object.frame++
			if object.frame > 31
				object.frame = 0
			end if
		end if
		break
	case 1
		temp0 = object.frame
		temp0 >>= 2
		if temp0 > 11
			object.direction = FLIP_X
		else
			object.direction = FLIP_NONE
		end if
		DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
		if temp0 == 11
			object.direction = FLIP_X
			DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
		else
			if temp0 == 15
				object.direction = FLIP_X
				DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
			end if
		end if
		object.frame++
		if object.frame > 63
			ResetObjectEntity(object.entityPos, TypeName[Blank Object], 0, 0, 0)
		end if
		break
	end switch
end event


event ObjectStartup
	LoadSpriteSheet("Global/Items2.gif")
	SpriteFrame(-32, -32, 64, 64, 83, 1)
	SpriteFrame(-28, -32, 56, 64, 199, 131)
	SpriteFrame(-24, -32, 48, 64, 148, 1)
	SpriteFrame(-16, -32, 32, 64, 223, 66)
	SpriteFrame(-12, -32, 24, 64, 197, 1)
	SpriteFrame(-16, -32, 32, 64, 223, 66)
	SpriteFrame(-24, -32, 48, 64, 148, 1)
	SpriteFrame(-28, -32, 56, 64, 199, 131)
	SpriteFrame(0, -32, 32, 64, 222, 1)
	SpriteFrame(-16, -32, 48, 64, 101, 66)
	SpriteFrame(-24, -32, 56, 64, 150, 66)
	SpriteFrame(0, -32, 32, 64, 156, 131)
	SpriteFrame(-24, -32, 56, 64, 150, 66)
	SpriteFrame(-16, -32, 48, 64, 101, 66)
	SpriteFrame(0, -32, 32, 64, 222, 1)
	SpriteFrame(-32, -32, 32, 64, 124, 131)
	if saved.superStates == 0
		temp0 = 63
	else
		temp0 = 127
	end if
	if specialStage.emeralds >= temp0
		foreach (TypeName[Special Ring], arrayPos0, ALL_ENTITIES)
			ResetObjectEntity(arrayPos0, TypeName[Blank Object], 0, 0, 0)
		next
	end if
	if options.gameMode == 2
		foreach (TypeName[Special Ring], arrayPos0, ALL_ENTITIES)
			ResetObjectEntity(arrayPos0, TypeName[Blank Object], 0, 0, 0)
		next
	end if
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Items2.gif")
	SpriteFrame(-32, -32, 64, 64, 83, 1)
end event
