// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Eggman Bomb Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 61 : TYPE_EGGMANBOMB


// Static Values

// Tables

event ObjectMain
	switch object.state
	case 0
		object.frame = 2
		if object.value2 < 0x2E0000
			object.value2 += 0x10000
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -10, -10, 10, 10, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				CallFunction(PlayerObject_Hit)
			end if
		next
		break
	case 1
		object.ypos += object.yvel
		object.yvel += 0x3800
		ObjectTileCollision(CSIDE_FLOOR, 0, 10, 0)
		if checkResult == 1
			object.type = TypeName[Blank Object]
			CreateTempObject(TypeName[Eggman Bomb], 0, object.xpos, object.ypos)
			object[tempObjectPos].state = 2
			object[tempObjectPos].xvel = -0x10000
			object[tempObjectPos].yvel = -0x30000
			CreateTempObject(TypeName[Eggman Bomb], 0, object.xpos, object.ypos)
			object[tempObjectPos].state = 2
			object[tempObjectPos].xvel = 0x10000
			object[tempObjectPos].yvel = -0x30000
			PlaySfx(SfxName[Explosion], 0)
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -4, -4, 4, 4, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				CallFunction(PlayerObject_Hit)
			end if
		next
		break
	case 2
		object.frame = object.animationTimer
		object.frame >>= 1
		object.animationTimer++
		object.animationTimer &= 3
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.yvel += 0x3800
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -4, -4, 4, 4, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				CallFunction(PlayerObject_Hit)
			end if
		next
		if object.outOfBounds == 1
			object.type = TypeName[Blank Object]
		end if
		break
	end switch
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone04")
	if checkResult == 1
		LoadSpriteSheet("CNZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 145, 172)
		SpriteFrame(-4, -4, 8, 8, 154, 172)
		SpriteFrame(-12, -12, 23, 23, 145, 181)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-4, -4, 8, 8, 224, 130)
		SpriteFrame(-4, -4, 8, 8, 224, 139)
		SpriteFrame(-12, -12, 23, 23, 200, 130)
	end if
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
