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

//-------Aliases-------//
private alias 75 : TYPE_TILTPLATFORML

// Function declarations
reserve function TiltPlatformL_DebugDraw
reserve function TiltPlatformL_DebugSpawn

// Static Values

// Tables

function TiltPlatformL_DebugDraw
	DrawSprite(0)
end function


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 = 192
end function


event ObjectMain
	switch object.state
	case 0
		temp0 = oscillation
		temp0 &= 240
		if temp0 == object.propertyValue
			object.priority = PRIORITY_ACTIVE
			object.animationTimer = 0
			object.frame = 0
			PlaySfx(SfxName[Thruster], 0)
			object.state = 1
		end if
		break
	case 1
		object.animationTimer++
		object.frame = object.animationTimer
		object.frame >>= 1
		object.frame &= 3
		if object.animationTimer >= 32
			object.state = 0
		end if
		break
	end switch
	if object.state == 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -24, -2, 24, 6, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
	else
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -24, -112, 24, 112, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				CallFunction(PlayerObject_Hit)
			end if
		next
	end if
	if object.outOfBounds == 1
		object.frame = 0
		object.state = 0
		object.priority = PRIORITY_ACTIVE_BOUNDS
	end if
end event


event ObjectDraw
	DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
	if object.state == 1
		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)
	SpriteFrame(-16, -16, 32, 32, 320, 108)
	SpriteFrame(-4, -24, 8, 48, 311, 99)
	SpriteFrame(-16, -16, 32, 32, 353, 108)
	SpriteFrame(-24, -112, 48, 256, 464, 0)
	foreach (TypeName[Tilt Platform L], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].inkEffect = INK_ALPHA
		object[arrayPos0].alpha = 192
	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

event RSDKDraw
	DrawSprite(0)
end event

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