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

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

// States
private alias 0 : TILTPLATFORM_L_IDLE
private alias 1 : TILTPLATFORM_L_LASERACTIVE


// ========================
// Function Declarations
// ========================

reserve function TiltPlatformL_DebugDraw
reserve function TiltPlatformL_DebugSpawn


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

private function TiltPlatformL_DebugDraw
	DrawSprite(0)
end function


private function TiltPlatformL_DebugSpawn
	CreateTempObject(TypeName[Tilt Platform L], 0, object.xpos, object.ypos)
	object[tempObjectPos].direction = object.direction
	object[tempObjectPos].inkEffect = INK_ALPHA
	object[tempObjectPos].alpha 	= 0xC0
end function


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

event ObjectUpdate
	switch object.state
	case TILTPLATFORM_L_IDLE
		temp0 = oscillation
		temp0 &= 0xF0
		if temp0 == object.propertyValue
			object.priority = PRIORITY_ACTIVE
			object.animationTimer 	= 0
			object.frame 			= 0
			PlaySfx(SfxName[Thruster], false)
			object.state 			= TILTPLATFORM_L_LASERACTIVE
		end if
		break

	case 1
		object.animationTimer++

		object.frame = object.animationTimer
		object.frame >>= 1
		object.frame &= 3
		if object.animationTimer >= 32
			object.state = TILTPLATFORM_L_IDLE
		end if
		break
		
	end switch

	if object.state == TILTPLATFORM_L_IDLE
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_SOLID, object.entityPos, -24, -2, 24, 6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		next
	else
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -24, -112, 24, 112, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			if checkResult == true
				CallFunction(Player_Hit)
			end if
		next
	end if

	if object.outOfBounds == true
		object.frame 	= 0
		object.state 	= TILTPLATFORM_L_IDLE
		object.priority = PRIORITY_BOUNDS
	end if
end event


event ObjectDraw
	DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
	if object.state == TILTPLATFORM_L_LASERACTIVE
		DrawSpriteFX(4, FX_INK, object.xpos, object.ypos)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-24, -4, 48, 8, 320, 99)		// Flat (H) 				- #0
	SpriteFrame(-16, -16, 32, 32, 320, 108)		// Diagonal (Down Right) 	- #1
	SpriteFrame(-4, -24, 8, 48, 311, 99)		// Diagonal (Down Left) 	- #2
	SpriteFrame(-16, -16, 32, 32, 353, 108)		// Flat (V)					- #3
	SpriteFrame(-24, -112, 48, 256, 464, 0)		// Laser					- #4

	foreach (TypeName[Tilt Platform L], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].inkEffect = INK_ALPHA
		object[arrayPos0].alpha 	= 0xC0
	next

	SetTableValue(TypeName[Tilt Platform L], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(TiltPlatformL_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(TiltPlatformL_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-24, -4, 48, 8, 320, 99)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "intervalOffset")
end event
