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

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

private alias object.value0 : object.bgTimer

// Priority
public alias 0 : PRIORITY_BOUNDS
public alias 1 : PRIORITY_ACTIVE
public alias 2 : PRIORITY_ALWAYS
public alias 3 : PRIORITY_XBOUNDS
public alias 4 : PRIORITY_XBOUNDS_DESTROY
public alias 5 : PRIORITY_INACTIVE
public alias 6 : PRIORITY_BOUNDS_SMALL
public alias 7 : PRIORITY_ACTIVE_SMALL

// Ink Effects
public alias 0 : INK_NONE
public alias 1 : INK_BLEND
public alias 2 : INK_ALPHA
public alias 3 : INK_ADD
public alias 4 : INK_SUB

// Flip Directions
public alias 0 : FLIP_NONE
public alias 1 : FLIP_X
public alias 2 : FLIP_Y
public alias 3 : FLIP_XY


// ========================
// Static Values
// ========================

public value BGAnimation_currentPreview = 0


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

event ObjectUpdate
	object.bgTimer++
	object.bgTimer &= 0x1FF
	Sin(temp0, object.bgTimer)
	
	// The background is all chunks and tiles in the level so "animating" it is actually just moving the camera around
	if temp0 > 0
		if temp0 < 32
			// Second frame
			screen.yoffset = 256
		else
			// First frame
			screen.yoffset = 0
		end if
	else
		if temp0 > -32
			// Third frame
			screen.yoffset = 512
		else
			// Fourth frame
			screen.yoffset = 768
		end if
	end if
end event


event ObjectDraw
	if stage.actNum == 1
		// If in the Level Select scene, then draw the zone preview too
		
		temp0 = screen.xcenter
		
		// Frame
		DrawSpriteScreenXY(9, temp0, 198)

		// Zone preview
		DrawSpriteScreenXY(BGAnimation_currentPreview, temp0, 198)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("LevelSelect/Icons.gif")
	
	// Set all BG Animation objects to be active
	foreach (TypeName[BG Animation], arrayPos0, ALL_ENTITIES)
		// Set all BG Animation objects to be active
		object[arrayPos0].priority = PRIORITY_ACTIVE
	next
	
	// Preview frames
	SpriteFrame(56, -12, 32, 24, 0, 50)   // Sonic vibin'
	SpriteFrame(56, -12, 32, 24, 1, 85)   // GHZ
	SpriteFrame(56, -12, 32, 24, 34, 85)  // MZ
	SpriteFrame(56, -12, 32, 24, 67, 85)  // SYZ
	SpriteFrame(56, -12, 32, 24, 100, 85) // LZ
	SpriteFrame(56, -12, 32, 24, 133, 85) // SLZ
	SpriteFrame(56, -12, 32, 24, 166, 85) // SBZ
	SpriteFrame(56, -12, 32, 24, 199, 85) // FZ
	SpriteFrame(56, -12, 32, 24, 180, 60) // Special Stage
	
	// Frame
	SpriteFrame(32, -24, 80, 50, 0, 0)
	
	// Set the preview to GHZ by default
	BGAnimation_currentPreview = 1
end event


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

event RSDKDraw
	DrawSprite(1)
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("LevelSelect/Icons.gif")
	SpriteFrame(56, -12, 32, 24, 0, 50)
	SpriteFrame(32, -24, 80, 50, 0, 0)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
