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

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

private alias object.value1 : object.startPos.x

// 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 Balkiry_DebugDraw
reserve function Balkiry_DebugSpawn


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

private function Balkiry_DebugDraw
	DrawSprite(2)
end function


private function Balkiry_DebugSpawn
	CreateTempObject(TypeName[Balkiry], 0, object.xpos, object.ypos)
	object[tempObjectPos].xvel = -0x30000
end function


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

event ObjectUpdate
	if object.priority != PRIORITY_XBOUNDS_DESTROY
		object.priority = PRIORITY_ACTIVE
	end if

	object.xpos += object.xvel
	if object.outOfBounds == true
		temp0 = object.xpos
		object.xpos = object.startPos.x
		if object.outOfBounds == true
			if object.priority != PRIORITY_XBOUNDS_DESTROY
				object.priority = PRIORITY_BOUNDS
			end if
		else
			object.xpos = temp0
		end if
	end if

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

	object.frame = object.animationTimer
	object.frame >>= 1
	object.animationTimer++
	object.animationTimer &= 3
end event


event ObjectDraw
	DrawSprite(3)
	DrawSprite(object.frame)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone10")
	if checkResult == true
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(27, -5, 16, 8, 186, 90)
		SpriteFrame(27, -5, 7, 8, 186, 99)
		SpriteFrame(-36, -20, 64, 32, 1, 1)
		SpriteFrame(-36, -20, 69, 34, 1, 34)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(27, -5, 16, 8, 186, 90)
		SpriteFrame(27, -5, 7, 8, 186, 99)
		SpriteFrame(-36, -20, 64, 32, 1, 1)
		SpriteFrame(-36, -20, 69, 34, 1, 34)
	end if

	foreach (TypeName[Balkiry], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].startPos.x = object[arrayPos0].xpos
		if object[arrayPos0].propertyValue == 0
			object[arrayPos0].xvel = -0x30000
		else
			object[arrayPos0].xvel = -0x50000
		end if
	next

	SetTableValue(TypeName[Balkiry], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(Balkiry_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(Balkiry_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 // speed
			checkResult = object.propertyValue
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			break
			
		case 0 // speed
			object.propertyValue = editor.variableValue
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSprite(2)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone10")
	if checkResult == true
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(27, -5, 16, 8, 186, 90)
		SpriteFrame(27, -5, 7, 8, 186, 99)
		SpriteFrame(-36, -20, 64, 32, 1, 1)
		SpriteFrame(-36, -20, 69, 34, 1, 34)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(27, -5, 16, 8, 186, 90)
		SpriteFrame(27, -5, 7, 8, 186, 99)
		SpriteFrame(-36, -20, 64, 32, 1, 1)
		SpriteFrame(-36, -20, 69, 34, 1, 34)
	end if

	AddEditorVariable("speed")
	SetActiveVariable("speed")
	AddEnumVariable("Slow", 0)
	AddEnumVariable("Fast", 1)
end event
