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

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

private alias object.value0 : object.timer

// States
private alias 0 : WRECKINGBALL_INACTIVE
private alias 1 : WRECKINGBALL_ACTIVE
private alias 2 : WRECKINGBALL_EXPLODE


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

event ObjectUpdate
	if object.state == WRECKINGBALL_EXPLODE
		object.rotation *= 248
		object.rotation >>= 8
		object.timer++
		temp0 = object.timer
		temp0 &= 7
		if temp0 == 4
			Rand(temp0, 32)
			temp0 -= 16
			temp0 <<= 16
			temp0 += object.xpos
			Rand(temp1, 32)
			temp1 -= 16
			temp1 <<= 16
			temp1 += object.ypos
			CreateTempObject(TypeName[Explosion], 0, temp0, temp1)
		end if

		if object.timer == 180
			object.type = TypeName[Blank Object]
		end if
	end if

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if object.state == WRECKINGBALL_ACTIVE
			BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			if checkResult == true
				CallFunction(Player_Hit)
			end if
		end if
	next
end event


event ObjectDraw
	// Draw Wrecking ball
	temp0 = object.rotation
	temp0 += 8
	temp0 >>= 4
	temp0 &= 7
	temp0++
	DrawSprite(temp0)

	// Draw Shine Overlay
	object.inkEffect = INK_ADD
	object.alpha = 160
	DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
end event


event ObjectStartup
	LoadSpriteSheet("GHZ/Objects2.gif")
	
	SpriteFrame(-24, -24, 48, 48, 1, 77)    // Shine Overlay - #0
	SpriteFrame(-24, -24, 48, 48, 50, 77) 	// Wrecking Ball - #1
	SpriteFrame(-24, -24, 48, 48, 148, 126) // Wrecking Ball - #2
	SpriteFrame(-24, -24, 48, 48, 99, 126) 	// Wrecking Ball - #3
	SpriteFrame(-24, -24, 48, 48, 50, 126) 	// Wrecking Ball - #4
	SpriteFrame(-24, -24, 48, 48, 1, 126) 	// Wrecking Ball - #5
	SpriteFrame(-24, -24, 48, 48, 197, 77) 	// Wrecking Ball - #6
	SpriteFrame(-24, -24, 48, 48, 148, 77) 	// Wrecking Ball - #7
	SpriteFrame(-24, -24, 48, 48, 99, 77) 	// Wrecking Ball - #8
end event


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

event RSDKDraw
	DrawSprite(1)
	
	// Draw Shine Overlay
	object.inkEffect = INK_ADD
	object.alpha = 160
	DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
end event


event RSDKLoad
	LoadSpriteSheet("GHZ/Objects2.gif")
	SpriteFrame(-24, -24, 48, 48, 1, 77)    // Shine Overlay
	SpriteFrame(-24, -24, 48, 48, 50, 77) 	// Wrecking Ball
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
