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

//-------Aliases-------//
private alias 57 : TYPE_VPLATFORM2

// Function declarations
reserve function VPlatform2_DebugDraw
reserve function VPlatform2_DebugSpawn

// Static Values
public value VPlatform2_value47 = 0;

// Tables

function VPlatform2_DebugDraw
	temp0 = object[0].value17
	temp0 -= VPlatform2_value47
	DrawSprite(temp0)
end function


function VPlatform2_DebugSpawn
	temp0 = object[0].value17
	temp0 -= VPlatform2_value47
	CreateTempObject(TypeName[V Platform 2], 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
	object.ypos += object.yvel
	temp0 = object.value0
	temp0 -= 0x600000
	if object.ypos <= temp0
		object.yvel += 0x800
	else
		object.yvel -= 0x800
	end if
	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 2], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value0 = object[arrayPos0].ypos
		if object[arrayPos0].direction == FLIP_Y
			object[arrayPos0].direction -= 0xC00000
		end if
		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
	VPlatform2_value47 = DebugMode_ObjCount
	while temp0 < 2
		SetTableValue(TypeName[V Platform 2], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(VPlatform2_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(VPlatform2_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
