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

// The object name is a bit odd so I'll just clarify here - 
// This object's purpose is to make the player not sink at the edge of a triangle chunk
// Well I suppose that's an equally as odd description, but since images are worth a thousand words, it's meant to prevent things like this
// https://randomsonicnet.org/taxman_sage2007/collisionbug.png

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

// Player Aliases
private alias object.ypos : player.ypos
private alias object.gravity : player.gravity
private alias object.collisionBottom : player.collisionBottom


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

event ObjectUpdate
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if player[currentPlayer].gravity == GRAVITY_GROUND
			BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			if checkResult == true
				temp0 = player[currentPlayer].collisionBottom
				temp0 *= -0x10000
				temp0 -= 0x80000
				temp0 += object.ypos
				if player[currentPlayer].ypos > temp0
					player[currentPlayer].ypos = temp0
				end if
			end if
		end if
	next
end event


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

event RSDKDraw
	DrawSprite(0)

	if editor.showGizmos == true
		editor.drawingOverlay = true
		
		// Draw the sensor hitbox
		temp0 = 8; temp1 = 8; temp2 = 8; temp3 = 8;
		CallFunction(EditorHelpers_DrawHitbox)
		
		editor.drawingOverlay = false
	end if
end event


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