// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: V Drop Bridge Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 52 : TYPE_VDROPBRIDGE

// Function declarations
reserve function VDropBridge_DebugDraw
reserve function VDropBridge_DebugSpawn

// Static Values

// Tables

function VDropBridge_DebugDraw
	DrawSprite(0)
end function


function VDropBridge_DebugSpawn
	CreateTempObject(TypeName[V Drop Bridge], 0, object.xpos, object.ypos)
	object[tempObjectPos].direction = object.direction
	object[tempObjectPos].angle = 256
end function


event ObjectMain
	switch object.state
	case 0
		if object[-1].propertyValue == 1
			if object.direction == FLIP_NONE
				object.state = 2
			else
				object.state = 1
			end if
			if object.priority != PRIORITY_XBOUNDS_DESTROY
				object.priority = PRIORITY_ACTIVE
			end if
			PlaySfx(SfxName[Drop Bridge], 0)
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -8, -136, 8, -8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 1
		if object.angle < 384
			object.angle += 2
		else
			object.state = 3
			PlaySfx(SfxName[Drop Bridge 2], 0)
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -8, -136, 8, -8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 2
		if object.angle > 128
			object.angle -= 2
		else
			object.state = 4
			PlaySfx(SfxName[Drop Bridge 2], 0)
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -8, -136, 8, -8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 3
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -136, -8, -8, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 4
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, 8, -8, 136, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	end switch
	if object.outOfBounds == 1
		if object.priority != PRIORITY_XBOUNDS_DESTROY
			object.angle = 256
			object.state = 0
		end if
	end if
end event


event ObjectDraw
	temp0 = 0
	temp1 = 0x800
	while temp0 < 8
		Sin(temp2, object.angle)
		temp2 *= temp1
		temp2 += object.xpos
		Cos(temp3, object.angle)
		temp3 *= temp1
		temp3 += object.ypos
		DrawSpriteXY(0, temp2, temp3)
		temp0++
		temp1 += 0x800
	loop
end event


event ObjectStartup
	LoadSpriteSheet("MCZ/Objects.gif")
	SpriteFrame(-8, -8, 16, 16, 135, 131)
	foreach (TypeName[V Drop Bridge], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].angle = 256
		object[arrayPos0].direction = object[arrayPos0].propertyValue
		object[arrayPos0].direction &= FLIP_X
	next
	SetTableValue(TypeName[V Drop Bridge], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(VDropBridge_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(VDropBridge_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
