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

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

// A pair of unused values, reset once then never seen again...
// -> Bit of a shot in the dark, but these may have been early versions of the
//    GHZSetup static values before the waterfall sound system got reworked
//    -  This coincides with how the rest of GHZ is formatted like RSDKv3 scripts as well,
//       given that static variables didn't exist back then
private alias object.value0 : object.unused1
private alias object.value1 : object.unused2

// Player Aliases
private alias object.xpos : player.xpos


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

event ObjectUpdate
	object.priority = PRIORITY_ACTIVE
	
	GHZSetup_playWaterfallSfx = true
	
	// Check if the object is out of bounds
	temp0 = camera[0].xpos
	temp0 -= object.ixpos
	Abs(temp0)
	temp0 -= 128
	if temp0 > screen.xcenter
		object.priority = PRIORITY_XBOUNDS
		// these aren't used anywhere else...
		object.unused1 = 0
		object.unused2 = 0
	end if
	
	// Make the SFX pan relative to player 1's position
	GHZSetup_waterfallPan = object.xpos
	GHZSetup_waterfallPan -= player[0].xpos
	GHZSetup_waterfallPan >>= 18
end event


event ObjectStartup
	foreach (TypeName[Waterfall Sound], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].priority = PRIORITY_XBOUNDS
	next
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-8, -8, 16, 16, 165, 141) // small "W"
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
