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

//-------Aliases-------//
private alias 60 : TYPE_PIPEVALVE

// Function declarations
reserve function PipeValve_DebugDraw
reserve function PipeValve_DebugSpawn

// Static Values

// Tables

function PipeValve_DebugDraw
	DrawSprite(2)
	DrawSprite(0)
end function


function PipeValve_DebugSpawn
	CreateTempObject(TypeName[Pipe Valve], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 5
end function


event ObjectMain
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -16, -8, 16, 8, currentPlayer, 0, 0, 0, 0)
		if checkResult == 1
			object[currentPlayer].state = PlayerObject_HandleAir
			object[currentPlayer].gravity = GRAVITY_AIR
			object[currentPlayer].animation = ANI_WATERSLIDE
			object[currentPlayer].yvel = -0x100000
			object[currentPlayer].xpos = object.xpos
			object[currentPlayer].ypos = object.ypos
			object[currentPlayer].speed = 0
			object[currentPlayer].xvel = 0
			object[currentPlayer].value1 = 0
			if object.state == 0
				object.state = 1
				CreateTempObject(TypeName[Water Geyser], 0, object.xpos, object.ypos)
				PlaySfx(SfxName[Water Geyser], 0)
			end if
		end if
	next
	if object.state == 1
		object.value0++
		if object.value0 == 64
			object.value0 = 0
			object.state = 0
		end if
		StopSfx(SfxName[Water Splash])
	end if
	object.frame = object.value0
	object.frame >>= 2
	object.frame &= 1
end event


event ObjectDraw
	DrawSprite(2)
	DrawSprite(object.frame)
end event


event ObjectStartup
	LoadSpriteSheet("HPZ/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 418, 1)
	SpriteFrame(-12, -12, 24, 24, 418, 26)
	SpriteFrame(-16, -16, 32, 32, 443, 1)
	foreach (TypeName[Pipe Valve], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 5
	next
	SetTableValue(TypeName[Pipe Valve], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(PipeValve_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(PipeValve_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
