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

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

private alias object.value0 : object.timer


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

event ObjectUpdate
	object.xpos += object.xvel
	object.ypos += object.yvel
	object.yvel += 0x3800

	object.frame = object.timer
	object.frame >>= 1
	object.timer++
	object.timer &= 3

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

	temp0 = object.ypos
	temp0 >>= 16
	temp0 -= camera[0].ypos
	Abs(temp0)
	if temp0 > 136
		object.type = TypeName[Blank Object]
	end if

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -6, -6, 6, 6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		if checkResult == true
			CallFunction(Player_ProjectileHit)
		end if
	next
end event


event ObjectDraw
	DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone01")
	if checkResult == true
		LoadSpriteSheet("GHZ/Objects.gif")
		SpriteFrame(-6, -6, 12, 12, 179, 127)
		SpriteFrame(-6, -6, 12, 12, 179, 140)
	end if

	CheckCurrentStageFolder("Zone03")
	if checkResult == true
		LoadSpriteSheet("SYZ/Objects.gif")
		SpriteFrame(-6, -6, 12, 12, 227, 1)
		SpriteFrame(-6, -6, 12, 12, 240, 1)
	end if

	CheckCurrentStageFolder("Zone07")
	if checkResult == true
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-6, -6, 12, 12, 47, 1)
		SpriteFrame(-6, -6, 12, 12, 60, 1)
	end if
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	// Make sure we have a fall-back, in case the current folder isn't actually a valid one
	temp0 = false
	
	CheckCurrentStageFolder("Zone03")
	temp0 |= checkResult
	if checkResult == true
		LoadSpriteSheet("SYZ/Objects.gif")
		SpriteFrame(-6, -6, 12, 12, 227, 1)
	end if
	
	CheckCurrentStageFolder("Zone07")
	temp0 |= checkResult
	if checkResult == true
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-6, -6, 12, 12, 47, 1)
	end if
	
	if temp0 == false
		// We use GHZ's sprites as the fallback, "Zone01" (GHZ's folder) will come here too
		LoadSpriteSheet("GHZ/Objects.gif")
		SpriteFrame(-6, -6, 12, 12, 179, 127)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
