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

//-------Aliases-------//
private alias 74 : TYPE_TILTPLATFORMM

// Function declarations
reserve function TiltPlatformM_DebugDraw
reserve function TiltPlatformM_DebugSpawn

// Static Values

// Tables

function TiltPlatformM_DebugDraw
	DrawSprite(0)
end function


function TiltPlatformM_DebugSpawn
	CreateTempObject(TypeName[Tilt Platform M], 0, object.xpos, object.ypos)
	object[tempObjectPos].direction = object.direction
end function


event ObjectMain
	switch object.state
	case 0
		break
	case 1
		object.value0--
		if object.value0 == 0
			object.animationTimer = 0
			object.frame = 1
			object.state = 2
		end if
		break
	case 2
		object.animationTimer++
		if object.animationTimer == 4
			object.frame = 2
			object.value0 = 74
			object.state = 3
		end if
		break
	case 3
		object.value0--
		if object.value0 == 0
			object.animationTimer = 0
			object.frame = 1
			object.state = 4
		end if
		break
	case 4
		object.animationTimer++
		if object.animationTimer == 4
			object.frame = 0
			object.state = 0
		end if
		break
	end switch
	if object.frame == 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)
			if object.state == 0
				if checkResult == 1
					if object[currentPlayer].xpos < object.xpos
						object.direction = FLIP_X
					else
						object.direction = FLIP_NONE
					end if
					object.value0 = 16
					object.state = 1
					object.priority = PRIORITY_ACTIVE
				end if
			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)
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)
	SetTableValue(TypeName[Tilt Platform M], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(TiltPlatformM_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(TiltPlatformM_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
