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

//-------Aliases-------//
private alias 51 : TYPE_VBLOCK

// Function declarations
reserve function VBlock_DebugDraw
reserve function VBlock_DebugSpawn

// Static Values

// Tables

function VBlock_DebugDraw
	DrawSprite(0)
end function


function VBlock_DebugSpawn
	CreateTempObject(TypeName[V Block], 0, object.xpos, object.ypos)
	object[tempObjectPos].value1 = object.ypos
	object[tempObjectPos].propertyValue = object.direction
	if object[tempObjectPos].propertyValue == 0
		object[tempObjectPos].ypos -= 0x600000
	else
		object[tempObjectPos].ypos += 0x600000
	end if
end function


event ObjectMain
	temp6 = object.ypos
	if Slots.Power == 0
		if object.ypos >= object.value1
			object.yvel -= 0x400
		else
			object.yvel += 0x400
		end if
		object.ypos += object.yvel
	end if
	temp0 = object.ypos
	temp6 &= -0x10000
	object.value2 = object.ypos
	object.value2 &= -0x10000
	object.value2 -= temp6
	object.ypos = temp6
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_BOX2, object.entityPos, -32, -32, 32, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		switch checkResult
		case 1
			object[currentPlayer].ypos += object.value2
			break
		case 4
			if object[currentPlayer].gravity == GRAVITY_GROUND
				if object.yvel > 0
					CallFunction(PlayerObject_Kill)
				end if
			end if
			break
		end switch
	next
	object.ypos = temp0
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("CNZ/Objects.gif")
	SpriteFrame(-32, -32, 64, 64, 82, 34)
	foreach (TypeName[V Block], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].ypos
		if object[arrayPos0].propertyValue == 0
			object[arrayPos0].ypos -= 0x600000
		else
			object[arrayPos0].ypos += 0x600000
		end if
		object[arraypos0].priority = PRIORITY_ACTIVE
	next
	SetTableValue(TypeName[V Block], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(VBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(VBlock_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
