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

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

private alias object.value1 : object.parent

// Player aliases
private alias object.value40 : player.hitboxLeft
private alias object.value38 : player.hitboxTop
private alias object.value41 : player.hitboxRight
private alias object.value39 : player.hitboxBottom

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

reserve function SmallTurtloid_DebugDraw
reserve function SmallTurtloid_DebugSpawn

private function SmallTurtloid_DebugDraw
	DrawSprite(2)
end function


private function SmallTurtloid_DebugSpawn
	CreateTempObject(TypeName[SmallTurtloid], 0, object.xpos, object.ypos)
end function


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

event ObjectUpdate
	if object.parent > 0
		arrayPos0 = object.parent
		object.xpos = object[arrayPos0].xpos
		object.xpos += 0x40000
		object.ypos = object[arrayPos0].ypos
		object.ypos -= 0x180000
	end if

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -12, -12, 12, 12, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
		if checkResult == true
			CallFunction(Player_BadnikBreak)
		end if
	next
end event


event ObjectDraw
	DrawSprite(object.frame)
	temp0 = object.frame
	temp0 += 2
	DrawSprite(temp0)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone10")
	if checkResult == true
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(-12, -11, 24, 23, 186, 42)
		SpriteFrame(-12, -11, 24, 23, 211, 42)
		SpriteFrame(-12, -11, 24, 23, 186, 66)
		SpriteFrame(-12, -11, 24, 23, 211, 66)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-12, -11, 24, 23, 186, 42)
		SpriteFrame(-12, -11, 24, 23, 211, 42)
		SpriteFrame(-12, -11, 24, 23, 186, 66)
		SpriteFrame(-12, -11, 24, 23, 211, 66)
	end if

	foreach (TypeName[SmallTurtloid], arrayPos0, ALL_ENTITIES)
		arrayPos1 = arrayPos0
		arrayPos1--
		if object[arrayPos1].type == TypeName[Big Turtloid]
			object[arrayPos0].parent = arrayPos1
		else
			object[arrayPos0].parent = 0
		end if
	next

	SetTableValue(TypeName[SmallTurtloid], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(SmallTurtloid_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(SmallTurtloid_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone10")
	if checkResult == true
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(-12, -11, 24, 23, 186, 42)
		SpriteFrame(-12, -11, 24, 23, 211, 42)
		SpriteFrame(-12, -11, 24, 23, 186, 66)
		SpriteFrame(-12, -11, 24, 23, 211, 66)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-12, -11, 24, 23, 186, 42)
		SpriteFrame(-12, -11, 24, 23, 211, 42)
		SpriteFrame(-12, -11, 24, 23, 186, 66)
		SpriteFrame(-12, -11, 24, 23, 211, 66)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
