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

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

private alias object.value0 : object.timer
private alias object.value1 : object.drawIndex
private alias object.value2 : object.drawPos.x

// Path ID Aliases
private alias 0 : PATH_A


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

event ObjectUpdate
	if object.timer > 0
		object.timer--
		if object.timer == 15
			PlaySfx(SfxName[Small Fireball], false)
		end if
	end if

	if object.timer < 16
		object.xpos += object.xvel
	end if

	if object.timer < 12
		if object.drawIndex == 2
			if object.direction == FLIP_NONE
				ObjectTileCollision(CSIDE_LWALL, -16, 0, PATH_A)
			else
				ObjectTileCollision(CSIDE_RWALL, 16, 0, PATH_A)
			end if

			if checkResult == true
				object.type = TypeName[Blank Object]
			end if
		else
			if object.direction == FLIP_NONE
				ObjectTileCollision(CSIDE_LWALL, 16, 0, PATH_A)
			else
				ObjectTileCollision(CSIDE_RWALL, -16, 0, PATH_A)
			end if

			if checkResult == true
				object.drawIndex = 2
				object.drawOrder = 1
			end if
		end if
	end if
	
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -8, -4, 8, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		if checkResult == true
			CallFunction(Player_Hit)
		end if
	next

	if object.outOfBounds == true
		object.type = TypeName[Blank Object]
	end if
end event


event ObjectDraw
	if object.drawIndex == 2
		DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
	else
		if object.drawIndex == 0
			AddDrawListEntityRef(2, object.entityPos)
		else
			if object.timer > 0
				DrawSpriteFX(1, FX_FLIP, object.drawPos.x, object.ypos)
			end if

			if object.timer < 16
				DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
			end if
		end if

		object.drawIndex ^= 1
	end if
end event


event ObjectStartup
	LoadSpriteSheet("ARZ/Objects.gif")

	// Arrow frames
	SpriteFrame(-16, -4, 32, 7, 1, 69)
	SpriteFrame(11, -8, 5, 16, 53, 65)
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("ARZ/Objects.gif")
	SpriteFrame(-16, -4, 32, 7, 1, 69)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
