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

//-------Aliases-------//
private alias 64 : TYPE_TRIBUMPER

// Function declarations
reserve function TriBumper_Function139
reserve function TriBumper_Function140

// Static Values

// Tables

function TriBumper_Function139
	ATan2(temp0, object[currentPlayer].xvel, object[currentPlayer].yvel)
	temp0 -= temp3
	temp1 = temp0
	Abs(temp1)
	FlipSign(temp0)
	temp0 += 256
	temp0 += temp3
	temp0 &= 255
	if temp1 >= 56
		temp0 = temp3
	end if
	Cos256(object[currentPlayer].xvel, temp0)
	object[currentPlayer].xvel *= -0xA00
	Sin256(object[currentPlayer].yvel, temp0)
	object[currentPlayer].yvel *= -0xA00
end function


function TriBumper_Function140
	if object[currentPlayer].state == PlayerObject_HandleFlyCarry
		object[1].value36 = 30
	end if
	CheckEqual(object[currentPlayer].animation, ANI_GLIDING)
	temp2 = checkResult
	CheckEqual(object[currentPlayer].animation, ANI_GLIDING_STOP)
	temp2 |= checkResult
	CheckEqual(object[currentPlayer].animation, ANI_FLYING)
	temp2 |= checkResult
	CheckEqual(object[currentPlayer].state, PlayerObject_HandleRollDecel)
	temp2 |= checkResult
	CheckEqual(object[currentPlayer].state, PlayerObject_Unknown)
	temp2 |= checkResult
	if object[currentPlayer].animation != ANI_GLIDING
		object[currentPlayer].speed = object[currentPlayer].xvel
		object[currentPlayer].value1 = 0
	end if
	if temp2 == 0
		object[currentPlayer].state = PlayerObject_HandleAir
		if object[currentPlayer].animation != ANI_JUMPING
			if object[currentPlayer].animation != ANI_RUNNING
				object[currentPlayer].animation = ANI_WALKING
			end if
		end if
	end if
	object[currentPlayer].gravity = GRAVITY_AIR
	object[currentPlayer].tileCollisions = 1
	PlaySfx(SfxName[CNZ Bumper], 0)
end function


