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

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

private alias object.value0 : object.targetPlayer

private alias 0 : FZINTRO_MANAGER
private alias 1 : FZINTRO_INTRO
private alias 2 : FZINTRO_DESTROY

// Player Aliases
private alias object.state 		: player.state
private alias object.xpos 		: player.xpos
private alias object.ypos 		: player.ypos
private alias object.yvel 		: player.yvel
private alias object.speed 		: player.speed
private alias object.gravity 	: player.gravity
private alias object.direction 	: player.direction
private alias object.animation 	: player.animation
private alias object.value26 	: player.flightVelocity


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

event ObjectUpdate
	switch object.state
	case FZINTRO_MANAGER
		tileLayer[2].scrollPos =  0x800000
		hParallax[0].scrollPos = -0x800000
		if recAnimation != ANI_STOPPED
			temp0 = recAnimation
			currentPlayer = 0

			// Create a FZ Intro object for each player
			while currentPlayer < playerCount
				player[currentPlayer].xpos = object.xpos
				player[currentPlayer].ypos = object.ypos
				CreateTempObject(TypeName[FZ Intro], 0, object.xpos, object.ypos)
				object[tempObjectPos].state = FZINTRO_INTRO
				object[tempObjectPos].targetPlayer = currentPlayer
				object[tempObjectPos].direction = temp0
				object[tempObjectPos].direction &= 0xFF
				temp0 >>= 8
				object[tempObjectPos].animation = temp0
				object[tempObjectPos].animation &= 0xFF
				temp0 >>= 8
				player[currentPlayer].yvel = -0x80000
				player[currentPlayer].gravity = GRAVITY_AIR
				player[currentPlayer].state = Player_State_Air
				currentPlayer++
			loop
			recAnimation = 0
		end if

		object.type = TypeName[Blank Object]
		temp0 = stage.newYBoundary2
		temp0 -= screen.ysize
		stage.newYBoundary1 = temp0
		break

	case FZINTRO_INTRO
		currentPlayer = object.targetPlayer
	
		player[currentPlayer].direction = object.direction
		player[currentPlayer].animation = object.animation

		if player[currentPlayer].animation == ANI_JUMPING
			player[currentPlayer].state = Player_State_Air
			object.state = FZINTRO_DESTROY
		end if
	
		if player[currentPlayer].animation == ANI_FLYING
			player[currentPlayer].state = Player_State_Fly
			player[currentPlayer].flightVelocity = 0x800
			player[currentPlayer].yvel >>= 2
			object.state = FZINTRO_DESTROY
		end if
	
		if player[currentPlayer].animation == ANI_GLIDING
			if player[currentPlayer].direction == 1
				player[currentPlayer].state = Player_State_GlideLeft
			else
				player[currentPlayer].state = Player_State_GlideRight
			end if

			object.state = FZINTRO_DESTROY
		end if
	
		if player[currentPlayer].animation == ANI_GLIDING_DROP
			player[currentPlayer].state = Player_State_GlideDrop
			object.state = FZINTRO_DESTROY
		end if
	
		if object.state != FZINTRO_DESTROY
			player[currentPlayer].state = Player_State_Air
			player[currentPlayer].direction = FACING_RIGHT
			player[currentPlayer].animation = ANI_BOUNCING
			object.state = FZINTRO_DESTROY
		end if
		break

	case FZINTRO_DESTROY
		object.type = TypeName[Blank Object]
		break
		
	end switch
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
