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

//-------Aliases-------//
private alias 65 : TYPE_CHECKEREDBALL

// Function declarations
reserve function CheckeredBall_DebugDraw
reserve function CheckeredBall_DebugSpawn
reserve function CheckeredBall_Function138
reserve function CheckeredBall_Function139
reserve function CheckeredBall_Function140
reserve function CheckeredBall_Function141
reserve function CheckeredBall_Function142
reserve function CheckeredBall_Function143
reserve function CheckeredBall_Function144

// Static Values

// Tables
public table CheckeredBall_table48
	0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6
	7, 8, 9, 10, 12, 14, 16, 20
end table

//0x14C0B
private table CheckeredBall_table0
	253, 251, 248, 245, 243, 240, 237, 235, 232, 229, 226, 224, 221, 219, 216, 213, 210, 208, 205, 203, 200, 197, 195, 192
end table

function CheckeredBall_DebugDraw
	DrawSprite(1)
end function


function CheckeredBall_DebugSpawn
	CreateTempObject(TypeName[Checkered Ball], 0, object.xpos, object.ypos)
	object[tempObjectPos].gravity = GRAVITY_AIR
	object[tempObjectPos].value7 = object.xpos
	object[tempObjectPos].value8 = object.ypos
	object[tempObjectPos].value1 = object.xpos
	object[tempObjectPos].value2 = object.ypos
end function


