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

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

private alias object.value0 : object.active

// Player Aliases
private alias object.state		 : player.state
private alias object.xvel		 : player.xvel
private alias object.yvel		 : player.yvel
private alias object.speed		 : player.speed
private alias object.interaction : player.interaction


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

reserve function GoalBlock_DebugDraw
reserve function GoalBlock_DebugSpawn


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

private function GoalBlock_DebugDraw
	DrawSprite(0)
end function


private function GoalBlock_DebugSpawn
	temp5 = TypeName[Goal Block]
	temp4 = 0
	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 > 0
			player[currentPlayer].state 		= Player_State_Static
			player[currentPlayer].xvel 			= 0
			player[currentPlayer].yvel 			= 0
			player[currentPlayer].speed 		= 0
			object.active 						= false
			player[currentPlayer].interaction 	= false
			ResetObjectEntity(20, TypeName[Special Finish], 0, 0, 0)
			object[20].priority = PRIORITY_ACTIVE
			PlaySfx(SfxName[Exit SS], false)
			stage.timeEnabled 		= false
			options.touchControls 	= false
		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
		DrawSpriteFX(temp2, FX_FLIP, temp0, temp1)
	else
		DrawSpriteXY(temp2, temp0, temp1)
	end if
#endplatform
#platform: USE_STANDALONE
	DrawSpriteXY(temp2, temp0, temp1)
#endplatform
end event


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

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

	SetTableValue(TypeName[Goal Block], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(GoalBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(GoalBlock_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, 201, 76)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
