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

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

// HullSeal States
private alias 1 : HULL_OPEN

// Player Aliases
private alias object.yvel : player.yvel
private alias object.gravity : player.gravity
private alias object.animation : player.animation

private alias object.value25 : player.gravityStrength


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

event ObjectUpdate
	temp1 = false

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		temp0 = player[currentPlayer].yvel
		
		BoxCollisionTest(C_SOLID, object.entityPos, -16, -8, 16, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		switch checkResult
		case COL_TOP
			if player[currentPlayer].animation == ANI_JUMPING
				player[currentPlayer].yvel = temp0
				if player[currentPlayer].yvel > 0
					player[currentPlayer].yvel += player[currentPlayer].gravityStrength
					player[currentPlayer].yvel += player[currentPlayer].gravityStrength
					FlipSign(player[currentPlayer].yvel)
					player[currentPlayer].gravity = GRAVITY_AIR
				end if
				
				temp1 = true
			end if
			break

		case COL_LEFT
		case COL_RIGHT
			if player[currentPlayer].gravity == 0
				if player[currentPlayer].animation == ANI_JUMPING
					temp1 = true
				end if
			end if
			break
			
		end switch
	next

	if temp1 == true
		PlaySfx(SfxName[Destroy], false)
		temp0 = object.xpos
		temp0 >>= 16
		temp0 -= 160
		stage.newXBoundary1 = temp0
		ResetObjectEntity(object.entityPos, TypeName[Smoke Puff], 0, object.xpos, object.ypos)

		object[+1].state 		= HULL_OPEN
		object[+1].inkEffect 	= 2
		object[+1].alpha 		= 0x100
	end if
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-16, -8, 32, 16, 409, 1)
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-16, -8, 32, 16, 409, 1)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