function CheckeredBall_Function138
	object.value10 = 0
	temp2 = 0
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CheckEqual(options.attractMode, 1)
		temp1 = checkResult
		CheckEqual(currentPlayer, 1)
		temp1 &= checkResult
		temp0 = object[currentPlayer].value21
		temp0 >>= 1
		if object[currentPlayer].gravity == GRAVITY_GROUND
			if object[currentPlayer].xvel < 0
				BoxCollisionTest(C_TOUCH, object.entityPos, 0, -14, 15, 14, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					if object[currentPlayer].left == 1
						if temp1 == 0
							SetBit(object.value10, temp2, 1)
							temp1 = object[currentPlayer].value20
							FlipSign(temp1)
							if object.speed > temp1
								object.speed -= temp0
							end if
							object.value6 = 1
						end if
						object[currentPlayer].xpos = object[currentPlayer].collisionRight
						object[currentPlayer].xpos += 14
						object[currentPlayer].xpos <<= 16
						object[currentPlayer].xpos += object.value1
						if object.xvel < 0
							if object[currentPlayer].speed < object.speed
								object[currentPlayer].xvel = object.xvel
								object[currentPlayer].speed = object.speed
							end if
						end if
						object[currentPlayer].pushing = 2
					end if
				end if
			else
				if object[currentPlayer].xvel > 0
					BoxCollisionTest(C_TOUCH, object.entityPos, -15, -14, 0, 14, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
					if checkResult == 1
						if object[currentPlayer].right == 1
							if temp1 == 0
								SetBit(object.value10, temp2, 1)
								if object.speed < object[currentPlayer].value20
									object.speed += temp0
								end if
								object.value6 = 1
							end if
							object[currentPlayer].xpos = object[currentPlayer].collisionLeft
							object[currentPlayer].xpos += -14
							object[currentPlayer].xpos <<= 16
							object[currentPlayer].xpos += object.value1
							if object.xvel > 0
								if object[currentPlayer].speed > object.speed
									object[currentPlayer].xvel = object.xvel
									object[currentPlayer].speed = object.speed
								end if
							end if
							object[currentPlayer].pushing = 2
						end if
					end if
				end if
			end if
		end if
		temp2++
	next
end function


function CheckeredBall_Function139
	temp6 = object.xpos
	temp6 &= -0x10000
	temp6 -= object.value1
	temp7 = object.ypos
	temp7 &= -0x10000
	temp7 -= object.value2
	temp4 = object.xpos
	temp5 = object.ypos
	object.xpos = object.value1
	object.ypos = object.value2
	temp2 = 0
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -2, -2, 2, 2, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 0
			GetBit(temp0, object.value10, temp2)
			if temp0 == 1
				if object[currentPlayer].xpos < object.xpos
					temp1 = object[currentPlayer].collisionRight
					FlipSign(temp1)
					temp1 -= 14
				else
					temp1 = object[currentPlayer].collisionLeft
					FlipSign(temp1)
					temp1 += 14
				end if
				temp1 <<= 16
				object[currentPlayer].xpos = temp1
				object[currentPlayer].xpos += temp4
			else
				BoxCollisionTest(C_BOX, object.entityPos, -14, -14, 14, 14, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					object[currentPlayer].xpos += temp6
					temp0 = temp6
					temp0 >>= 1
					object[currentPlayer].xpos += temp0
					object[currentPlayer].ypos += temp7
					if object[currentPlayer].xvel != 0
						temp0 = object[currentPlayer].value21
						temp0 >>= 2
						if object[currentPlayer].xvel > 0
							FlipSign(temp0)
						end if
					else
						temp0 = 0
					end if
					object.speed += temp0
					if temp0 != 0
						object.value6 = 1
					end if
					object.xpos = temp4
					object.ypos = temp5
					BoxCollisionTest(C_BOX, object.entityPos, -14, -14, 14, 14, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
					object.xpos = object.value1
					object.ypos = object.value2
					if checkResult == 0
						temp0 = temp6
						temp1 = temp6
						temp0 >>= 1
						temp1 += temp0
						object[currentPlayer].speed += temp0
						object[currentPlayer].xvel = object[currentPlayer].speed
						object[currentPlayer].gravity = GRAVITY_AIR
						object[currentPlayer].controlLock = 15
					end if
				end if
				if checkResult == 4
					if object.yvel >= 0
						if object[currentPlayer].gravity == GRAVITY_GROUND
							CallFunction(PlayerObject_Kill)
						end if
					end if
				end if
			end if
			temp2++
		end if
	next
	object.xpos = temp4
	object.ypos = temp5
end function


function CheckeredBall_Function140
	temp0 = object.xvel
	temp0 |= object.yvel
	if temp0 != 0
		ResetObjectEntity(object[arrayPos0].entityPos, TypeName[Blank Object], 0, object[arrayPos0].xpos, object[arrayPos0].ypos)
		Rand(checkResult, 32)
		if checkResult > 15
			CreateTempObject(animalType1, TypeName[Blank Object], object[arrayPos0].xpos, object[arrayPos0].ypos)
		else
			CreateTempObject(animalType2, TypeName[Blank Object], object[arrayPos0].xpos, object[arrayPos0].ypos)
		end if
		object[tempObjectPos].priority = PRIORITY_UNKNOWN
		CreateTempObject(TypeName[Smoke Puff], 0, object[arrayPos0].xpos, object[arrayPos0].ypos)
		object[tempObjectPos].drawOrder = 4
		CreateTempObject(TypeName[Object Score], object.value11, object[arrayPos0].xpos, object[arrayPos0].ypos)
		object[tempObjectPos].drawOrder = 4
		PlaySfx(SfxName[Destroy], 0)
		switch object.value11
		case 0
			player.score += 100
			break
		case 1
			player.score += 200
			break
		case 2
			player.score += 500
			break
		case 3
		case 4
		case 5
		case 6
		case 7
		case 8
		case 9
		case 10
		case 11
		case 12
		case 13
		case 14
			player.score += 1000
			break
		case 15
			player.score += 0x2710
			break
		end switch
		if object.value11 < 15
			object.value11++
		end if
	end if
end function


function CheckeredBall_Function141
	temp0 = object.xpos
	temp0 -= object[arrayPos0].xpos
	temp1 = object.ypos
	temp1 -= object[arrayPos0].ypos
	ATan2(temp2, temp0, temp1)
	Sin256(temp0, temp2)
	Cos256(temp1, temp2)
	object[arrayPos0].xvel = temp1
	object[arrayPos0].xvel *= -0x800
	object[arrayPos0].yvel = temp0
	object[arrayPos0].yvel *= -0x800
end function


function CheckeredBall_Function142
	switch object[arrayPos0].propertyValue
	case 0
		temp0 = object[arrayPos0].value1
		if object.gravity == GRAVITY_AIR
			temp0 = 1
		end if
		if object.collisionMode > CMODE_FLOOR
			if object.yvel < 0
				temp0 = 1
			end if
		end if
		if temp0 == 0
			BoxCollisionTest(C_BOX, object[arrayPos0].entityPos, -14, -8, 14, 8, object.entityPos, -14, -14, 14, 14)
			BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -14, -10, 14, -6, object.entityPos, -14, -14, 14, 14)
			if checkResult == 1
				object[arrayPos0].value0 = 1
				object.tileCollisions = 1
				object.gravity = GRAVITY_AIR
				object.speed = object.xvel
				object.yvel = temp7
				FlipSign(object.yvel)
				object.yvel += object[arrayPos0].value2
				PlaySfx(SfxName[Spring], 0)
			end if
		else
			if object.yvel >= 0
				BoxCollisionTest(C_PLATFORM, object[arrayPos0].entityPos, -14, -8, 14, 8, object.entityPos, -14, -14, 14, 14)
				BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -14, -10, 14, -6, object.entityPos, -14, -14, 14, 14)
				if checkResult == 1
					object[arrayPos0].value0 = 1
					object.tileCollisions = 1
					object.gravity = GRAVITY_AIR
					object.speed = object.xvel
					object.yvel = temp7
					FlipSign(object.yvel)
					object.yvel += object[arrayPos0].value2
					PlaySfx(SfxName[Spring], 0)
				end if
			end if
		end if
		break
	case 1
		BoxCollisionTest(C_BOX, object[arrayPos0].entityPos, -8, -14, 8, 14, object.entityPos, -14, -14, 14, 14)
		if object.gravity == GRAVITY_GROUND
			BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, 6, -14, 10, 14, object.entityPos, -14, -14, 14, 14)
			if checkResult == 1
				object[arrayPos0].value0 = 1
				object.tileCollisions = 1
				object.speed = temp7
				object.collisionMode = CMODE_FLOOR
				object.direction = FLIP_NONE
				PlaySfx(SfxName[Spring], 0)
			end if
		end if
		break
	case 2
		BoxCollisionTest(C_BOX, object[arrayPos0].entityPos, -8, -14, 8, 14, object.entityPos, -14, -14, 14, 14)
		if object.gravity == GRAVITY_GROUND
			BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -10, -14, -6, 14, object.entityPos, -14, -14, 14, 14)
			if checkResult == 1
				object[arrayPos0].value0 = 1
				object.tileCollisions = 1
				object.speed = temp7
				FlipSign(object.speed)
				object.collisionMode = CMODE_FLOOR
				object.direction = FLIP_X
				PlaySfx(SfxName[Spring], 0)
			end if
		end if
		break
	case 3
		BoxCollisionTest(C_BOX, object[arrayPos0].entityPos, -14, -8, 14, 8, object.entityPos, -14, -14, 14, 14)
		BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -14, 6, 14, 10, object.entityPos, -14, -14, 14, 14)
		if checkResult == 1
			object[arrayPos0].value0 = 1
			if object.collisionMode == CMODE_ROOF
				FlipSign(object.speed)
				FlipSign(object.xvel)
			end if
			object.tileCollisions = 1
			object.gravity = GRAVITY_AIR
			object.speed = object.xvel
			object.yvel = temp7
			PlaySfx(SfxName[Spring], 0)
		end if
		break
	end switch