event ObjectMain
	switch object.propertyValue
	case 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -32, -32, 32, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				temp0 = object.ypos
				temp0 -= object[currentPlayer].ypos
				FlipSign(temp0)
				if temp0 >= 0x200000
					object[currentPlayer].yvel = 0xA0000
					CallFunction(TriBumper_Function140)
				else
					temp0 = object.xpos
					temp0 -= object[currentPlayer].xpos
					FlipSign(temp0)
					if temp0 >= 0x200000
						object[currentPlayer].xvel = 0xA0000
						CallFunction(TriBumper_Function140)
					else
						temp0 = object.xpos
						temp0 -= object[currentPlayer].xpos
						if temp0 >= 0x200000
							temp0 = 0x200000
						end if
						temp0 += object.ypos
						temp0 -= 0x80000
						temp1 = object[currentPlayer].ypos
						temp1 += 0xE0000
						temp0 -= temp1
						if temp0 < 0
							temp3 = 32
							CallFunction(TriBumper_Function139)
							CallFunction(TriBumper_Function140)
						end if
					end if
				end if
			end if
		next
		break
	case 1
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -32, -32, 32, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				temp0 = object.ypos
				temp0 -= object[currentPlayer].ypos
				FlipSign(temp0)
				if temp0 >= 0x200000
					object[currentPlayer].yvel = 0xA0000
					CallFunction(TriBumper_Function140)
				else
					temp0 = object.xpos
					temp0 -= object[currentPlayer].xpos
					if temp0 >= 0x200000
						object[currentPlayer].xvel = -0xA0000
						CallFunction(TriBumper_Function140)
					else
						temp0 = object.xpos
						temp0 -= object[currentPlayer].xpos
						FlipSign(temp0)
						if temp0 >= 0x200000
							temp0 = 0x200000
						end if
						temp0 += object.ypos
						temp0 -= 0x80000
						temp1 = object[currentPlayer].ypos
						temp1 += 0xE0000
						temp0 -= temp1
						if temp0 < 0
							temp3 = 96
							CallFunction(TriBumper_Function139)
							CallFunction(TriBumper_Function140)
						end if
					end if
				end if
			end if
		next
		break
	case 2
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -64, -8, 64, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				temp0 = object.ypos
				temp0 -= object[currentPlayer].ypos
				FlipSign(temp0)
				if temp0 >= 0x80000
					object[currentPlayer].yvel = 0xA00
					CallFunction(TriBumper_Function140)
				else
					temp0 = object.xpos
					temp0 -= object[currentPlayer].xpos
					if temp0 >= 0x400000
						object[currentPlayer].xvel = -0xA0000
						CallFunction(TriBumper_Function140)
					else
						FlipSign(temp0)
						if temp0 >= 0x400000
							object[currentPlayer].xvel = 0xA0000
							CallFunction(TriBumper_Function140)
						else
							if temp0 < 0
								temp3 = 56
							else
								temp3 = 72
							end if
							CallFunction(TriBumper_Function139)
							CallFunction(TriBumper_Function140)
						end if
					end if
				end if
			end if
		next
		break
	case 3
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -64, -8, 64, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				temp0 = object.ypos
				temp0 -= object[currentPlayer].ypos
				if temp0 >= 0x80000
					object[currentPlayer].yvel = -0xA0000
					CallFunction(TriBumper_Function140)
				else
					temp0 = object.xpos
					temp0 -= object[currentPlayer].xpos
					if temp0 >= 0x400000
						object[currentPlayer].xvel = -0xA0000
						CallFunction(TriBumper_Function140)
					else
						FlipSign(temp0)
						if temp0 >= 0x400000
							object[currentPlayer].xvel = 0xA0000
							CallFunction(TriBumper_Function140)
						else
							if temp0 < 0
								temp3 = 200
							else
								temp3 = 184
							end if
							CallFunction(TriBumper_Function139)
							CallFunction(TriBumper_Function140)
						end if
					end if
				end if
			end if
		next
		break
	case 4
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -8, -64, 8, 64, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				temp0 = object.xpos
				temp0 -= object[currentPlayer].xpos
				FlipSign(temp0)
				if temp0 >= 0x80000
					object[currentPlayer].xvel = 0xA0000
					CallFunction(TriBumper_Function140)
				else
					temp0 = object.ypos
					temp0 -= object[currentPlayer].ypos
					if temp0 >= 0x400000
						object[currentPlayer].yvel = -0xA0000
						CallFunction(TriBumper_Function140)
					else
						FlipSign(temp0)
						if temp0 >= 0x400000
							object[currentPlayer].yvel = 0xA0000
							CallFunction(TriBumper_Function140)
						else
							if temp0 < 0
								temp3 = 8
							else
								temp3 = 248
							end if
							CallFunction(TriBumper_Function139)
							CallFunction(TriBumper_Function140)
						end if
					end if
				end if
			end if
		next
		break
	case 5
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -8, -64, 8, 64, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				temp0 = object.xpos
				temp0 -= object[currentPlayer].xpos
				if temp0 >= 0x80000
					object[currentPlayer].xvel = 0xA0000
					CallFunction(TriBumper_Function140)
				else
					temp0 = object.ypos
					temp0 -= object[currentPlayer].ypos
					if temp0 >= 0x400000
						object[currentPlayer].yvel = -0xA0000
						CallFunction(TriBumper_Function140)
					else
						FlipSign(temp0)
						if temp0 >= 0x400000
							object[currentPlayer].yvel = 0xA0000
							CallFunction(TriBumper_Function140)
						else
							if temp0 < 0
								temp3 = 120
							else
								temp3 = 136
							end if
							CallFunction(TriBumper_Function139)
							CallFunction(TriBumper_Function140)
						end if
					end if
				end if
			end if
		next
		break
	end switch
end event

event RSDKDraw
	DrawSprite(0)
end event

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