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

//-------Aliases-------//
private alias 48 : TYPE_VPLATFORM

// Function declarations
reserve function VPlatform_DebugDraw
reserve function VPlatform_DebugSpawn

// Static Values
public value VPlatform_value40 = 0;

// Tables

function VPlatform_DebugDraw
	temp0 = object[0].value17
	temp0 -= VPlatform_value40
	DrawSprite(temp0)
end function


function VPlatform_DebugSpawn
	temp0 = object[0].value17
	temp0 -= VPlatform_value40
	CreateTempObject(TypeName[V Platform], temp0, object.xpos, object.ypos)
	object[tempObjectPos].value0 = object.ypos
	object[tempObjectPos].direction = object.direction
	if object[tempObjectPos].propertyValue == 0
		object[tempObjectPos].value1 = -32
		object[tempObjectPos].value2 = 32
	else
		object[tempObjectPos].value1 = -24
		object[tempObjectPos].value2 = 24
	end if
end function


event ObjectMain
	temp6 = object.ypos
	GetTableValue(temp0, 14, StageSetup_table9)
	if object.direction == FLIP_X
		FlipSign(temp0)
		temp0 += 0x8000
	end if
	temp0 <<= 8
	object.ypos = object.value0
	object.ypos -= temp0
	temp6 &= -0x10000
	temp7 = object.ypos
	temp7 &= -0x10000
	temp7 -= temp6
	temp2 = 0
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		GetBit(temp0, object.value3, temp2)
		if temp0 == 1
			object[currentPlayer].ypos += temp7
		end if
		SetBit(object.value3, temp2, 0)
		BoxCollisionTest(C_PLATFORM, object.entityPos, object.value1, -16, object.value2, 0, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			SetBit(object.value3, temp2, 1)
		end if
		temp2++
	next
end event


event ObjectDraw
	DrawSprite(object.propertyValue)
end event


event ObjectStartup
	LoadSpriteSheet("CPZ/Objects.gif")
	SpriteFrame(-32, -16, 64, 27, 136, 155)
	SpriteFrame(-24, -16, 48, 26, 136, 183)
	foreach (TypeName[V Platform], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value0 = object[arrayPos0].ypos
		if object[arrayPos0].propertyValue == 0
			object[arrayPos0].value1 = -32
			object[arrayPos0].value2 = 32
		else
			object[arrayPos0].value1 = -24
			object[arrayPos0].value2 = 24
		end if
	next
	temp0 = 0
	VPlatform_value40 = DebugMode_ObjCount
	while temp0 < 2
		SetTableValue(TypeName[V Platform], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(VPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(VPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

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