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

//-------Aliases-------//
private alias 65 : TYPE_SPINNERH


// Static Values

// Tables

event ObjectMain
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CheckEqual(object[currentPlayer].state, PlayerObject_Death)
		temp0 = checkResult
		CheckEqual(object[currentPlayer].state, PlayerObject_KnuxLedgePullUp)
		temp0 |= checkResult
		if temp0 == 0
			BoxCollisionTest(C_TOUCH, object.entityPos, object.value0, -12, object.value1, 12, currentPlayer, 0, 0, 0, 0)
			if checkResult == 1
				switch object.direction
				case 0
					if object[currentPlayer].yvel > 0
						if object[currentPlayer].animation != ANI_JUMPING
							if object[currentPlayer].state != CNZSetup_Function97
								PlaySfx(SfxName[Rolling], 0)
							end if
						end if
						if object[currentPlayer].state == PlayerObject_KnuxGlideLeft
							FlipSign(object[currentPlayer].speed)
						end if
						object[currentPlayer].state = CNZSetup_Function97
						object[currentPlayer].animation = ANI_JUMPING
						if object[currentPlayer].value34 == 1
							object[currentPlayer].value34 = 0
						end if
						object[currentPlayer].value35 = 0
					else
						CheckEqual(object[currentPlayer].state, CNZSetup_Function97)
						temp0 = checkResult
						CheckEqual(object[currentPlayer].state, CNZSetup_Function98)
						temp0 |= checkResult
						if temp0 == 1
							object[currentPlayer].state = PlayerObject_HandleRolling
							object[currentPlayer].animation = ANI_JUMPING
						end if
					end if
					break
				case 1
					if object[currentPlayer].yvel < 0
						if object[currentPlayer].animation != ANI_JUMPING
							if object[currentPlayer].state != CNZSetup_Function97
								PlaySfx(SfxName[Rolling], 0)
							end if
						end if
						if object[currentPlayer].state == PlayerObject_KnuxGlideLeft
							FlipSign(object[currentPlayer].speed)
						end if
						object[currentPlayer].state = CNZSetup_Function97
						object[currentPlayer].animation = ANI_JUMPING
						if object[currentPlayer].value34 == 1
							object[currentPlayer].value34 = 0
						end if
						object[currentPlayer].value35 = 0
					else
						CheckEqual(object[currentPlayer].state, CNZSetup_Function97)
						temp0 = checkResult
						CheckEqual(object[currentPlayer].state, CNZSetup_Function98)
						temp0 |= checkResult
						if temp0 == 1
							object[currentPlayer].state = PlayerObject_HandleRolling
							object[currentPlayer].animation = ANI_JUMPING
						end if
					end if
					break
				end switch
			end if
		end if
	next
end event


event ObjectStartup
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-8, -8, 16, 16, 127, 113)
	SpriteFrame(-8, -8, 16, 16, 144, 113)
	foreach (TypeName[Spinner H], arrayPos0, ALL_ENTITIES)
		temp0 = object[arrayPos0].propertyValue
		temp0 &= 3
		temp0 += 2
		object[arrayPos0].value0 = 1
		object[arrayPos0].value0 <<= temp0
		object[arrayPos0].value0 <<= 3
		object[arrayPos0].value1 = object[arrayPos0].value0
		FlipSign(object[arrayPos0].value0)
		GetBit(object[arrayPos0].direction, object[arrayPos0].propertyValue, 2)
	next
end event


event ObjectDraw
	if object[0].type == TypeName[Debug Mode]
		temp1 = object.propertyValue
		temp1 &= 3
		temp1 += 2
		temp0 = 1
		temp0 <<= temp1
		temp1 = temp0
		temp0 <<= 19
		FlipSign(temp0)
		temp0 += object.xpos
		temp0 += 0x80000
		GetBit(temp2, object.propertyValue, 2)
		temp3 = 0
		while temp3 < temp1
			DrawSpriteXY(temp2, temp0, object.ypos)
			temp0 += 0x100000
			temp3++
		loop
		if temp1 == 0
			DrawSprite(temp2)
		end if
	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
