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

//-------Aliases-------//
private alias 61 : TYPE_EGGMANCAR


// Static Values

// Tables

event ObjectMain
	if object.state < 3
		object.value1 = object.value4
		object.value1 >>= 1
		object.value1 -= 0xC0000
		object.value4 = 0
	end if
	switch object.state
	case 0
		object.xpos -= 0x10000
		object.value0++
		if object.value0 == 321
			object.value0 = 0
			object.state++
		end if
		temp0 = oscillation
		temp0 &= 15
		if temp0 == 0
			temp0 = object.xpos
			if object.direction == FLIP_NONE
				temp0 += 0x2E0000
			else
				temp0 -= 0x2E0000
			end if
			temp1 = object.value1
			temp1 -= 0x40000
			CreateTempObject(TypeName[Exhaust Puff], 0, temp0, temp1)
			object[tempObjectPos].yvel = -0x10000
		end if
		break
	case 1
		break
	case 2
		object.xpos += object.xvel
		if object.xpos <= object.value2
			FlipSign(object.xvel)
			object.direction ^= FLIP_X
			object[-2].direction ^= FLIP_X
			object[-1].direction ^= FLIP_X
			object[+1].direction ^= FLIP_X
			object[+2].direction ^= FLIP_X
			object[+3].direction ^= FLIP_X
			object[+4].direction ^= FLIP_X
			if object[-1].value8 == 1
				if object[+1].state == 0
					object[+1].state += 2
					object[+1].xpos = object.xpos
					if object.direction == FLIP_NONE
						object[+1].xpos -= 0x360000
						object[+1].xvel = -0x30000
					else
						object[+1].xpos += 0x360000
						object[+1].xvel = 0x30000
					end if
				end if
			end if
		end if
		if object.xpos >= object.value3
			FlipSign(object.xvel)
			object.direction ^= FLIP_X
			object[-2].direction ^= FLIP_X
			object[-1].direction ^= FLIP_X
			object[+1].direction ^= FLIP_X
			object[+2].direction ^= FLIP_X
			object[+3].direction ^= FLIP_X
			object[+4].direction ^= FLIP_X
			if object[-1].value8 == 1
				if object[+1].state == 0
					object[+1].state += 2
					object[+1].xpos = object.xpos
					if object.direction == FLIP_NONE
						object[+1].xpos -= 0x360000
						object[+1].xvel = -0x30000
					else
						object[+1].xpos += 0x360000
						object[+1].xvel = 0x30000
					end if
				end if
			end if
		end if
		object[-1].xpos = object.xpos
		object[-1].ypos = object.value1
		object[-1].ypos -= 0x80000
		temp0 = oscillation
		temp0 &= 15
		if temp0 == 0
			temp0 = object.xpos
			if object.direction == FLIP_NONE
				temp0 += 0x2E0000
			else
				temp0 -= 0x2E0000
			end if
			temp1 = object.value1
			temp1 -= 0x40000
			CreateTempObject(TypeName[Exhaust Puff], 0, temp0, temp1)
			object[tempObjectPos].yvel = -0x10000
		end if
		break
	case 3
		object.ypos += object.yvel
		object.yvel += 0x3800
		object.value1 = object.ypos
		ObjectTileCollision(CSIDE_FLOOR, 0, 17, 0)
		if checkResult == 1
			if object.direction == FLIP_NONE
				temp0 = -0x20000
			else
				temp0 = 0x20000
			end if
			object[-2].state += 2
			object[-2].xvel = temp0
			object[-2].yvel = 0x30000
			FlipSign(object[-2].xvel)
			object[+2].state += 2
			object[+2].xvel = temp0
			object[+2].yvel = 0x30000
			object[+3].state += 2
			object[+3].xvel = temp0
			object[+3].yvel = 0x30000
			object.state++
		end if
		object[-1].xpos = object.xpos
		object[-1].ypos = object.value1
		object[-1].ypos -= 0x80000
		break
	case 4
		break
	end switch
end event


event ObjectDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.value1)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone01")
	if checkResult == 1
		LoadSpriteSheet("EHZ/Objects.gif")
		SpriteFrame(-48, -16, 93, 32, 0, 109)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-48, -16, 93, 32, 123, 1)
	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
