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

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

private alias object.value0 : object.timer

// States
private alias 0 : LAVABUBBLE_BUBBLING
private alias 1 : LAVABUBBLE_POPPED


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

reserve function LavaBubble_DebugDraw
reserve function LavaBubble_DebugSpawn


// ========================
// Function Definitions
// ========================

private function LavaBubble_DebugDraw
	DrawSprite(0)
end function


private function LavaBubble_DebugSpawn
	CreateTempObject(TypeName[Lava Bubble], object.direction, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 4
end function


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

event ObjectUpdate
	if object.state == LAVABUBBLE_BUBBLING
		object.animationTimer++
		if object.animationTimer == 12
			object.animationTimer = 0
			object.frame++
			if object.frame >= 6
				object.timer = 128
				object.state = LAVABUBBLE_POPPED
			end if
		end if
	else
		object.timer--
		if object.timer == 0
			object.frame = 0
			object.state = LAVABUBBLE_BUBBLING
		end if
	end if
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	LoadSpriteSheet("MPZ/Objects.gif")
	SpriteFrame(-7, 2, 14, 8, 1, 1)
	SpriteFrame(-7, 0, 14, 8, 1, 1)
	SpriteFrame(-7, -2, 14, 8, 1, 1)
	SpriteFrame(-7, -4, 14, 8, 1, 1)
	SpriteFrame(-11, -4, 22, 8, 1, 10)
	SpriteFrame(-14, -4, 27, 8, 1, 19)
	SpriteFrame(0, 0, 1, 1, 1, 1)

	foreach (TypeName[Lava Bubble], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 4
	next

	SetTableValue(TypeName[Lava Bubble], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(LavaBubble_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(LavaBubble_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("MPZ/Objects.gif")
	SpriteFrame(-7, 2, 14, 8, 1, 1)
	
	// set to 34 in the scene, doesn't mean anything though
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
