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

// ========================
// Aliases
// ========================

private alias object.value1 : object.drawPos.y

// Player Aliases
private alias object.ypos : player.ypos


// ========================
// Function Declarations
// ========================

reserve function VPlatform_DebugDraw
reserve function VPlatform_DebugSpawn


// ========================
// Tables
// ========================

private function VPlatform_DebugDraw
	DrawSprite(0)
end function


private function VPlatform_DebugSpawn
	CreateTempObject(TypeName[V Platform], 0, object.xpos, object.ypos)
end function


// ========================
// Events
// ========================

event ObjectUpdate
	GetTableValue(temp1, 14, StageSetup_oscillationTable)
	temp1 <<= 8
	temp0 = object.ypos
	temp0 -= temp1
	temp2 = object.drawPos.y
	temp2 &= 0xFFFF0000
	temp1 = temp0
	temp1 &= 0xFFFF0000
	temp1 -= temp2
	temp2 = object.ypos

	object.ypos = object.drawPos.y
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -12, 32, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		if checkResult == true
			player[currentPlayer].ypos += temp1
		end if
	next

	object.ypos = temp2
	object.drawPos.y = temp0
end event


event ObjectDraw
	DrawSpriteXY(0, object.xpos, object.drawPos.y)
end event


event ObjectStartup
	LoadSpriteSheet("SBZ/Objects.gif")
	SpriteFrame(-32, -12, 64, 24, 318, 140)

	SetTableValue(TypeName[V Platform], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(VPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(VPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("SBZ/Objects.gif")
	SpriteFrame(-32, -12, 64, 24, 318, 140)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
