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

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

private alias object.value0 : object.timer

private alias 0 : BBSHOT_CHARGE1 // frame 1
private alias 1 : BBSHOT_CHARGE2 // frame 2
private alias 2 : BBSHOT_SHOT	 // actually shot the projectile


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

event ObjectUpdate
	switch object.state
	case BBSHOT_CHARGE1
		if object.timer < 8
			object.timer++
		else
			object.timer = 0
			object.state++
			object.frame = 1
		end if
		break

	case BBSHOT_CHARGE2
		if object.timer < 8
			object.timer++
		else
			object.timer = 0
			object.state++
			object.frame = 2
		end if
		break

	case BBSHOT_SHOT
		object.xpos += object.xvel
		object.ypos += object.yvel
		
		if object.timer >= 2
			object.frame = 3
		else
			object.frame = 2
		end if

		object.timer++
		object.timer &= 3
		break
		
	end switch

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

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if object.state > BBSHOT_CHARGE1
			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
		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(-8, -8, 16, 16, 160, 94)
		SpriteFrame(-7, -7, 14, 14, 177, 94)
		SpriteFrame(-6, -6, 12, 12, 160, 111)
		SpriteFrame(-6, -6, 12, 12, 173, 111)
	end if

	CheckCurrentStageFolder("Zone02")
	if checkResult == true
		LoadSpriteSheet("MZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 1, 177)
		SpriteFrame(-7, -7, 14, 14, 19, 178)
		SpriteFrame(-6, -6, 12, 12, 37, 179)
		SpriteFrame(-6, -6, 12, 12, 54, 179)
	end if

	CheckCurrentStageFolder("Zone03")
	if checkResult == true
		LoadSpriteSheet("SYZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 47, 81)
		SpriteFrame(-7, -7, 14, 14, 65, 82)
		SpriteFrame(-6, -6, 12, 12, 83, 83)
		SpriteFrame(-6, -6, 12, 12, 100, 83)
	end if

	CheckCurrentStageFolder("Zone07")
	if checkResult == true
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 1, 51)
		SpriteFrame(-8, -8, 14, 14, 18, 51)
		SpriteFrame(-8, -8, 16, 16, 35, 51)
		SpriteFrame(-8, -8, 16, 16, 52, 51)
	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("Zone02")
	temp0 |= checkResult
	if checkResult == true
		LoadSpriteSheet("MZ/Objects.gif")
		SpriteFrame(-6, -6, 12, 12, 37, 179)
	end if

	CheckCurrentStageFolder("Zone03")
	temp0 |= checkResult
	if checkResult == true
		LoadSpriteSheet("SYZ/Objects.gif")
		SpriteFrame(-6, -6, 12, 12, 83, 83)
	end if

	CheckCurrentStageFolder("Zone07")
	temp0 |= checkResult
	if checkResult == true
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 35, 51)
	end if
	
	if temp0 == true
		// 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, 160, 111)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
