// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Leaf Spawner Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 61 : TYPE_LEAFSPAWNER

// Function declarations
reserve function LeafSpawner_Function140

// Static Values

// Tables

function LeafSpawner_Function140
	CreateTempObject(TypeName[Leaf], 0, object[currentPlayer].xpos, object[currentPlayer].ypos)
	Rand(temp2, 16)
	temp2 -= 8
	temp2 <<= 16
	object[tempObjectPos].xpos += temp2
	Rand(temp2, 16)
	temp2 -= 8
	temp2 <<= 16
	object[tempObjectPos].ypos += temp2
	Rand(object[tempObjectPos].frame, 2)
	object[tempObjectPos].value1 = object[currentPlayer].xpos
	object[tempObjectPos].value2 = object[currentPlayer].ypos
	object[tempObjectPos].value3 = 2
	object[tempObjectPos].value4 = 4
end function


event ObjectMain
	if object.value0 == 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, object.value2, -32, object.value1, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				temp0 = object[currentPlayer].xvel
				Abs(temp0)
				temp1 = object[currentPlayer].yvel
				Abs(temp1)
				temp0 |= temp1
				if temp0 > 0x20000
					object.value0 = 15
					PlaySfx(SfxName[Rustle], 0)
					CallFunction(LeafSpawner_Function140)
					object[tempObjectPos].xvel = -0x8000
					object[tempObjectPos].yvel = -0x8000
					CallFunction(LeafSpawner_Function140)
					object[tempObjectPos].xvel = 0xC000
					object[tempObjectPos].yvel = -0x4000
					CallFunction(LeafSpawner_Function140)
					object[tempObjectPos].xvel = -0xC000
					object[tempObjectPos].yvel = 0x4000
					CallFunction(LeafSpawner_Function140)
					object[tempObjectPos].xvel = 0x8000
					object[tempObjectPos].yvel = 0x8000
				end if
			end if
		next
	else
		object.value0--
	end if
end event


event ObjectStartup
	foreach (TypeName[Leaf Spawner], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = 32
		object[arrayPos0].value1 <<= object[arrayPos0].propertyValue
		object[arrayPos0].value2 = object[arrayPos0].value1
		FlipSign(object[arrayPos0].value2)
	next
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
