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

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

private alias object.value0 : object.timer
private alias object.value1 : object.offset.y

private alias 0 : TUBECOVER_IDLE
private alias 1 : TUBECOVER_STARTUP_DELAY
private alias 2 : TUBECOVER_STARTUP
private alias 3 : TUBECOVER_ACTIVE_DELAY
private alias 4 : TUBECOVER_ACTIVE
private alias 5 : TUBECOVER_ACTIVATED_DELAY
private alias 6 : TUBECOVER_ACTIVATED
private alias 7 : TUBECOVER_MOVING_DELAY
private alias 8 : TUBECOVER_MOVING
private alias 9 : TUBECOVER_FINISHED

event ObjectUpdate
	switch object.state
	case TUBECOVER_IDLE
		break

	case TUBECOVER_STARTUP
		temp1 = object.ypos
		temp1 -= 0x200000
		CreateTempObject(TypeName[Smoke Puff], 0, object.xpos, temp1)
		object[tempObjectPos].drawOrder = 5
		object.state++
		break

	case TUBECOVER_STARTUP_DELAY
	case TUBECOVER_ACTIVE_DELAY
	case TUBECOVER_ACTIVATED_DELAY
	case TUBECOVER_MOVING_DELAY
		object.timer++
		if object.timer == 16
			object.timer = 0
			object.state++
		end if
		break

	case TUBECOVER_ACTIVE
		temp0 = object.xpos
		temp0 -= 0x100000
		temp1 = object.ypos
		temp1 -= 0x200000
		CreateTempObject(TypeName[Smoke Puff], 0, temp0, temp1)
		object[tempObjectPos].drawOrder = 5
		temp0 += 0x200000

		CreateTempObject(TypeName[Smoke Puff], 0, temp0, temp1)
		object[tempObjectPos].drawOrder = 5
		object.state++
		break

	case TUBECOVER_ACTIVATED
		temp0 = object.xpos
		temp0 -= 0x200000
		temp1 = object.ypos
		temp1 -= 0x200000

		CreateTempObject(TypeName[Smoke Puff], 0, temp0, temp1)
		object[tempObjectPos].drawOrder = 5
		temp0 += 0x400000

		CreateTempObject(TypeName[Smoke Puff], 0, temp0, temp1)
		object[tempObjectPos].drawOrder = 5
		object.state++
		break

	case TUBECOVER_MOVING
		object.ypos += object.yvel
		object.offset.y += object.yvel
		object.yvel += 0x2800

		object.timer++
		if object.timer == 60
			object.state++
		end if
		break

	case TUBECOVER_FINISHED
		break
		
	end switch

	if object.state == TUBECOVER_STARTUP_DELAY
		// ???
		// This prolly did something at one point, or on one platform, and that prolly made this object more than a fancy decoration
	end if

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_SOLID, object.entityPos, -32, -32, 32, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
	next
end event


event ObjectDraw
	temp0 = object.ypos
	temp0 -= object.offset.y
	DrawSpriteXY(1, object.xpos, temp0)
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("SBZ/Objects.gif")
	SpriteFrame(-32, -32, 64, 64, 317, 339)
	SpriteFrame(-32, -8, 32, 40, 2, 472)

	foreach (TypeName[Tube Cover], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 4
	next
end event


event RSDKDraw
	DrawSprite(1)
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("SBZ/Objects.gif")
	SpriteFrame(-32, -32, 64, 64, 317, 339)
	SpriteFrame(-32, -8, 32, 40, 2, 472)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
