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

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

private alias object.value1 : object.hitbox.left
private alias object.value2 : object.hitbox.right

// Player Aliases
private alias object.xpos : player.xpos
private alias object.gravity : player.gravity


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

event ObjectUpdate
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if player[currentPlayer].gravity == GRAVITY_GROUND
			BoxCollisionTest(C_TOUCH, object.entityPos, object.hitbox.left, -20, object.hitbox.right, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			if checkResult == true
				player[currentPlayer].xpos += object.xvel
			end if
		end if
	next
end event


event ObjectStartup
	foreach (TypeName[Conveyor Belt], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].hitbox.left = object[arrayPos0].propertyValue
		object[arrayPos0].hitbox.left <<= 4
		object[arrayPos0].hitbox.right = object[arrayPos0].hitbox.left
		FlipSign(object[arrayPos0].hitbox.left)
		
		// Direction is set from the editor
		if object[arrayPos0].direction == FLIP_NONE
			object[arrayPos0].xvel = 0x20000
		else
			object[arrayPos0].xvel = -0x20000
		end if
	next
end event


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

event RSDKDraw
	DrawSprite(0)
	
	if editor.showGizmos == true
		editor.drawingOverlay = true
		
		// Draw the Conveyor Belt's hitbox
		
		// Right hitbox
		temp2 = object.propertyValue
		temp2 <<= 4
		
		// Left hitbox (just mirrored)
		temp0 = temp2
		FlipSign(temp0)
		
		temp1 = -20; temp3 = 0;
		CallFunction(EditorHelpers_DrawHitbox)
		
		editor.drawingOverlay = false
	end if
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-8, -8, 16, 16, 168, 18) // "trigger" - #0
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "size")
end event
