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

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

// Player Aliases
private alias object.value10 : debugMode.currentSelection
private alias object.value15 : player.upDownBlockTimer


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

reserve function UpDownBlock_DebugDraw
reserve function UpDownBlock_DebugSpawn


// ========================
// Static Values
// ========================

private value UpDownBlock_startDebugID = 0


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

private function UpDownBlock_DebugDraw
	temp4 = debugMode[0].currentSelection
	temp4 -= UpDownBlock_startDebugID
	DrawSprite(temp4)
end function


private function UpDownBlock_DebugSpawn
	temp4 = debugMode[0].currentSelection
	temp4 -= UpDownBlock_startDebugID
	temp5 = TypeName[Up Down Block]
	CallFunction(DebugMode_PlaceBlock)
	object[arrayPos0].drawOrder = 4
	object[arrayPos0].groupID = GROUP_BLOCKS
end function


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

event ObjectUpdate
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CallFunction(SpecialSetup_PlayerBlockCol)
		if checkResult != false
			if player[currentPlayer].upDownBlockTimer == 0
				player[currentPlayer].upDownBlockTimer = 30
				if object.propertyValue == 0
					if Player_rotateSpeed < 1
						Player_rotateSpeed++
						object.propertyValue = 1
						PlaySfx(SfxName[Rotate Block], false)
					end if
				else
					if Player_rotateSpeed > 0
						Player_rotateSpeed--
						object.propertyValue = 0
						PlaySfx(SfxName[Rotate Block], false)
					end if
				end if
			end if
		end if
	next
end event


event ObjectDraw
	CallFunction(SpecialSetup_GetBlockPos)
	temp2 = oscillation
	temp2 &= 15
	temp2 >>= 3
#platform: USE_ORIGINS
	if game.playMode == BOOT_PLAYMODE_MIRRORING
		object.direction = FACING_LEFT
		if temp2 == 0
			DrawSpriteFX(object.propertyValue, FX_FLIP, temp0, temp1)
		else
			DrawSpriteFX(2, FX_FLIP, temp0, temp1)
		end if
	else
		if temp2 == 0
			DrawSpriteXY(object.propertyValue, temp0, temp1)
		else
			DrawSpriteXY(2, temp0, temp1)
		end if
	end if
#endplatform
#platform: USE_STANDALONE
	if temp2 == 0
		DrawSpriteXY(object.propertyValue, temp0, temp1)
	else
		DrawSpriteXY(2, temp0, temp1)
	end if
#endplatform
end event


event ObjectStartup
	LoadSpriteSheet("Special/Objects.gif")

	// Up and down 'n all around frames
	SpriteFrame(-12, -12, 24, 24, 226, 76)
	SpriteFrame(-12, -12, 24, 24, 226, 176)
	SpriteFrame(-12, -12, 24, 24, 251, 76)

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

	// Add this object to the debug item list twice
	UpDownBlock_startDebugID = DebugMode_ObjCount
	SetTableValue(TypeName[Up Down Block], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(UpDownBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(UpDownBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++

	SetTableValue(TypeName[Up Down Block], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(UpDownBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(UpDownBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKEdit
	if editor.returnVariable == true
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			checkResult = object.propertyValue
			break
			
		case 0 // type
			checkResult = object.propertyValue
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			break
			
		case 0 // type
			object.propertyValue = temp0
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSprite(object.propertyValue)
end event


event RSDKLoad
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 226, 76)
	SpriteFrame(-12, -12, 24, 24, 226, 176)
	SpriteFrame(-12, -12, 24, 24, 251, 76)
	
	AddEditorVariable("type")
	SetActiveVariable("type")
	AddEnumVariable("Speed Up", 0)
	AddEnumVariable("Slow Down", 1)
end event
