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

//-------Aliases-------//
private alias 61 : TYPE_SPEAR

// Function declarations
reserve function Spear_Function134
reserve function Spear_DebugDraw
reserve function Spear_DebugSpawn

// Static Values
public value Spear_value40 = 0;

// Tables

function Spear_Function134
	object[arrayPos0].ypos = object[arrayPos0].value1
	object[arrayPos0].ypos += object[arrayPos0].value31
	object[arrayPos0].drawOrder = 2
	object[arrayPos0].value0 = 0
	object[arrayPos0].state = 0
	object[arrayPos0].priority = PRIORITY_ACTIVE_BOUNDS
end function


function Spear_DebugDraw
	DrawSprite(0)
end function


function Spear_DebugSpawn
	temp0 = object[0].value17
	temp0 -= Spear_value40
	temp0 <<= 2
	CreateTempObject(TypeName[Spear], temp0, object.xpos, object.ypos)
	arrayPos0 = object[tempObjectPos].entityPos
	object[arrayPos0].value1 = object.ypos
	CallFunction(Spear_Function134)
end function


event ObjectMain
	switch object.state
	case 0
		temp0 = oscillation
		temp0 -= object.propertyValue
		temp0 &= 127
		if temp0 == 0
			object.priority = PRIORITY_ACTIVE
			object.value0 = 8
			object.state = 1
		end if
		break
	case 1
		object.ypos -= 0x40000
		object.value0--
		if object.value0 == 0
			object.value0 = 3
			object.state = 2
		end if
		break
	case 2
		object.value0--
		if object.value0 == 0
			object.value0 = 8
			object.state = 3
		end if
		break
	case 3
		object.ypos += 0x40000
		object.value0--
		if object.value0 == 0
			object.state = 0
		end if
		break
	end switch
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -4, -16, 4, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			CallFunction(PlayerObject_Hit)
		end if
	next
	if object.outOfBounds == 1
		arrayPos0 = object.entityPos
		CallFunction(Spear_Function134)
	end if
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("MPZ/Objects.gif")
	SpriteFrame(-4, -16, 8, 32, 34, 102)
	foreach (TypeName[Spear], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].ypos
		CallFunction(Spear_Function134)
	next
	temp0 = 0
	Spear_value40 = DebugMode_ObjCount
	while temp0 < 16
		SetTableValue(TypeName[Spear], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(Spear_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(Spear_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

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