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

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

// Player Aliases
private alias object.state : player.state
private alias object.xpos : player.xpos
private alias object.ixpos : player.ixpos
private alias object.xvel : player.xvel
private alias object.speed : player.speed
private alias object.pushing : player.pushing
private alias object.collisionLeft : player.collisionLeft
private alias object.collisionRight : player.collisionRight

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

event ObjectUpdate
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if player[currentPlayer].state != Player_State_LedgePullUp
			BoxCollisionTest(C_TOUCH, object.entityPos, -16, -12, 16, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			if checkResult == true
				if player[currentPlayer].xpos > object.xpos
					player[currentPlayer].ixpos = player[currentPlayer].collisionLeft
					FlipSign(player[currentPlayer].xpos)
					player[currentPlayer].xpos += 0x100000
					player[currentPlayer].xpos += object.xpos
					if player[currentPlayer].xvel < 0
						player[currentPlayer].pushing = 2
						player[currentPlayer].xvel = 0
						player[currentPlayer].speed = 0
					end if
				else
					player[currentPlayer].ixpos = player[currentPlayer].collisionRight
					FlipSign(player[currentPlayer].xpos)
					player[currentPlayer].xpos -= 0x100000
					player[currentPlayer].xpos += object.xpos
					if player[currentPlayer].xvel > 0
						player[currentPlayer].pushing = 2
						player[currentPlayer].xvel = 0
						player[currentPlayer].speed = 0
					end if
				end if
			end if
		end if
	next
end event


event RSDKDraw
	DrawSprite(0)
	
	if editor.showGizmos == true
		// Show the object's hitbox

		editor.drawingOverlay = true
		
		temp0 = object.ixpos; temp0 -= 0x8
		temp1 = object.iypos; temp1 -= 0x8
		DrawRectOutline(temp0, temp1, 16, 16, 255, 255, 255, 255)
		
		editor.drawingOverlay = false
	end if
end event


event RSDKLoad
	LoadSpriteSheet("MZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 159, 322)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
