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

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

// Player Aliases
private alias object.ypos : player.ypos
private alias object.yvel : player.yvel


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

event ObjectUpdate
	// Screen Wrap (Bottom)
	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
					
					// Move the background too so that it doesn't visibly warp
					tileLayer[2].scrollPos += 0x1000000
				end if
			next

			camera[0].ypos -= 0x800
			screen.yoffset -= 0x800
		end if
	end if

	// Screen Wrap (Top)
	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
					
					// To make sure it doesn't visibly warp, move the BG around too
					tileLayer[2].scrollPos -= 0x1000000
				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(-16, -16, 32, 32, 1, 143)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
