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

//-------Aliases-------//
private alias 46 : TYPE_ROCKCRUSHER

// Function declarations
reserve function RockCrusher_DebugDraw
reserve function RockCrusher_DebugSpawn

// Static Values

// Tables

function RockCrusher_DebugDraw
	DrawSprite(0)
end function


function RockCrusher_DebugSpawn
	CreateTempObject(TypeName[Rock Crusher], 0, object.xpos, object.ypos)
	object[tempObjectPos].value1 = object[tempObjectPos].ypos
	object[tempObjectPos].yvel = -0x10000
end function


event ObjectMain
	if object.state == 0
		object.value0++
		if object.value0 == 96
			object.value0 = 0
			object.yvel = 0x80000
			object.state = 1
		end if
	else
		object.value0++
		if object.value0 == 12
			object.value0 = 0
			object.yvel = -0x10000
			object.state = 0
		end if
		if object.value0 == 6
			PlaySfx(SfxName[Ground Impact], 0)
		end if
	end if
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_BOX2, object.entityPos, -15, -64, 15, 64, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		switch checkResult
		case 1
			object[currentPlayer].ypos += object.yvel
			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 += object.yvel
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("MCZ/Objects.gif")
	SpriteFrame(-15, -74, 30, 148, 201, 0)
	foreach (TypeName[Rock Crusher], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].ypos
		object[arrayPos0].yvel = -0x10000
	next
	SetTableValue(TypeName[Rock Crusher], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(RockCrusher_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(RockCrusher_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
