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

//-------Aliases-------//
private alias 71 : TYPE_HPLATFORM2

// Function declarations
reserve function HPlatform2_DebugDraw
reserve function HPlatform2_DebugSpawn

// Static Values

// Tables

function HPlatform2_DebugDraw
	DrawSprite(0)
end function


function HPlatform2_DebugSpawn
	CreateTempObject(TypeName[H Platform 2], 0, object.xpos, object.ypos)
	object[tempObjectPos].value0 = object.xpos
	object[tempObjectPos].propertyValue = object.direction
end function


event ObjectMain
	temp6 = object.xpos
	GetTableValue(temp0, 14, StageSetup_table9)
	if object.propertyValue == 1
		FlipSign(temp0)
		temp0 += 0x8000
	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.value1, temp2)
		if temp0 == 1
			object[currentPlayer].xpos += temp7
		end if
		SetBit(object.value1, temp2, 0)
		BoxCollisionTest(C_BOX, object.entityPos, -32, -12, 32, 12, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		switch checkResult
		case 1
			SetBit(object.value1, temp2, 1)
			break
		case 2
		case 3
			if object[currentPlayer].state == PlayerObject_KnuxWallClimb
				object[currentPlayer].value1 = 0
				object[currentPlayer].animation = ANI_GLIDING_DROP
				object[currentPlayer].state = PlayerObject_KnuxGlideDrop
			end if
			break
		case 4
			if object[currentPlayer].gravity == GRAVITY_GROUND
				CallFunction(PlayerObject_Kill)
			end if
			break
		end switch
		temp2++
	next
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("MPZ/Objects.gif")
	SpriteFrame(-32, -12, 64, 24, 383, 207)
	foreach (TypeName[H Platform 2], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value0 = object[arrayPos0].xpos
	next
	SetTableValue(TypeName[H Platform 2], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(HPlatform2_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(HPlatform2_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
