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

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

private alias object.value0 : object.timer


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

reserve function WarpBlock_DebugDraw
reserve function WarpBlock_DebugSpawn


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

private function WarpBlock_DebugDraw
	DrawSprite(0)
end function


private function WarpBlock_DebugSpawn
	temp5 = TypeName[Warp Block]
	temp4 = 0
	CallFunction(DebugMode_PlaceBlock)
	object[arrayPos0].drawOrder = 4
	object[arrayPos0].groupID = GROUP_BLOCKS
end function


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

event ObjectUpdate
	if object.state == 1
		object.frame = object.timer
		object.frame >>= 3
		object.timer++
		if object.timer == 32
			object.timer = 0
			object.state = 0
			object.frame = 0
		end if
	end if
	
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CallFunction(SpecialSetup_PlayerBlockCol)
	next
end event


event ObjectDraw
	CallFunction(SpecialSetup_GetBlockPos)
	DrawSpriteXY(object.frame, temp0, temp1)
end event


event ObjectStartup
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 301, 176)

	foreach (TypeName[Warp Block], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].groupID = GROUP_BLOCKS
	next

	SetTableValue(TypeName[Warp Block], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(WarpBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(WarpBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 301, 176)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
