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

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

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

	object.animationTimer++
	if object.animationTimer >= 3
		object.animationTimer = 0
		object.frame ^= 1
	end if

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

	temp0 = object.xpos
	temp0 >>= 16
	temp0 -= camera[0].xpos
	Abs(temp0)
	temp0 -= 32

	temp1 = object.ypos
	temp1 >>= 16
	temp1 -= camera[0].ypos
	Abs(temp1)
	temp1 -= 32

	if temp0 >= screen.xcenter
		object.type = TypeName[Blank Object]
	end if

	if temp1 >= screen.ycenter
		object.type = TypeName[Blank Object]
	end if
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone11")
	if checkResult == true
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 442, 79)
		SpriteFrame(-4, -4, 8, 8, 451, 79)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 973, 677)
		SpriteFrame(-4, -4, 8, 8, 982, 677)
	end if
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone11")
	if checkResult == true
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 442, 79)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 973, 677)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
