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

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

private alias object.value0 : object.beltDir


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

reserve function Wheel_DebugDraw
reserve function Wheel_DebugSpawn


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

private function Wheel_DebugDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
end function


private function Wheel_DebugSpawn
	CreateTempObject(TypeName[Wheel], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 4
end function


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

event ObjectUpdate
	if object.beltDir != LZSetup_beltDirection
		object.direction ^= 1
		object.beltDir = LZSetup_beltDirection
		temp2 = 1
	else
		object.frame = oscillation
		object.frame >>= 2
		object.frame &= 3
		if object.direction == 1
			object.frame ^= 3
		end if
	end if
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 223, 22)
	SpriteFrame(-16, -16, 32, 32, 223, 55)
	SpriteFrame(-16, -16, 32, 32, 223, 88)
	SpriteFrame(-16, -16, 32, 32, 223, 121)

	foreach (TypeName[Wheel], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 4
	next

	SetTableValue(TypeName[Wheel], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(Wheel_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(Wheel_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 223, 22)
	
	// 127 in the scene, doesn't seem to do anything though
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
