// ----------------------------------
// RSDK Project: Sonic 1
// Script Description: Vertical Wrap Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

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

private alias object.yvel : player.yvel
private alias object.ypos : player.ypos


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

event ObjectUpdate
	// First, check for bottom->top wrap
	if player[0].yvel >= 0
		if camera[0].ypos >= 2168
			temp1 = player[0].ypos
			foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
				temp0 = player[currentPlayer].ypos
				temp0 -= temp1
				Abs(temp0)
				if temp0 < 0x8C0000
					player[currentPlayer].ypos -= 0x8000000
				end if
			next
			camera[0].ypos -= 0x800
			screen.yoffset -= 0x800
		end if
	end if
	
	// Then, check for top->bottom wrap
	if player[0].yvel <= 0
		if camera[0].ypos <= 120
			temp1 = player[0].ypos
			foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
				temp0 = player[currentPlayer].ypos
				temp0 -= temp1
				Abs(temp0)
				if temp0 < 0x8C0000
					player[currentPlayer].ypos += 0x8000000
				end if
			next
			camera[0].ypos += 0x800
			screen.yoffset += 0x800
		end if
	end if
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-8, -8, 16, 16, 239, 239) // "Trigger" - #0
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
