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

// ========================
// Aliases
// ========================

private alias object.value0 : object.timer
private alias object.value1 : object.interval


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

reserve function Gargoyle_DebugDraw
reserve function Gargoyle_DebugSpawn


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

private function Gargoyle_DebugDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
end function


private function Gargoyle_DebugSpawn
	CreateTempObject(TypeName[Gargoyle], 0, object.xpos, object.ypos)
	object[tempObjectPos].direction = object.direction
	object[tempObjectPos].interval = 60
	object[tempObjectPos].timer = 60
end function


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

event ObjectUpdate
	temp0 = object.ixpos
	temp0 -= camera[0].xpos
	Abs(temp0)
	if temp0 < screen.xcenter
		temp0 = object.iypos
		temp0 -= camera[0].ypos
		Abs(temp0)
		if temp0 < screen.ycenter
		
			object.timer--
			if object.timer <= 0
				PlaySfx(SfxName[Small Fireball], false)
				CreateTempObject(TypeName[Gargoyle Shot], 0, object.xpos, object.ypos)
				object[tempObjectPos].drawOrder = 2
				if object.direction == FLIP_NONE
					object[tempObjectPos].xvel = -0x20000
				else
					object[tempObjectPos].xvel = 0x20000
				end if
				object[tempObjectPos].ypos += 0x80000
				object[tempObjectPos].direction = object.direction
				object.timer = object.interval
			end if
		end if
	end if
end event


event ObjectDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
end event


event ObjectStartup
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-16, -15, 32, 31, 93, 128)

	foreach (TypeName[Gargoyle], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].interval = object[arrayPos0].propertyValue
		object[arrayPos0].interval++
		object[arrayPos0].interval *= 30
		object[arrayPos0].timer = object[arrayPos0].interval
	next

	SetTableValue(TypeName[Gargoyle], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(Gargoyle_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(Gargoyle_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event


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

event RSDKEdit
	if editor.returnVariable == true
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			checkResult = object.propertyValue
			break
			
		case 0 // interval
			checkResult = object.propertyValue
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			break
			
		case 0 // interval
			object.propertyValue = editor.variableValue
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
end event


event RSDKLoad
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-16, -15, 32, 31, 93, 128)

	AddEditorVariable("interval")
	SetActiveVariable("interval")
end event
