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

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

// Push Button aliases
private alias object.propertyValue : pushButton.stood

private alias object.value0 : object.movePos

private alias 0 : MOVINGBLOCK_WAITFORBUTTON
private alias 1 : MOVINGBLOCK_MOVING
private alias 2 : MOVINGBLOCK_FINISHED

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


// ========================
// Function Declarations
// ========================

reserve function MovingBlock_DebugDraw
reserve function MovingBlock_DebugSpawn


// ========================
// Tables
// ========================

private function MovingBlock_DebugDraw
	DrawSprite(0)
end function


private function MovingBlock_DebugSpawn
	CreateTempObject(TypeName[Moving Block], 0, object.xpos, object.ypos)
end function


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

event ObjectUpdate
	switch object.state
	case MOVINGBLOCK_WAITFORBUTTON
		if pushButton[-1].stood == true
			object.state = MOVINGBLOCK_MOVING
			object.priority = PRIORITY_ACTIVE
		end if
		break
		
	case MOVINGBLOCK_MOVING
		if object.movePos < 0x38A0000
			object.movePos += 0x10000
			object.xpos += 0x10000
			object.xvel = 0x10000
		else
			object.xvel = 0
			object.priority = PRIORITY_BOUNDS
			object.state++
		end if
		break

	case MOVINGBLOCK_FINISHED
		break
		
	end switch

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_SOLID, object.entityPos, -32, -26, 32, 26, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		if checkResult == COL_TOP
			player[currentPlayer].xpos += object.xvel
		end if
	next
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("SYZ/Objects.gif")
	SpriteFrame(-32, -26, 64, 52, 119, 99)

	SetTableValue(TypeName[Moving Block], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(MovingBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(MovingBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKDraw
	DrawSprite(0)
	
	if editor.showGizmos == true
		editor.drawingOverlay = true
		
		// Draw an arrow from this object's activator button
		DrawArrow(object[-1].xpos, object[-1].ypos, object.xpos, object.ypos, 255, 255, 255)
		
		editor.drawingOverlay = false
	end if
end event


event RSDKLoad
	LoadSpriteSheet("SYZ/Objects.gif")
	SpriteFrame(-32, -26, 64, 52, 119, 99)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
