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

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

private alias object.value0 : object.timer

private alias 0 : BLOCK_ROTATE_IDLE
private alias 1 : BLOCK_ROTATE_ACTIVATED

private alias object.value14 : player.rotateBlockTimer


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

reserve function RotateBlock_DebugDraw
reserve function RotateBlock_DebugSpawn


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

private function RotateBlock_DebugDraw
	DrawSprite(0)
end function


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


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

event ObjectUpdate
	if object.state == BLOCK_ROTATE_ACTIVATED
		object.frame = object.timer
		object.frame >>= 3
		object.timer++
		if object.timer == 32
			object.timer = 0
			object.state = BLOCK_ROTATE_IDLE
			object.frame = 0
		end if
	end if

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CallFunction(SpecialSetup_PlayerBlockCol)
		if checkResult != false
			if player[currentPlayer].rotateBlockTimer == 0
				player[currentPlayer].rotateBlockTimer = 30
				object.state = BLOCK_ROTATE_ACTIVATED
				Player_rotateDir ^= 1
				PlaySfx(SfxName[Rotate Block], false)
			end if
		end if
	next
end event


event ObjectDraw
	CallFunction(SpecialSetup_GetBlockPos)
#platform: USE_ORIGINS
	if game.playMode == BOOT_PLAYMODE_MIRRORING
		object.direction = FACING_LEFT
		DrawSpriteFX(object.frame, FX_FLIP, temp0, temp1)
	else
		DrawSpriteXY(object.frame, temp0, temp1)
	end if
#endplatform
#platform: USE_STANDALONE
	DrawSpriteXY(object.frame, temp0, temp1)
#endplatform
end event


event ObjectStartup
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 176, 76)
	SpriteFrame(-12, -12, 24, 24, 176, 176)
	SpriteFrame(-12, -12, 24, 24, 176, 76)
	SpriteFrame(-12, -12, 24, 24, 176, 176)
	
	foreach (TypeName[Rotate Block], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].groupID = GROUP_BLOCKS
	next

	SetTableValue(TypeName[Rotate Block], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(RotateBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(RotateBlock_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, 176, 76)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
