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

// ========================
// Function Declarations
// ========================

reserve function VPropeller_DebugDraw
reserve function VPropeller_DebugSpawn


// ========================
// Function Definitions
// ========================

private function VPropeller_DebugDraw
	DrawSprite(0)
end function


private function VPropeller_DebugSpawn
	CreateTempObject(TypeName[V Propeller], 0, object.xpos, object.ypos)
end function


// ========================
// Events
// ========================

event ObjectUpdate
	temp0 = object.xpos
	temp0 >>= 16
	temp0 -= camera[0].xpos
	Abs(temp0)
	temp0 -= 96
	if temp0 < screen.xcenter
		temp0 = object.ypos
		temp0 >>= 16
		temp0 -= camera[0].ypos
		Abs(temp0)
		if temp0 < 160
			temp0 = oscillation
			temp0 &= 0x1F
			if temp0 == 0
				PlaySfx(SfxName[Helicopter], false)
			end if
		end if
	end if

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -4, -64, 4, 64, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
		if checkResult == true
			CallFunction(Player_Hit)
		end if
	next
end event


event ObjectDraw
	DrawSprite(WFZSetup_vPropellerFrame)
end event


event ObjectStartup
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-4, -64, 8, 64, 121, 106)
	SpriteFrame(-4, -32, 8, 64, 121, 106)
	SpriteFrame(-4, 0, 8, 64, 121, 106)

	SetTableValue(TypeName[V Propeller], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(VPropeller_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(VPropeller_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-4, -64, 8, 64, 121, 106)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
