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

//-------Aliases-------//
private alias 87 : TYPE_WFZINVBLOCK


// Static Values

// Tables

event ObjectMain
	temp0 = object.value0
	FlipSign(temp0)
	temp1 = object.value1
	FlipSign(temp1)
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if object[currentPlayer].state != PlayerObject_KnuxLedgePullUp
			if object[currentPlayer].animation != ANI_FANROTATE
				BoxCollisionTest(C_BOX, object.entityPos, temp0, temp1, object.value0, object.value1, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				switch checkResult
				case 0
					temp0 += 2
					temp1 += 2
					temp2 = object.value0
					temp3 = object.value1
					temp2 -= 2
					temp3 -= 2
					BoxCollisionTest(C_TOUCH, object.entityPos, temp0, temp1, temp2, temp3, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
					if checkResult == 1
						object[currentPlayer].gravity = GRAVITY_GROUND
					end if
					break
				case 4
					if object[currentPlayer].gravity == GRAVITY_GROUND
						CallFunction(PlayerObject_Kill)
					end if
					break
				end switch
			end if
		end if
	next
end event


event ObjectDraw
	if object[0].type == TypeName[Debug Mode]
		temp0 = object.xpos
		temp1 = object.ypos
		temp2 = object.propertyValue
		temp4 = temp2
		temp4 &= 240
		temp4 <<= 15
		temp2 >>= 4
		temp2++
		temp6 = temp2
		temp3 = object.propertyValue
		temp3 &= 15
		temp5 = temp3
		temp5 <<= 19
		temp3++
		temp0 -= temp4
		temp4 = temp0
		temp1 -= temp5
		while temp3 > 0
			while temp2 > 0
				DrawSpriteXY(0, temp0, temp1)
				temp0 += 0x100000
				temp2--
			loop
			temp2 = temp6
			temp0 = temp4
			temp1 += 0x100000
			temp3--
		loop
	end if
end event


event ObjectStartup
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-8, -7, 16, 14, 1, 176)
	foreach (TypeName[WFZ Inv Block], arrayPos0, ALL_ENTITIES)
		if object[arrayPos0].value0 == 1
			if options.gameMode != 2
				object[arrayPos0].type = TypeName[Blank Object]
			end if
		end if
		object[arrayPos0].drawOrder = 5
		object[arrayPos0].value0 = object[arrayPos0].propertyValue
		object[arrayPos0].value0 &= 240
		object[arrayPos0].value0 += 16
		object[arrayPos0].value0 >>= 1
		object[arrayPos0].value1 = object[arrayPos0].propertyValue
		object[arrayPos0].value1 &= 15
		object[arrayPos0].value1++
		object[arrayPos0].value1 <<= 3
	next
end event

event RSDKDraw
	DrawSprite(0)
end event

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