end function


function CheckeredBall_Function143
	if object[arrayPos0].state < 3
		player.score++
		if object[arrayPos0].propertyValue < 2
			if object.yvel >= 0
				BoxCollisionTest(C_PLATFORM, arrayPos0, -64, -24, 64, 0, object.entityPos, -10, -14, 10, 14)
			else
				checkResult = 0
			end if
		else
			BoxCollisionTest(C_BOX, arrayPos0, -64, -16, 64, 16, object.entityPos, -10, -14, 10, 14)
		end if
		if checkResult == 1
			if object[arrayPos0].state == 0
				object[arrayPos0].state = 1
				object[arrayPos0].priority = PRIORITY_ACTIVE
			end if
		end if
	end if
end function


function CheckeredBall_Function144
	if object.gravity == GRAVITY_AIR
		object.yvel += 0x3800
		object.speed = object.xvel
	else
		Sin256(temp0, object.value4)
		temp0 *= 0x2000
		temp0 >>= 8
		object.speed += temp0
		object.value5 = object.speed
		if temp0 == 0
			if object.value6 == 0
				if object.speed > 0
					object.speed -= 0x400
					if object.speed < 0
						object.speed = 0
					end if
				else
					object.speed += 0x400
					if object.speed > 0
						object.speed = 0
					end if
				end if
			end if
		end if
		Cos256(temp0, object.value4)
		temp0 *= object.speed
		temp0 >>= 8
		object.xvel = temp0
		Sin256(temp0, object.value4)
		temp0 *= object.speed
		temp0 >>= 8
		object.yvel = temp0
	end if
	object.value6 = 0
end function


