// ----------------------------------
// 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 44 : TYPE_HPLATFORM

// Function declarations
reserve function HPlatform_DebugDraw
reserve function HPlatform_DebugSpawn

// Static Values

// Tables

function HPlatform_DebugDraw
	DrawSprite(0)
end function


function HPlatform_DebugSpawn
	CreateTempObject(TypeName[H Platform], 0, object.xpos, object.ypos)
	object[tempObjectPos].value1 = object[tempObjectPos].xpos
	if object.direction == FLIP_NONE
		object[tempObjectPos].value1 += 0x680000
		object[tempObjectPos].xvel = -0x10000
		object[tempObjectPos].value0 = 104
	else
		object[tempObjectPos].value1 -= 0x680000
		object[tempObjectPos].xvel = 0x10000
		object[tempObjectPos].value0 = -104
	end if
end function


event ObjectMain
	object.value1 += object.xvel
	object.value2 = object.xvel
	if object.xvel > 0
		object.value0++
		if object.value0 == 104
			FlipSign(object.xvel)
		end if
	else
		object.value0--
		if object.value0 == -104
			FlipSign(object.xvel)
		end if
	end if
	temp0 = object.xpos
	object.xpos = object.value1
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			object[currentPlayer].xpos += object.value2
		end if
	next
	object.xpos = temp0
end event


event ObjectDraw
	DrawSpriteXY(0, object.value1, object.ypos)
end event


event ObjectStartup
	LoadSpriteSheet("MCZ/Objects.gif")
	SpriteFrame(-24, -8, 48, 16, 141, 165)
	foreach (TypeName[H Platform], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].xpos
		if object[arrayPos0].propertyValue == 0
			object[arrayPos0].value1 += 0x680000
			object[arrayPos0].xvel = -0x10000
			object[arrayPos0].value0 = 104
		else
			object[arrayPos0].value1 -= 0x680000
			object[arrayPos0].xvel = 0x10000
			object[arrayPos0].value0 = -104
		end if
	next
	SetTableValue(TypeName[H Platform], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(HPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(HPlatform_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
