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

//-------Aliases-------//
private alias 47 : TYPE_HPLATFORM

// Function declarations
reserve function HPlatform_DebugDraw
reserve function HPlatform_DebugSpawn

// Static Values
public value HPlatform_value39 = 0;

// Tables

function HPlatform_DebugDraw
	temp0 = object[0].value17
	temp0 -= HPlatform_value39
	DrawSprite(temp0)
end function


function HPlatform_DebugSpawn
	temp0 = object[0].value17
	temp0 -= HPlatform_value39
	CreateTempObject(TypeName[H Platform], temp0, object.xpos, object.ypos)
	object[tempObjectPos].value0 = object.xpos
	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.xpos
	GetTableValue(temp0, 6, StageSetup_table9)
	if object.direction == FLIP_X
		FlipSign(temp0)
		temp0 += 0x6000
	end if
	temp0 <<= 8
	object.xpos = object.value0
	object.xpos -= temp0
	temp6 &= -0x10000
	temp7 = object.xpos
	temp7 &= -0x10000
	temp7 -= temp6
	temp2 = 0
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		GetBit(temp0, object.value3, temp2)
		if temp0 == 1
			object[currentPlayer].xpos += 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[H Platform], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value0 = object[arrayPos0].xpos
		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
	HPlatform_value39 = DebugMode_ObjCount
	while temp0 < 2
		SetTableValue(TypeName[H Platform], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(HPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(HPlatform_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
