// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: Bridge End Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

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

reserve function BridgeEnd_DebugDraw
reserve function BridgeEnd_DebugSpawn


// ========================
// Function Definitions
// ========================

private function BridgeEnd_DebugDraw
	// this object has the same sprite regardless of its direction...
	// (leftover from EHZ's Bridge End, which itself is based off of GHZ's Bridge End)
	temp0 = object.direction
	temp0 &= FLIP_X
	DrawSprite(temp0)
end function


private function BridgeEnd_DebugSpawn
	CreateTempObject(TypeName[Bridge End], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 4

	// this object's propertyValue doesn't mean anything anyways...
	// (leftover from EHZ's Bridge End, which itself is based off of GHZ's Bridge End)
	object[tempObjectPos].propertyValue = object.direction
	object[tempObjectPos].propertyValue &= FLIP_X
end function


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

event ObjectUpdate
	object.frame = object.animationTimer
	object.frame /= 9
	object.animationTimer++
	object.animationTimer %= 54
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	LoadSpriteSheet("HPZ/Objects.gif")
	SpriteFrame(-4, -12, 8, 24, 214, 206)
	SpriteFrame(-4, -12, 8, 24, 214, 206)
	SpriteFrame(-4, -12, 8, 24, 205, 206)
	SpriteFrame(-4, -12, 8, 24, 196, 206)
	SpriteFrame(-4, -12, 8, 24, 196, 206)
	SpriteFrame(-4, -12, 8, 24, 205, 206)

	arrayPos0 = 32
	while arrayPos0 < 0x420
		if object[arrayPos0].type == TypeName[Bridge End]
			object[arrayPos0].drawOrder = 4
		end if
		arrayPos0++
	loop

	SetTableValue(TypeName[Bridge End], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(BridgeEnd_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(BridgeEnd_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("HPZ/Objects.gif")
	SpriteFrame(-4, -12, 8, 24, 205, 206)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
