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

//-------Aliases-------//
private alias 62 : TYPE_RINGPLATFORM

// Function declarations
reserve function RingPlatform_DebugDraw
reserve function RingPlatform_DebugSpawn

// Static Values

// Tables
//0x13ECD
private table RingPlatform_table0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
end table

function RingPlatform_DebugDraw
	DrawSprite(0)
end function


function RingPlatform_DebugSpawn
	CreateTempObject(TypeName[Ring Platform], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 4
	object[tempObjectPos].direction = object.direction
end function


event ObjectMain
	temp0 = object.angle
	if object.direction == FLIP_NONE
		object.angle++
	else
		object.angle--
	end if
	temp6 = object.xpos
	temp7 = object.ypos
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		temp0 >>= 1
		temp5 = object.angle
		temp5 >>= 1
		Cos256(temp2, temp0)
		temp2 <<= 12
		Sin256(temp3, temp0)
		temp3 <<= 12
		Cos256(temp0, temp5)
		temp0 <<= 12
		Sin256(temp1, temp5)
		temp1 <<= 12
		object.value0 = object.xpos
		object.value1 = object.ypos
		temp4 = 0
		while temp4 < 6
			BoxCollisionTest(C_BOX, object.entityPos, -8, -8, 8, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				temp5 = object.value0
				temp5 &= -0x10000
				object.value2 = object.xpos
				object.value2 &= -0x10000
				temp5 -= object.value2
				object[currentPlayer].xpos += temp5
				temp5 = object.value1
				temp5 &= -0x10000
				object.value2 = object.ypos
				object.value2 &= -0x10000
				temp5 -= object.value2
				object[currentPlayer].ypos += temp5
			end if
			object.xpos += temp2
			object.ypos += temp3
			object.value0 += temp0
			object.value1 += temp1
			temp4++
		loop
		object.xpos = temp6
		object.ypos = temp7
	next
end event


event ObjectDraw
	temp5 = object.angle
	temp5 >>= 1
	temp0 = object.xpos
	temp1 = object.ypos
	Cos256(temp2, temp5)
	temp2 <<= 12
	Sin256(temp3, temp5)
	temp3 <<= 12
	temp4 = 0
	while temp4 < 6
		DrawSpriteXY(0, temp0, temp1)
		temp0 += temp2
		temp1 += temp3
		temp4++
	loop
end event


event ObjectStartup
	LoadSpriteSheet("Global/Items.gif")
	foreach (TypeName[Ring Platform], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 4
	next
	SpriteFrame(-8, -8, 16, 16, 1, 1)
	SetTableValue(TypeName[Ring Platform], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(RingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(RingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

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