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

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

private alias object.value0 : object.timer

// States
private alias 0 : BURNINGLOG_BURN
private alias 1 : BURNINGLOG_FALL

// Player Aliases
private alias object.value40 : player.hitboxLeft
private alias object.value38 : player.hitboxTop
private alias object.value41 : player.hitboxRight
private alias object.value39 : player.hitboxBottom


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

event ObjectUpdate
	switch object.state
	case BURNINGLOG_BURN
		object.timer--
		if object.timer <= 0
			object.state = BURNINGLOG_FALL
		end if
		break

	case BURNINGLOG_FALL
		object.ypos += object.yvel
		object.yvel += 0x3800

		if object.outOfBounds == true
			object.type = TypeName[Blank Object]
		end if
		break
		
	end switch

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_PLATFORM, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
		if object.timer <= 15
			BoxCollisionTest(C_TOUCH, object.entityPos, -8, -16, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
			if checkResult == true
				CallFunction(Player_FireHit)
			end if
		end if
	next
	
	object.frame = object.animationTimer
	object.frame /= 3
	object.frame += 3
	object.animationTimer++
	if object.animationTimer >= 6
		object.animationTimer = 0
	end if
end event


event ObjectDraw
	DrawSprite(0)
	
	if object.timer <= 15
		GetBit(object.direction, oscillation, 2)
		DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)
	end if
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone01")
	if checkResult == true
		LoadSpriteSheet("EHZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 82, 78)
		SpriteFrame(-8, -16, 16, 24, 110, 19)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 137, 313)
		SpriteFrame(-8, -16, 16, 24, 110, 19)
	end if
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone01")
	if checkResult == true
		LoadSpriteSheet("EHZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 82, 78)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-8, -8, 16, 16, 137, 313)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
