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

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

private alias object.value0 : object.timer
private alias object.value1 : object.isOOB

// States
private alias 0 : EHZEGGMANDRILL_ATTATCHED
private alias 1 : EHZEGGMANDRILL_IDLE
private alias 2 : EHZEGGMANDRILL_FIRED

// Eggman Car Aliases
private alias object.state 	: eggmanCar.state
private alias object.value1	: eggmanCar.drawPos.y

// Eggman Car States
private alias 1 : EHZEGGMANCAR_EGGMANENTER


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

event ObjectUpdate
	switch object.state
	case EHZEGGMANDRILL_ATTATCHED
		object.xpos = object[-1].xpos
		if object.direction == FLIP_NONE
			object.xpos -= 0x360000
		else
			object.xpos += 0x360000
		end if

		object.ypos = eggmanCar[-1].drawPos.y
		object.ypos += 0x80000

		if eggmanCar[-1].state > EHZEGGMANCAR_EGGMANENTER
			object.timer++
			if object.timer == 18
				object.timer = 0
			end if

			object.frame = object.timer
			object.frame /= 6
		end if
		break

	case EHZEGGMANDRILL_IDLE
		break

	case EHZEGGMANDRILL_FIRED
		object.xpos += object.xvel

		object.timer++
		if object.timer == 18
			object.timer = 0
		end if

		object.frame = object.timer
		object.frame /= 6

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

	if eggmanCar[-1].state > EHZEGGMANCAR_EGGMANENTER
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			if checkResult == true
				CallFunction(Player_Hit)
			end if
		next
	end if
end event


event ObjectDraw
	DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone01")
	if checkResult == true
		LoadSpriteSheet("EHZ/Objects.gif")
		
		// Drill Frames
		SpriteFrame(-16, -12, 32, 23, 94, 131)
		SpriteFrame(-16, -12, 32, 23, 127, 131)
		SpriteFrame(-16, -12, 32, 23, 160, 131)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		
		// Drill Frames
		SpriteFrame(-16, -12, 32, 23, 123, 34)
		SpriteFrame(-16, -12, 32, 23, 156, 34)
		SpriteFrame(-16, -12, 32, 23, 189, 34)
	end if
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone01")
	if checkResult == true
		LoadSpriteSheet("EHZ/Objects.gif")
		SpriteFrame(-16, -12, 32, 23, 94, 131)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-16, -12, 32, 23, 123, 34)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
