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

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

private alias 0 : LAVABUBBLE_BUBBLING
private alias 1 : LAVABUBBLE_DISSIPATED


// ========================
// 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], 0, object.xpos, object.ypos)
end function


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

event ObjectUpdate
	if object.state == LAVABUBBLE_BUBBLING
		object.animationTimer++
		if object.animationTimer >= 13
			object.animationTimer = 0
			object.frame++
			if object.frame == 3
				object.frame = 0
				object.state = LAVABUBBLE_DISSIPATED
			end if
		end if

		if object.frame == 2
			if object.animationTimer == 8
				PlaySfx(SfxName[Small Fireball], false)
				CreateTempObject(TypeName[Lava Jump], 0, object.xpos, object.ypos)
				object[tempObjectPos].xvel = -0x1C000
				object[tempObjectPos].yvel = -0x60000

				CreateTempObject(TypeName[Lava Jump], 0, object.xpos, object.ypos)
				object[tempObjectPos].xvel = 0x1C000
				object[tempObjectPos].yvel = -0x60000
				object[tempObjectPos].direction = FACING_LEFT
			end if
		end if
	else
		object.animationTimer++
		if object.animationTimer >= 60
			object.animationTimer = 0
			object.state = LAVABUBBLE_BUBBLING
		end if
	end if
end event


event ObjectDraw
	if object.state == LAVABUBBLE_BUBBLING
		DrawSprite(object.frame)
	end if
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone05")
	if checkResult == true
		LoadSpriteSheet("HTZ/Objects.gif")
		SpriteFrame(-8, -2, 16, 11, 124, 110)
		SpriteFrame(-8, -5, 16, 11, 141, 110)
		SpriteFrame(-8, -7, 16, 13, 158, 108)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		
		// These frames don't really match up, they're just the HTZ sheet pos
		SpriteFrame(-8, -2, 16, 11, 125, 110)
		SpriteFrame(-8, -5, 16, 11, 141, 110)
		SpriteFrame(-8, -7, 16, 13, 158, 108)
	end if

	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
	CheckCurrentStageFolder("Zone05")
	if checkResult == true
		LoadSpriteSheet("HTZ/Objects.gif")
		SpriteFrame(-8, -2, 16, 11, 124, 110)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-8, -2, 16, 11, 125, 110)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
