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

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

reserve function RedWhiteBlock_DebugDraw
reserve function RedWhiteBlock_DebugSpawn


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

private function RedWhiteBlock_DebugDraw
	DrawSprite(0)
end function


private function RedWhiteBlock_DebugSpawn
	temp5 = TypeName[Red White Block]
	CallFunction(DebugMode_PlaceBlock)
	object[arrayPos0].drawOrder = 4
	object[arrayPos0].groupID = GROUP_BLOCKS
end function


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

event ObjectUpdate
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if object.propertyValue == 0
			CallFunction(SpecialSetup_PlayerBlockCol)
		else
			switch object.propertyValue
			case 1
				BoxCollisionTest(C_TOUCH, object.entityPos, -160, 36, 160, 60, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
				if checkResult == true
					object.propertyValue = 0
					object.inkEffect = INK_NONE
				end if
				break

			case 2
				BoxCollisionTest(C_TOUCH, object.entityPos, 36, -160, 60, 160, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
				if checkResult == true
					object.propertyValue = 0
					object.inkEffect = INK_NONE
				end if
				break

			case 3
				BoxCollisionTest(C_TOUCH, object.entityPos, -60, -160, -36, 160, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
				if checkResult == true
					object.propertyValue = 0
					object.inkEffect = INK_NONE
				end if
				break

			case 4
				BoxCollisionTest(C_TOUCH, object.entityPos, -160, -60, 160, -36, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
				if checkResult == true
					object.propertyValue = 0
					object.inkEffect = INK_NONE
				end if
				break

			case 5
				BoxCollisionTest(C_TOUCH, object.entityPos, 36, -24, 60, 24, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
				if checkResult == true
					object.propertyValue = 0
					object.inkEffect = INK_NONE
				end if
				break
				
			end switch
		end if
	next
end event


event ObjectDraw
	CallFunction(SpecialSetup_GetBlockPos)
	temp2 = oscillation
	temp2 &= 15
	temp2 >>= 3
	DrawSpriteFX(temp2, FX_INK, temp0, temp1)
end event


event ObjectStartup
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 276, 76)
	SpriteFrame(-12, -12, 24, 24, 276, 176)
	
	foreach (TypeName[Red White Block], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].groupID = GROUP_BLOCKS
		if object[arrayPos0].propertyValue > 0
			object[arrayPos0].inkEffect = INK_BLEND
			object[arrayPos0].alpha = 128
		end if
	next

	SetTableValue(TypeName[Red White Block], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(RedWhiteBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(RedWhiteBlock_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
	object.inkEffect = INK_NONE
	if object.propertyValue > 0
		object.inkEffect = INK_BLEND
	end if

	DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
end event


event RSDKLoad
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 276, 76)
	
	AddEditorVariable("type")
	SetActiveVariable("type")
	AddEnumVariable("Solid", 0)
	AddEnumVariable("Transparent (Enter From Top)", 1)
	AddEnumVariable("Transparent (Enter From Right)", 2)
	AddEnumVariable("Transparent (Enter From Left)", 3)
	AddEnumVariable("Transparent (Enter From Bottom)", 4)
	AddEnumVariable("Transparent (Enter From Right, Small)", 5)
end event
