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

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

private alias object.state : object.setup

// Player Aliases
private alias object.xpos : player.xpos
private alias object.ypos : player.ypos
private alias object.xvel : player.xvel
private alias object.yvel : player.yvel
private alias object.speed : player.speed


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

event ObjectUpdate
	if object.setup == false
		stage.newXBoundary2 = object.xpos
		stage.newXBoundary2 >>= 16
		stage.newXBoundary2 += 16
		stage.newYBoundary1 = object.ypos
		stage.newYBoundary1 >>= 16
		stage.newYBoundary1 -= 16
		object.setup = true
	end if
	
	if stage.state == STAGE_RUNNING
		if player[0].ypos < object.ypos
			player[0].yvel = 0
			player[0].speed = 0
			player[0].ypos = object.ypos
		end if
		
		if player[0].xpos > object.xpos
			player[0].xvel = 0
			player[0].speed = 0
			player[0].xpos = object.xpos
		end if
	end if
end event


event ObjectDraw
	// sure ig
	// (event exists, but there's no code inside it)
end event


event ObjectStartup
	foreach (TypeName[MissionAreaTR], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].priority = PRIORITY_ACTIVE
	next
end event


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

event RSDKDraw
	DrawSprite(0)
	
	// TODO: same note as the other 3 corner bounds objects
	
	temp0 = object.xpos
	temp0 += 0x100000
	
	temp1 = object.ypos
	temp1 -= 0x100000
	
	temp2 = temp0
	temp2 -= 0x380000
	
	temp3 = temp1
	temp3 += 0x380000
	
	editor.drawingOverlay = true
	
	DrawLine(temp0, temp1, temp0, temp3, 255, 0, 255)
	DrawLine(temp0, temp1, temp2, temp1, 255, 0, 255)
	
	editor.drawingOverlay = false
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