event ObjectMain
	if object.state == 0
		object.priority = PRIORITY_ACTIVE
		CallFunction(CheckeredBall_Function138)
		object.value3 += object.value5
		object.collisionLeft = -14
		object.collisionTop = -14
		object.collisionRight = 14
		object.collisionBottom = 14
		CallFunction(CheckeredBall_Function144)
		ProcessObjectMovement()
		object.value4 = object.angle
	else
		object.collisionLeft = -14
		object.collisionTop = -14
		object.collisionRight = 14
		object.collisionBottom = 14
		ProcessObjectMovement()
		object.value3 += 0x40000
	end if
	foreach (TypeName[Blank Object], arrayPos0, ACTIVE_ENTITIES)
		switch object[arrayPos0].type
		case 55
			BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, arrayPos0, -16, -12, 16, 12)
			if checkResult == 1
				CallFunction(CheckeredBall_Function140)
			end if
			break
		case 57
			BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, arrayPos0, -16, -10, 16, 10)
			if checkResult == 1
				CallFunction(CheckeredBall_Function140)
			end if
			break
		case 56
			BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, arrayPos0, -4, -4, 4, 4)
			if checkResult == 1
				CallFunction(CheckeredBall_Function141)
			end if
			break
		case 58
			BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, arrayPos0, -4, -4, 4, 4)
			if checkResult == 1
				CallFunction(CheckeredBall_Function141)
			end if
			break
		case 13
			BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, arrayPos0, -16, -14, 16, 16)
			if checkResult == 1
				object[arrayPos0].state = 0
				CreateTempObject(TypeName[Smoke Puff], 0, object[arrayPos0].xpos, object[arrayPos0].ypos)
				object[tempObjectPos].drawOrder = 4
				object[arrayPos0].type = TypeName[Broken Monitor]
				if object[arrayPos0].priority != PRIORITY_XBOUNDS_DESTROY
					object[arrayPos0].priority = PRIORITY_ACTIVE
				end if
				object[arrayPos0].alpha = 255
				object[arrayPos0].value0 = object[arrayPos0].ypos
				object[arrayPos0].value1 = -0x30000
				PlaySfx(SfxName[Destroy], 0)
			end if
			break
		case 17
			switch object[arrayPos0].propertyValue
			case 0
				BoxCollisionTest(C_BOX, arrayPos0, -16, -16, 16, 16, object.entityPos, -14, -14, 14, 14)
				break
			case 1
				BoxCollisionTest(C_BOX, arrayPos0, -16, -16, 15, 16, object.entityPos, -14, -14, 14, 14)
				break
			case 2
				BoxCollisionTest(C_BOX, arrayPos0, -15, -16, 16, 16, object.entityPos, -14, -14, 14, 14)
				break
			case 3
				BoxCollisionTest(C_BOX, arrayPos0, -16, -16, 16, 15, object.entityPos, -14, -14, 14, 14)
				break
			end switch
			switch checkResult
			case 1
				object.gravity = GRAVITY_GROUND
				break
			case 2
				if object.speed > 0
					object.speed = 0
				end if
				break
			case 3
				if object.speed < 0
					object.speed = 0
				end if
				break
			end switch
			break
		case 16
			temp7 = 0xA0000
			CallFunction(CheckeredBall_Function142)
			break
		case 15
			temp7 = 0x100000
			CallFunction(CheckeredBall_Function142)
			break
		case 50
			temp0 = object[arrayPos0].value1
			temp0 -= object[arrayPos0].value2
			temp0 >>= 16
			temp0 -= 20
			BoxCollisionTest(C_BOX, arrayPos0, -16, temp0, 16, 20, object.entityPos, -10, -14, 10, 14)
			if checkResult == 1
				object[arrayPos0].value3 |= 1
				object.ypos += object[arrayPos0].value2
				if object[arrayPos0].state == 2
					if object[arrayPos0].value1 == 0x120000
						object.gravity = GRAVITY_AIR
						object.yvel = -0x60000
						object.value0 = 0
						PlaySfx(SfxName[Spring], 0)
					end if
				end if
			end if
			break
		case 51
			if object[arrayPos0].direction == FLIP_NONE
				temp0 = -20
				temp1 = object[arrayPos0].value1
				temp1 >>= 16
				FlipSign(temp1)
				temp1 += 22
			else
				temp0 = object[arrayPos0].value1
				temp0 >>= 16
				temp0 -= 22
				temp1 = 20
			end if
			temp2 = object.speed
			BoxCollisionTest(C_BOX, arrayPos0, temp0, -16, temp1, 16, object.entityPos, -10, -14, 10, 14)
			object.speed = temp2
			switch checkResult
			case 2
				temp0 >>= 8
				object.speed -= temp0
				if object.speed > 0
					object[arrayPos0].value2 |= 1
				end if
				if object[arrayPos0].state == 1
					if object[arrayPos0].value1 > 0x10000
						object.speed = -12
						object.speed *= object[arrayPos0].value1
						object.speed /= 18
						object.collisionMode = CMODE_FLOOR
						PlaySfx(SfxName[Spring], 0)
					end if
				end if
				break
			case 3
				temp0 >>= 5
				object.speed -= temp0
				if object.speed < 0
					object[arrayPos0].value2 |= 1
				end if
				if object[arrayPos0].state == 1
					if object[arrayPos0].value1 > 0x10000
						object.speed = 12
						object.speed *= object[arrayPos0].value1
						object.speed /= 18
						PlaySfx(SfxName[Spring], 0)
					end if
				end if
				break
			end switch
			break
		case 52
			BoxCollisionTest(C_TOUCH, arrayPos0, -4, -4, 4, 4, object.entityPos, -10, -14, 10, 14)
			if checkResult == 1
				temp0 = 1
				temp0 <<= 5
				temp0 &= object[arrayPos0].value5
				if temp0 == 0
					object.state = 1
					object.xpos = object[arrayPos0].xpos
					object.ypos = object[arrayPos0].ypos
					object.speed = 0
					object.xvel = 0
					object.yvel = 0
					object.visible = 0
					object.tileCollisions = 0
					temp0 = 1
					temp0 <<= 5
					object[arrayPos0].value5 |= temp0
					object[arrayPos0].value0 = 0
					object[arrayPos0].value1 = 0
					object[arrayPos0].state = 1
					if object[arrayPos0].priority != PRIORITY_XBOUNDS_DESTROY
						object[arrayPos0].priority = PRIORITY_ACTIVE
					end if
					object.value15 = arrayPos0
					PlaySfx(SfxName[Rolling], 0)
				end if
			end if
			break
		case 44
			temp0 = object[arrayPos0].ypos
			object[arrayPos0].ypos = object[arrayPos0].value1
			BoxCollisionTest(C_BOX, arrayPos0, -32, 8, 32, 48, object.entityPos, -10, -14, 10, 14)
			BoxCollisionTest(C_BOX, arrayPos0, -16, 0, 16, 24, object.entityPos, -10, -14, 10, 14)
			object[arrayPos0].ypos = temp0
			object[arrayPos0].ypos -= object[arrayPos0].value2
			BoxCollisionTest(C_PLATFORM, arrayPos0, -24, -8, 24, 12, object.entityPos, -10, -14, 10, 14)
			if checkResult == 1
				object.value13 = object[arrayPos0].value2
			end if
			object[arrayPos0].ypos += object[arrayPos0].value2
			break
		case 45
			object[arrayPos0].ypos -= object[arrayPos0].value4
			if object[arrayPos0].frame == 0
				BoxCollisionTest(C_PLATFORM, arrayPos0, -64, -12, 64, 12, object.entityPos, -10, -14, 10, 14)
			else
				BoxCollisionTest(C_PLATFORM, arrayPos0, -32, -12, 32, 12, object.entityPos, -10, -14, 10, 14)
			end if
			if checkResult == 1
				object.value13 = object[arrayPos0].value4
			end if
			object[arrayPos0].ypos += object[arrayPos0].value4
			break
		case 46
			temp0 = object[arrayPos0].xpos
			temp1 = object[arrayPos0].ypos
			object[arrayPos0].xpos = object[arrayPos0].value1
			object[arrayPos0].ypos = object[arrayPos0].value2
			object[arrayPos0].xpos -= object[arrayPos0].value3
			object[arrayPos0].ypos -= object[arrayPos0].value4
			BoxCollisionTest(C_PLATFORM, object[arrayPos0].entityPos, -32, -8, 32, 8, object.entityPos, -10, -14, 10, 14)
			if checkResult == 1
				object.value12 = object[arrayPos0].value3
				object.value13 = object[arrayPos0].value4
			end if
			object[arrayPos0].xpos = temp0
			object[arrayPos0].ypos = temp1
			break
		case 43
			CallFunction(CheckeredBall_Function143)
			break
		case 36
			CheckEqual(object[arrayPos0].value6, 0)
			temp0 = checkResult
			CheckEqual(object.gravity, GRAVITY_GROUND)
			temp0 |= checkResult
			if temp0 == 1
				BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -12, object[arrayPos0].value0, 12, object[arrayPos0].value1, object.entityPos, -2, -14, 2, 14)
				if checkResult == 1
					if object.xvel > 0
						object.collisionPlane = object[arrayPos0].value3
						object.drawOrder = object[arrayPos0].value5
					else
						object.collisionPlane = object[arrayPos0].value2
						object.drawOrder = object[arrayPos0].value4
					end if
				end if
			end if
			break
		case 35
			CheckEqual(object[arrayPos0].value6, 0)
			temp0 = checkResult
			CheckEqual(object.gravity, GRAVITY_GROUND)
			temp0 |= checkResult
			if temp0 == 1
				BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, object[arrayPos0].value0, -12, object[arrayPos0].value1, 12, object.entityPos, -14, -2, 14, 2)
				if checkResult == 1
					if object.yvel > 0
						object.collisionPlane = object[arrayPos0].value3
						object.drawOrder = object[arrayPos0].value5
					else
						object.collisionPlane = object[arrayPos0].value2
						object.drawOrder = object[arrayPos0].value4
					end if
				end if
			end if
			break
		case 60
			if object[arrayPos0].value3 != 0
				if object[arrayPos0].visible == 1
					if object[arrayPos0].value4 == 0
						BoxCollisionTest(C_TOUCH, arrayPos0, -24, -10, 24, 24, object.entityPos, -14, -14, 14, 14)
						if checkResult == 1
							object[arrayPos0].value3--
							if object[arrayPos0].value3 == 0
								player.score += 1000
								object[arrayPos0].animationTimer = 0
								object[arrayPos0].animation = 4
								object[arrayPos0].value5 = 1
								object[arrayPos0].value0 = 0
								object[arrayPos0].state = 7
								SetPaletteEntry(0, 192, 0)
							else
								object[arrayPos0].animationTimer = 0
								object[arrayPos0].animation = 3
								object[arrayPos0].value4 = 64
								object[arrayPos0].value9 = 1
								PlaySfx(SfxName[Boss Hit], 0)
							end if
						end if
					end if
				end if
			end if
			break
		case 66
			if object[arrayPos0].frame == 0
				BoxCollisionTest(C_BOX, arrayPos0, -14, -6, 14, 12, object.entityPos, -14, -14, 14, 14)
				if checkResult == 1
					object[arrayPos0].value1 = 1
					object[arrayPos0].value0 = 1
					object.ypos += 0x9C40
					PlaySfx(SfxName[Button Press], 0)
				end if
			else
				if object.yvel >= 0
					BoxCollisionTest(C_PLATFORM, arrayPos0, -14, -6, 14, 12, object.entityPos, -14, -14, 14, 14)
					if checkResult == 1
						object[arrayPos0].value1 = 1
						object.ypos += 0x20000
					else
						BoxCollisionTest(C_TOUCH, arrayPos0, -20, -12, 20, 8, object.entityPos, -14, -14, 14, 14)
						if checkResult == 1
							object.ypos = object.collisionBottom
							FlipSign(object.ypos)
							object.ypos <<= 16
							object.ypos += object[arrayPos0].ypos
							object.ypos -= 0x20000
							object.gravity = GRAVITY_AIR
						end if
					end if
				end if
			end if
			break
		case 65
			if arrayPos0 != object.entityPos
				temp0 = object.xpos
				temp0 -= object[arrayPos0].xpos
				Abs(temp0)
				temp0 >>= 17
				if temp0 >= 16
					temp0 = 15
				end if
				GetTableValue(temp6, temp0, CheckeredBall_table48)
				temp0 = temp6
				temp0 >>= 1
				temp6 += temp0
				temp6 -= 14
				temp7 = temp6
				FlipSign(temp7)
				temp0 = object.xvel
				temp1 = object.yvel
				temp2 = object.speed
				BoxCollisionTest(C_BOX, arrayPos0, -14, temp6, 14, temp7, object.entityPos, -14, -14, 14, 14)
				switch checkResult
				case 2
				case 3
					CheckGreater(temp0, 0)
					temp3 = checkResult
					CheckLower(object.xpos, object[arrayPos0].xpos)
					temp3 &= checkResult
					CheckLower(temp0, 0)
					temp4 = checkResult
					CheckGreater(object.xpos, object[arrayPos0].xpos)
					temp4 &= checkResult
					temp3 |= temp4
					if temp3 != 0
						object.xvel = object[arrayPos0].xvel
						object.speed = object[arrayPos0].speed
						object[arrayPos0].xvel = temp0
						object[arrayPos0].speed = temp2
					end if
					break
				case 1
					if object.xpos < object[arrayPos0].xpos
						object.speed -= 0xC00
						object.xvel -= 0xC00
						object[arrayPos0].speed += 0xC00
						object[arrayPos0].xvel += 0xC00
						object[arrayPos0].value5 += 0xC00
					else
						object.speed += 0xC00
						object.xvel += 0xC00
						object[arrayPos0].speed -= 0xC00
						object[arrayPos0].xvel -= 0xC00
						object[arrayPos0].value5 -= 0xC00
					end if
				case 4
					CheckGreater(temp1, 0)
					temp3 = checkResult
					CheckLower(object.ypos, object[arrayPos0].ypos)
					temp3 &= checkResult
					CheckLower(temp1, 0)
					temp4 = checkResult
					CheckGreater(object.ypos, object[arrayPos0].ypos)
					temp4 &= checkResult
					temp3 |= temp4
					if temp3 != 0
						object.yvel = object[arrayPos0].yvel
						object[arrayPos0].yvel = temp1
					end if
					break
				end switch
				BoxCollisionTest(C_TOUCH, arrayPos0, -14, temp6, 14, temp7, object.entityPos, -14, -14, 14, 14)
				if checkResult == 1
					if object.xpos < object[arrayPos0].xpos
						object.xpos -= 0x10000
					else
						object.xpos += 0x10000
					end if
					if object.ypos < object[arrayPos0].ypos
						object.ypos -= 0x10000
					else
						object.ypos += 0x10000
					end if
				end if
			end if
			break
		case 53
			switch object[arrayPos0].state
			case 0
				temp0 = object.yvel
				BoxCollisionTest(C_BOX, arrayPos0, -16, -16, 16, 16, object.entityPos, -14, -14, 14, 14)
				object.yvel = temp0
				if checkResult == 1
					object.gravity = GRAVITY_AIR
					temp0 = 0
					temp1 = 0
					while temp0 < 16
						CreateTempObject(TypeName[Gas Break Block], 0, object[arrayPos0].xpos, object[arrayPos0].ypos)
						GetTableValue(object[tempObjectPos].frame, temp0, GasBreakBlock_table43)
						GetTableValue(temp2, temp1, GasBreakBlock_table44)
						GetTableValue(object[tempObjectPos].xvel, temp1, GasBreakBlock_table45)
						temp1++
						GetTableValue(temp3, temp1, GasBreakBlock_table44)
						GetTableValue(object[tempObjectPos].yvel, temp1, GasBreakBlock_table45)
						temp1++
						object[tempObjectPos].xpos += temp2
						object[tempObjectPos].ypos += temp3
						object[tempObjectPos].state = 2
						object[tempObjectPos].drawOrder = 5
						temp0++
					loop
					object[arrayPos0].state++
					if object[arrayPos0].priority != PRIORITY_XBOUNDS_DESTROY
						object[arrayPos0].priority = PRIORITY_ACTIVE
					end if
					PlaySfx(SfxName[Block Break], 0)
				end if
				break
			case 1
				if object.state == 0
					BoxCollisionTest(C_TOUCH, arrayPos0, -8, -4, 8, 4, object.entityPos, -10, -14, 10, 14)
					if checkResult == 1
						object.state = 1
						object.xpos = object[arrayPos0].xpos
						object.ypos = object[arrayPos0].ypos
						if object[arrayPos0].propertyValue == 0
							object.xvel = 0
							object.yvel = -0x80000
						else
							object.xvel = 0x80000
							object.yvel = 0
						end if
						PlaySfx(SfxName[Rolling], 0)
					end if
				end if
				break
			end switch
			break
		case 22
			object[arrayPos0].value2 = object[arrayPos0].ypos
			object[arrayPos0].value2 -= 0x300000
			temp2 = object[arrayPos0].value2
			temp2 += 0x80000
			BoxCollisionTest(C_BOX, arrayPos0, -32, -24, 32, 32, object.entityPos, -10, -14, 10, 14)
			BoxCollisionTest(C_BOX, arrayPos0, -16, -40, 16, -24, object.entityPos, -10, -14, 10, 14)
			if object[arrayPos0].state == 0
				if checkResult == 1
					object[arrayPos0].state = 1
					stage.timeEnabled = 0
					if PlayerObject_SuperState == 1
						PlayerObject_SuperState = 2
					end if
					object[arrayPos0].xvel = 0x80000
					object[arrayPos0].yvel = -0x40000
					object[arrayPos0].value3 = object[arrayPos0].xpos
					object[arrayPos0].value4 = object[arrayPos0].ypos
					CreateTempObject(TypeName[Smoke Puff], 0, object[arrayPos0].xpos, object[arrayPos0].ypos)
					object[tempObjectPos].ypos -= 0x180000
					PlaySfx(SfxName[Destroy], 0)
				end if
			end if
			BoxCollisionTest(C_TOUCH, arrayPos0, -15, -48, 15, -24, object.entityPos, -10, -14, 10, 14)
			if checkResult == 1
				temp0 = object.collisionBottom
				temp0 <<= 16
				temp0 += object.ypos
				if temp0 > object[arrayPos0].value2
					if temp0 <= temp2
						object[arrayPos0].value2 = temp0
					end if
				end if
			end if
			break
		end switch
	next
	if object.value15 != 0
		arrayPos0 = object.value15
		if object[arrayPos0].state == 4
			if object[arrayPos0].value6 == 1
				object.state = 0
				object.gravity = GRAVITY_AIR
				object.tileCollisions = 1
			end if
			object.visible = 1
			object.value0 = 0
			object.speed = object[arrayPos0].xvel
			object.xvel = object[arrayPos0].xvel
			object.yvel = object[arrayPos0].yvel
		end if
	end if
	temp1 = object.xpos
	temp1 >>= 16
	temp2 = object.ypos
	temp2 >>= 16
	temp2 += 6
	Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_ANGLEB)
	switch temp0
	case 1
		if object.yvel > -1
			object.gravity = GRAVITY_GROUND
			object.yvel = 0
			object.ypos += 0x10000
		end if
		temp0 = object.speed
		temp0 >>= 5
		object.speed -= temp0
		break
	case 3
		break
	case 5
		break
	end switch
	if object.state == 0
		CallFunction(CheckeredBall_Function139)
		temp0 = object.value12
		temp0 |= object.value13
		if temp0 != 0
			foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
				BoxCollisionTest(C_TOUCH, object.entityPos, -2, -2, 2, 2, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 0
					BoxCollisionTest(C_BOX, object.entityPos, -14, -14, 14, 14, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
					if checkResult == 1
						object[currentPlayer].xpos += object.value12
						object[currentPlayer].ypos += object.value13
					end if
				end if
			next
			object.xpos += object.value12
			object.ypos += object.value13
			object.value12 = 0
			object.value13 = 0
		end if
	end if
	if object.outOfBounds == 1
		temp0 = object.xpos
		temp1 = object.ypos
		object.xpos = object.value7
		object.ypos = object.value8
		if object.outOfBounds == 1
			object.value1 = object.xpos
			object.value2 = object.ypos
			object.xvel = 0
			object.yvel = 0
			object.speed = 0
			object.value11 = 0
			object.value4 = 0
			object.value10 = 0
			object.value3 = 0
			object.value5 = 0
			object.value6 = 0
			object.priority = PRIORITY_ACTIVE_BOUNDS
			object.state = 0
		else
			object.xpos = temp0
			object.ypos = temp1
		end if
	end if
	object.value1 = object.xpos
	object.value1 &= -0x10000
	object.value2 = object.ypos
	object.value2 &= -0x10000
end event


event ObjectDraw
	object.rotation = object.value3
	object.rotation >>= 14
	temp0 = object.rotation
	temp0 += 8
	temp0 >>= 4
	temp0 &= 7
	temp0++
	DrawSprite(temp0)
	object.inkEffect = INK_ADD
	object.alpha = 160
	DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
end event


event ObjectStartup
	LoadSpriteSheet("OOZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 396, 190)
	SpriteFrame(-16, -16, 32, 32, 429, 190)
	SpriteFrame(-16, -16, 32, 32, 273, 133)
	SpriteFrame(-16, -16, 32, 32, 322, 100)
	SpriteFrame(-16, -16, 32, 32, 289, 100)
	SpriteFrame(-16, -16, 32, 32, 256, 100)
	SpriteFrame(-16, -16, 32, 32, 256, 67)
	SpriteFrame(-16, -16, 32, 32, 256, 34)
	SpriteFrame(-16, -16, 32, 32, 256, 1)
	LoadAnimation("WreckingBallJr.ani")
	foreach (TypeName[Checkered Ball], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].gravity = GRAVITY_AIR
		object[arrayPos0].value7 = object.xpos
		object[arrayPos0].value8 = object.ypos
	next
	SetTableValue(TypeName[Checkered Ball], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(CheckeredBall_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(CheckeredBall_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

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