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

//-------Aliases-------//
private alias 50 : TYPE_PULLSWITCH

// Function declarations
reserve function PullSwitch_DebugDraw
reserve function PullSwitch_DebugSpawn

// Static Values

// Tables

function PullSwitch_DebugDraw
	DrawSprite(0)
end function


function PullSwitch_DebugSpawn
	CreateTempObject(TypeName[Pull Switch], 0, object.xpos, object.ypos)
end function


event ObjectMain
	object.propertyValue = 0
	temp0 = object.ypos
	temp0 += 0x300000
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if object[currentPlayer].state != PlayerObject_Blank
			if object[currentPlayer].down == 0
				if object[currentPlayer].ypos < temp0
					BoxCollisionTest(C_TOUCH, object.entityPos, -8, 64, 8, 68, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				else
					BoxCollisionTest(C_TOUCH, object.entityPos, -8, 46, 8, 48, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				end if
				if checkResult == 1
					if object[currentPlayer].gravity == GRAVITY_AIR
						object[currentPlayer].state = PlayerObject_Blank
						object[currentPlayer].animation = ANI_HANGING
						object[currentPlayer].speed = 0
						object[currentPlayer].xvel = 0
						object[currentPlayer].yvel = 0
						object[currentPlayer].xpos = object.xpos
						object[currentPlayer].ypos = object[currentPlayer].collisionTop
						FlipSign(object[currentPlayer].ypos)
						object[currentPlayer].ypos += 26
						object[currentPlayer].ypos <<= 16
						object[currentPlayer].ypos += object.ypos
						object.propertyValue |= 1
					end if
				end if
			end if
		else
			BoxCollisionTest(C_TOUCH, object.entityPos, -8, 0, 8, 64, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				if object[currentPlayer].jumpPress == 1
					object[currentPlayer].animation = ANI_JUMPING
					PlaySfx(SfxName[Jump], 0)
					object[currentPlayer].value35 = 1
					object[currentPlayer].state = PlayerObject_HandleAir
					object[currentPlayer].yvel = -0x40000
					object[currentPlayer].gravity = GRAVITY_AIR
				else
					object[currentPlayer].xpos = object.xpos
					object[currentPlayer].ypos = object[currentPlayer].collisionTop
					FlipSign(object[currentPlayer].ypos)
					object[currentPlayer].ypos += 26
					object[currentPlayer].ypos <<= 16
					object[currentPlayer].ypos += object.ypos
					object.propertyValue |= 1
				end if
			end if
		end if
	next
	if object.frame == 0
		if object.propertyValue == 1
			PlaySfx(SfxName[Pull Switch], 0)
		end if
	end if
	object.frame = object.propertyValue
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	LoadSpriteSheet("MCZ/Objects.gif")
	SpriteFrame(-8, -48, 16, 95, 215, 161)
	SpriteFrame(-8, -44, 16, 95, 215, 161)
	foreach (TypeName[Pull Switch], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].priority = PRIORITY_ACTIVE
	next
	
	SetTableValue(TypeName[Pull Switch], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(PullSwitch_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(PullSwitch_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
